Skip to content

Prevent field from being bound #2011

Answered by aldas
bitflipp asked this question in Q&A
Oct 12, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

First of all. You really should not bind to struct that have have fields that must not be filled. This potentially opens you for security risks. Especially if you are dealing with JSON which uses standard library implementation that will bind to public fields ("captitalized names") that do not have "json" tag.

https://echo.labstack.com/guide/binding/ has this note

To avoid security flaws try to avoid passing bound structs directly to other methods if these structs contain fields that should not be bindable. It is advisable to have separate struct for binding and map it explicitly to your business struct. Consider what will happen if your bound struct has public field IsAdmin bool and req…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bitflipp
Comment options

Answer selected by bitflipp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants