Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] ctx.ReadForm fires error if there is no csrf value in struct #1941

Closed
mostafa-binesh opened this issue Jul 30, 2022 · 2 comments

Comments

@mostafa-binesh
Copy link

mostafa-binesh commented Jul 30, 2022

Hey. I realized something today. Consider this example:
I put {{ .csrfField }} in the template and CSRF middleware verifies it
Processing the request:
type LoginUser struct {
Username string json:"username" form:"username" validate:"required,min=3"
Password string json:"password" form:"password" validate:"required,min=4"
}
...

func Proccesing(ctx iris.Context) {
user := LoginUser{}
err := ctx.ReadForm(&user)
if err != nil {
ctx.Writef("Error: %v",err)
return
}
...
}

It actually prints

error: schema: invalid path "csrf.token"

Because my LoginUser{} struct doesn't have any field with form:"csrf.token"
Please add a feature to ReadForm that would ignore csrf.token field and not try to fill the struct with that value
I know that there's a way to fix it (add if !iris.IsErrPath(err) to the error checking or read the values one by one) but please add a fix to it
Thanks

@mostafa-binesh mostafa-binesh changed the title [BUG] ctx.ReadForm fires error if there is no csrf value in struct [Feature Request] ctx.ReadForm fires error if there is no csrf value in struct Jul 30, 2022
kataras added a commit that referenced this issue Aug 14, 2022
@kataras
Copy link
Owner

kataras commented Aug 14, 2022

Hello @mostafa-binesh,

Sounds like a good exception, added on /v12@master version. Sorry for the delayed response!

@mostafa-binesh
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants