Bild-Upload: animierte GIFs erhalten statt aufs erste Frame reduzieren
Animierte GIFs (mehr als 1 Frame) werden jetzt unverändert durchgereicht statt via Decode+Re-Encode auf das erste Frame reduziert. Da die Bytes dabei nicht mehr sanitisiert werden, zwei Guardrails: - gif.DecodeAll läuft über einen io.LimitReader (16 MB) und prüft danach ein Frame-Budget (1000) sowie ein Gesamtpixel-Budget (100 MP) -> bremst den DoS-Vektor (GIF-Bombe mit vielen Frames). copyUpload schreibt die Bytes unter serverseitig erzeugtem Namen und deckelt hart bei 16 MB. - noSniff-Middleware setzt X-Content-Type-Options: nosniff auf /static/*, damit der Browser eine durchgereichte Datei nicht als HTML/JS deutet (Polyglot/Stored-XSS). Standbilder (JPEG/PNG/Einzelbild-GIF) behalten den skalierenden Re-Encode-Pfad und damit die Sanitisierung. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -65,8 +65,10 @@ func routes() http.Handler {
|
||||
r.Post("/user/delete", handleUserDelete)
|
||||
})
|
||||
|
||||
// Hochgeladene Medien + alte statische Assets
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
// Hochgeladene Medien + alte statische Assets. nosniff verhindert, dass der
|
||||
// Browser eine durchgereichte (nicht re-kodierte) Datei als HTML/JS
|
||||
// interpretiert -> schließt Polyglot/Stored-XSS über Bild-Uploads.
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", noSniff(http.FileServer(http.Dir("static")))))
|
||||
|
||||
// Neues JS-Frontend
|
||||
r.Handle("/*", http.FileServer(http.Dir("web")))
|
||||
@@ -74,6 +76,15 @@ func routes() http.Handler {
|
||||
return r
|
||||
}
|
||||
|
||||
// noSniff setzt X-Content-Type-Options: nosniff, damit der Browser den
|
||||
// deklarierten Content-Type nicht überstimmt (Schutz vor Content-Sniffing).
|
||||
func noSniff(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
|
||||
Reference in New Issue
Block a user