fix(security): harden HLS session IDs, /health disclosure, archive password handling
Phase 1 security audit follow-up: - Reject HLS session IDs that aren't safe filesystem components (regex allowlist) to defend against path traversal via a buggy or compromised server. Applied at StartHLSSession and at the /hls URL handler; invalid IDs share the 404 of unknown sessions so the accepted format isn't enumerable. - /health no longer leaks the active filename, taskID prefix or client IP to non-loopback callers. Uses net.IP.IsLoopback so IPv4-mapped IPv6 (::ffff:127.0.0.1) is recognised and the empty-string parse failure stops bypassing the boundary. - unrar/7z passwords now travel through stdin instead of -p<password> in argv, removing /proc/<pid>/cmdline disclosure. Control characters in the password are rejected up front so a hostile NZB cannot feed extra prompt answers. Both invocations are bounded by a 30-minute context to stop indefinite hangs if the tool ever decides to prompt.
This commit is contained in:
parent
a73e1a7756
commit
c148cb8ce7
6 changed files with 213 additions and 16 deletions
|
|
@ -261,3 +261,33 @@ func TestCleanupHLSOrphanDirsMissingRoot(t *testing.T) {
|
|||
t.Errorf("CleanupHLSOrphanDirs on missing root = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidSessionID(t *testing.T) {
|
||||
good := []string{
|
||||
"abc",
|
||||
"7b8c4f12-9d3e-4a1b-9c2f-aabbccddeeff",
|
||||
"ABC_123-xyz",
|
||||
strings.Repeat("a", 128),
|
||||
}
|
||||
bad := []string{
|
||||
"",
|
||||
"../etc/passwd",
|
||||
"foo/bar",
|
||||
"foo\\bar",
|
||||
"foo.bar",
|
||||
"with spaces",
|
||||
"with\nnewline",
|
||||
strings.Repeat("a", 129),
|
||||
"héctor", // non-ascii
|
||||
}
|
||||
for _, id := range good {
|
||||
if !validSessionID.MatchString(id) {
|
||||
t.Errorf("validSessionID rejected good id %q", id)
|
||||
}
|
||||
}
|
||||
for _, id := range bad {
|
||||
if validSessionID.MatchString(id) {
|
||||
t.Errorf("validSessionID accepted bad id %q", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue