summaryrefslogtreecommitdiff
path: root/form
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:53:17 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:53:17 +0200
commit986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e (patch)
treef0198af6854ca4c3b13495eb8e3feb5788251a44 /form
parent3234c5ec777117d429bdc04dcf10c30094079e57 (diff)
downloadgosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.tar.gz
gosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.tar.bz2
gosten-986eb0cd93a8f11ff73e3f17d8dabb6d4260c67e.zip
Fix CSRF handling, esp. when errors occur in form
Diffstat (limited to '')
-rw-r--r--form.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/form.go b/form.go
index c5dffa0..db0d097 100644
--- a/form.go
+++ b/form.go
@@ -12,6 +12,7 @@ var schemaDecoder *schema.Decoder
func init() {
schemaDecoder = schema.NewDecoder()
+ schemaDecoder.IgnoreUnknownKeys(true)
}
type fieldError struct {
@@ -34,4 +35,8 @@ func parseForm[T any](r *http.Request, data *T) {
if err := schemaDecoder.Decode(data, r.PostForm); err != nil {
log.Panic("Decoding form: ", err)
}
+
+ if withCsrf, ok := any(data).(WithCsrf); ok {
+ withCsrf.SetCsrfField(r)
+ }
}