-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
c.bind() binds both POST request body and query to given struct causing security vulnerability and problems with slices #1670
Comments
Regarding the query parameter that fills what should be filled with the Body, please see my comment |
I agree on idea that where bind takes its data should have choice for user but it should have also 'safe' defaults for all users. Mixing query params with POST/PUT body is not safe or expected behavior in my opinion. For example POST: your requests have Anyway this For example GET: you have endpoint to list some entities. You provide extensive API to order, filter, paginate etc by query params. So you would have many query parameters. In that case it is nice to bind all query params to struct. Seems that there are even (rare) cases when body is used with GET. But back to this example - in this case this is what I expect to happens and not 'side effect'. It would be nice if user would have choice to switch on/off binding blocks for:
sometimes you wand some of them (GETs?), sometimes only one specific NB: this choice could be different for every handler function - definitely GETs have most of the time different requirements than POST/PUT/PATCH etc. |
I just noticed that when I copy&paste my previous comment the link were removed (my bad 😞). Please see this |
Now the DefaultBinder could be configured to avoid binding struct fields by name. This is particularly useful when the user don't want to bind certain struct fields (with this config in true, only the tagged fields will be binded) Fixes labstack#1620, fixes labstack#1631, partially fixes labstack#1670
workaround would be to use #1681 if it gets merged or for instead of: if err := c.Bind(&payload); err != nil {
return err
} use: if err := json.NewDecoder(c.Request().Body).Decode(&payload); err != nil {
return err
} |
Currently, echo supports binding data from query, path or body. Sometimes we need to read bind data from headers. It would be nice to automatically bind those using the `bindData` func, which is already well prepared to accept `http.Header`. I didn't add this to the `Bind` func, so this will not happen automatically. Main reason is backwards compatability. It might be confusing if variables are bound from headers when upgrading, and might even have become a security issue as pointed out in labstack#1670.
Currently, echo supports binding data from query, path or body. Sometimes we need to read bind data from headers. It would be nice to automatically bind those using the `bindData` func, which is already well prepared to accept `http.Header`. I didn't add this to the `Bind` func, so this will not happen automatically. Main reason is backwards compatability. It might be confusing if variables are bound from headers when upgrading, and might even have become a security issue as pointed out in #1670. * Add docs for BindHeaders * Add test for BindHeader with invalid data type
Issue Description
Commit b129098 removed content length and request method check from c.bind() function. This causes many unwanted side effects
see example:
binding element must be a struct
Example:
Expected behaviour
I think expected behavior is as it was before b129098
Version/commit
v4.1.17
The text was updated successfully, but these errors were encountered: