summaryrefslogtreecommitdiff
path: root/player-server/internal/api/handlers_share.go
diff options
context:
space:
mode:
Diffstat (limited to 'player-server/internal/api/handlers_share.go')
-rw-r--r--player-server/internal/api/handlers_share.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/player-server/internal/api/handlers_share.go b/player-server/internal/api/handlers_share.go
index 03ec32a..ccf1632 100644
--- a/player-server/internal/api/handlers_share.go
+++ b/player-server/internal/api/handlers_share.go
@@ -7,6 +7,7 @@ import (
"time"
"codeberg.org/snonux/player/internal/service"
+ "codeberg.org/snonux/player/internal/web"
)
// ------------------------------------------------------------------
@@ -91,6 +92,15 @@ func (s *Server) handleSharePage(w http.ResponseWriter, r *http.Request) {
return
}
+ // Sanitize the media filename before embedding it in the share page to
+ // prevent XSS via HTML injection and to cap memory growth from enormous
+ // filenames (DoS). SanitizeFileName truncates to MaxFileNameLength runes
+ // and HTML-escapes the result; encoding/json also Unicode-escapes </>
+ // inside string values, so both layers reinforce each other.
+ if res.Media != nil {
+ res.Media.FileName = web.SanitizeFileName(res.Media.FileName)
+ }
+
// Render the HTML view via the dedicated renderer. This keeps the
// handler focused on transport concerns (status codes, headers) and
// keeps templating in the internal/web package.