Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/radio-source-plan.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,16 @@ test("never forwards OAuth-style stream credentials to a third-party proxy", ()
]);
assert.equal(result.filter(item => item.proxied).length, 1);
});


test("does not re-proxy an already proxied URL with canonical-equivalent host casing or port", () => {
const alreadyProxied = "https://CORS.EXAMPLE:443/https://radio.example/live.mp3";
const result = buildPlaybackSources([{ src: alreadyProxied }], "https://cors.example/");
assert.deepEqual(result.map(item => item.src), [alreadyProxied]);

const otherStream = "https://radio.example/live.mp3";
assert.deepEqual(
buildPlaybackSources([{ src: otherStream }], "https://cors.example/").map(item => item.src),
[otherStream, "https://cors.example/https://radio.example/live.mp3"],
);
});
5 changes: 4 additions & 1 deletion utils/radio-source-plan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ export const buildPlaybackSources = (sources, corsServer) => {
// Never forward URL-embedded credentials to a third-party CORS proxy.
// Preserve the direct candidate; only suppress its proxy fallback.
let hasCredentials = false;
let alreadyProxied = false;
try {
const parsed = new URL(src);
// Signed stream URLs (including AWS/GCS provider-specific query fields) must not reach third-party proxies.
const sensitiveQuery = [...parsed.searchParams.keys()].some(key =>
/^(?:x-amz-.+|x-goog-.+|awsaccesskeyid|googleaccessid|token|(?:access|refresh|id|auth|session)[_-]?token|access[_-]?key|api[_-]?key|client[_-]?secret|session[_-]?key|auth(?:orization)?|signature|sig|secret|password|jwt|expires?|policy|key[_-]?pair[_-]?id)$/i.test(key));
hasCredentials = Boolean(parsed.username || parsed.password || sensitiveQuery);
// URL canonicalization normalizes host casing and default ports, unlike a raw string prefix check.
alreadyProxied = Boolean(proxyBase) && parsed.href.startsWith(new URL(proxyBase).href);
} catch { /* Invalid URLs are not eligible for proxy fallback. */
hasCredentials = true;
}
Expand All @@ -57,7 +60,7 @@ export const buildPlaybackSources = (sources, corsServer) => {
!isHls &&
!source.proxied &&
/^https?:\/\//i.test(src) &&
!src.startsWith(proxyBase);
!alreadyProxied;

if (canProxy) {
push({
Expand Down
Loading