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
37 changes: 37 additions & 0 deletions tests/radio-source-plan.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
15 changes: 15 additions & 0 deletions tests/station-sharing-mailto-line-endings.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)\}/);
});
5 changes: 4 additions & 1 deletion utils/radio-source-plan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion utils/station-sharing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading