Sync shared snapshot from 9e58b6d
Security / Secrets (gitleaks) (push) Successful in 2m3s
Security / Code (Semgrep) (push) Successful in 2m22s
Security / Dependencies (Trivy) (push) Successful in 1m16s
Docker / Docker Build & Push (push) Successful in 7m40s

This commit is contained in:
Claude Code committed 2026-11-18 14:00:13 +01:00
1 parent 36ab01aab1
commit 5a4bf45bc7
10 files changed
+393 -51

No files matched your search

+26 -12
View File
@@ -135,7 +135,23 @@ func (c *Service) streamMediaIdentifier(w http.ResponseWriter, r *http.Request,
writeError(w, http.StatusNotFound, "media not found")
return
}
c.carrierNode.Proxy(w, r, "/media/"+upstream)
c.carrierNode.Proxy(w, r, streamUpstreamPath(upstream, r.URL.Query()))
}
// streamUpstreamPath is the CarrierNode request path for a stream. CarrierNode answers with a live
// H.264 copy when the query carries quality (a height) and start (seconds), which is how browsers get
// containers they cannot decode. Those two parameters are the only ones forwarded.
func streamUpstreamPath(upstream string, query url.Values) string {
forward := url.Values{}
for _, key := range []string{"quality", "start"} {
if value := strings.TrimSpace(query.Get(key)); value != "" {
forward.Set(key, value)
}
}
if len(forward) == 0 {
return "/media/" + upstream
}
return "/media/" + upstream + "?" + forward.Encode()
}
func (c *Service) thumbnailMediaByQuery(w http.ResponseWriter, r *http.Request) {
@@ -911,21 +927,19 @@ func urlPath(value string) string {
return value
}
// upstreamMediaPath returns the escaped CarrierNode path for a stored file path. It reports false
// when the stored path is not a safe relative path, or when it contains a query or fragment marker
// that CarrierNode would read as the end of the path.
// upstreamMediaPath returns the CarrierNode path for a stored file path. It reports false only when
// the stored path is not a safe relative path.
//
// url.PathEscape would write a comma as %2C, and the request then keeps that escape as a raw path.
// CarrierNode's router matches a raw path literally, so "Hello, World.mp4" would never be found. A
// URL built from Path alone leaves no raw path, so the name reaches CarrierNode decoded. Query and
// fragment markers are escaped the same way, so they no longer need refusing.
func upstreamMediaPath(filePath string) (string, bool) {
relative := urlPath(filePath)
if !files.SafeRelative(relative) || strings.ContainsAny(relative, "?#") {
if !files.SafeRelative(relative) {
return "", false
}
// Escape each segment so percent-escapes and other reserved characters in a stored name
// reach CarrierNode as literal text, not as an escape or a traversal it decodes later.
segments := strings.Split(relative, "/")
for i, segment := range segments {
segments[i] = url.PathEscape(segment)
}
return strings.Join(segments, "/"), true
return (&url.URL{Path: relative}).EscapedPath(), true
}
// canonicalMediaID returns the numeric media id that identifier spells exactly. Leading zeros, signs