diff --git a/tests/radio-source-plan.test.mjs b/tests/radio-source-plan.test.mjs index 1c00af0d..9ee20b65 100644 --- a/tests/radio-source-plan.test.mjs +++ b/tests/radio-source-plan.test.mjs @@ -148,3 +148,40 @@ test("does not disclose embedded stream credentials through a CORS proxy", () => ]); assert.equal(result.filter(item => item.proxied).length, 1); }); + + +test("never forwards signed query credentials to a third-party proxy", () => { + const sources = [ + { src: "https://radio.example/live.mp3?token=private-test-value" }, + { src: "https://radio.example/live.aac?accessKey=private-test-value" }, + { src: "https://radio.example/live.mp3?Signature=private-test-value" }, + { src: "https://radio.example/live.mp3?quality=high" }, + ]; + const result = buildPlaybackSources(sources, "https://cors.example/"); + assert.deepEqual(result.map(item => item.src), [ + ...sources.slice(0, 3).map(item => item.src), + "https://radio.example/live.mp3?quality=high", + "https://cors.example/https://radio.example/live.mp3?quality=high", + ]); +}); + +test("never forwards cloud-provider signed stream query parameters to a third-party proxy", () => { + const signed = [ + "https://radio.example/live.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=test&X-Amz-Signature=test", + "https://radio.example/live.aac?X-Amz-Security-Token=test", + "https://radio.example/live.mp3?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Signature=test", + "https://radio.example/live.mp3?AWSAccessKeyId=test", + "https://radio.example/live.mp3?GoogleAccessId=test", + ]; + const ordinary = "https://radio.example/live.mp3?quality=high"; + const result = buildPlaybackSources( + [...signed, ordinary].map(src => ({ src })), + "https://cors.example/", + ); + assert.deepEqual(result.map(item => item.src), [ + ...signed, + ordinary, + `https://cors.example/${ordinary}`, + ]); + assert.equal(result.filter(item => item.proxied).length, 1); +}); diff --git a/tests/station-sharing-mailto-line-endings.test.mjs b/tests/station-sharing-mailto-line-endings.test.mjs index e6852fb8..028d6440 100644 --- a/tests/station-sharing-mailto-line-endings.test.mjs +++ b/tests/station-sharing-mailto-line-endings.test.mjs @@ -19,3 +19,18 @@ test('mailto body normalizes mixed CRLF, CR and LF to single CRLF', () => { assert.equal((body.match(/\r\n/g) || []).length, 6); assert.equal(body.replace(/\r\n/g, '').includes('\r'), false); }); + + +test('mailto expands a single localized placeholder without leaking literal braces or duplicating station details', () => { + const stationOnly = new URL(stationReportEmailUrl( + '/vn/ho-chi-minh/test-radio', 'Test Radio', 'Playback problem', 'Station: {station}', + )); + const urlOnly = new URL(stationReportEmailUrl( + '/vn/ho-chi-minh/test-radio', 'Test Radio', 'Playback problem', 'Station page: {url}', + )); + const stationBody = stationOnly.searchParams.get('body'); + const urlBody = urlOnly.searchParams.get('body'); + assert.equal(stationBody, 'Station: Test Radio\r\nhttps://radio.eplus.dev/vn/ho-chi-minh/test-radio'); + assert.equal(urlBody, 'Station page: https://radio.eplus.dev/vn/ho-chi-minh/test-radio\r\nTest Radio'); + assert.doesNotMatch(stationBody + urlBody, /\{(?:station|url)\}/); +}); diff --git a/utils/radio-source-plan.mjs b/utils/radio-source-plan.mjs index 4cdc43e6..bfc5f461 100644 --- a/utils/radio-source-plan.mjs +++ b/utils/radio-source-plan.mjs @@ -43,7 +43,10 @@ export const buildPlaybackSources = (sources, corsServer) => { let hasCredentials = false; try { const parsed = new URL(src); - hasCredentials = Boolean(parsed.username || parsed.password); + // 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[_-]?key|api[_-]?key|auth(?:orization)?|signature|sig|secret|password|jwt|expires?|policy|key[_-]?pair[_-]?id)$/i.test(key)); + hasCredentials = Boolean(parsed.username || parsed.password || sensitiveQuery); } catch { /* Invalid URLs are not eligible for proxy fallback. */ hasCredentials = true; } diff --git a/utils/station-sharing.mjs b/utils/station-sharing.mjs index ab892a92..b049a28c 100644 --- a/utils/station-sharing.mjs +++ b/utils/station-sharing.mjs @@ -49,9 +49,11 @@ export function stationReportEmailUrl(path, title, subject, description) { const message = String(description || 'I cannot hear this station.').slice(0, 1000); // Localized templates may place the station name and public URL directly in // the email. Preserve the previous plain-text fallback for older callers. - const hasPlaceholders = message.includes('{station}') && message.includes('{url}'); + const hasPlaceholders = /\{(?:station|url)\}/.test(message); const body = hasPlaceholders ? message.replace(/\{(station|url)\}/g, (_match, key) => key === 'station' ? safeTitle : stationPage) + + (message.includes('{station}') ? '' : '\n' + safeTitle) + + (message.includes('{url}') ? '' : '\n' + stationPage) : message + '\n\n' + safeTitle + '\n' + stationPage; // mailto URLs follow RFC 6068, not HTML form encoding. URLSearchParams