Files
EdgeAdmin/internal/web/actions/actionutils/csrf.go

24 lines
505 B
Go
Raw Normal View History

2020-10-25 11:22:11 +08:00
package actionutils
import (
2024-07-27 15:42:58 +08:00
"net/http"
2020-10-25 11:22:11 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/csrf"
"github.com/iwind/TeaGo/actions"
)
type CSRF struct {
}
func (this *CSRF) BeforeAction(actionPtr actions.ActionWrapper, paramName string) (goNext bool) {
action := actionPtr.Object()
token := action.ParamString("csrfToken")
if !csrf.Validate(token) {
action.ResponseWriter.WriteHeader(http.StatusForbidden)
action.WriteString("表单已失效,请刷新页面后重试(001)")
return
}
return true
}