-
Is there a way (e. g. using a magic tag value like encoding/json allows) to prevent a field from being bound?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 https://echo.labstack.com/guide/binding/ has this note
You may want to read this #1670 (comment) What version are you using? Since version So if you remove the tag. it should be enough // curl -v -F "should_be_bound=test" -F "ShouldNotBeBound=nope" http://localhost:8080/
func main() {
e := echo.New()
e.POST("/", func(c echo.Context) error {
type Thing struct {
ShouldBeBound string `form:"should_be_bound"`
ShouldNotBeBound string // `form:"-"`
}
fields := Thing{}
if err := c.Bind(&fields); err != nil {
return err
}
log.Printf("%+v\n", fields)
return c.String(http.StatusOK, "OK\n")
})
log.Fatal(e.Start(":8080"))
} Should log something like that
|
Beta Was this translation helpful? Give feedback.
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