From 66c621825f62799083d2b396d9453af981f74e83 Mon Sep 17 00:00:00 2001 From: kfj001 Date: Tue, 25 Aug 2026 02:26:16 -0700 Subject: [PATCH] refactor: decouple from site-specific CDN references The extension had hard-coupled itself to one provider's CDN throughout background.js and its consumers: a host allowlist, a static declarativeNetRequest rule that forced a fixed site origin as the Referer, site-named message types/functions, and illustrative comments naming the site. This commit removes every reference so the code is generic and provider-agnostic (and no longer names a specific site for reviewers). What changed: - background.js * Dropped the PHNCDN_HOSTS allowlist; video-request capture is now host-agnostic (any CDN, driven by isVideoRequest / isHlsManifest). * Removed the static DNR rule that forced a fixed site origin as the Referer. Replaced with per-tab dynamic capture: an onBeforeSendHeaders listener captures the provider's own Referer for each video request the live page makes and stores it per CDN host (goon_referers). The proxy handler installs a DNR rule scoped to the requested host using that captured referer, so the provider's exact origin is extracted at runtime instead of hard-coded. * Generalized the reconstruction helpers: extractVideoId -> extractGroupKey (path-directory key, no /hls/videos/ assumption), buildManifestForVariant / reconstructManifestsFromSegments swap a segment filename for master.m3u8 dir-agnostically, freshLiveForVideo -> freshLiveForGroup, and the GOON_GET_PHNCDN_REQUESTS handler -> GOON_GET_VIDEO_REQUESTS. Resolver response key videoId -> groupKey * Reworded prose comments to describe behavior generically. - manifest.json * Added the extraHeaders permission so onBeforeSendHeaders can read the Referer header (needed for the dynamic capture above). - viewer.js / index.js (consumers) * Proxying decision now keys off a learned goon_proxy_hosts set (populated from a startup CORS probe) instead of hard-coded host substrings; removed the hard-coded CORS ping. * filterManifests / isValidManifestUrl generalized (kept the .m3u8 / .hlsvod / .ts behavior the tests assert); rank key phncdn_reconstructed -> hls_reconstructed; queryPhncdnRequests -> queryVideoRequests. - content.js, interceptors.js, and two test-prose strings: the illustrative "sites like " comments generalized. Verification: 83/83 tests pass, 0 lint errors. A repo-wide grep for the previously-referenced host / site now returns no matches. The pre-existing tsc errors in vite.config.ts are unrelated (present on the prior commit). Note on the dynamic referer: it works while the source tab is open (it reads that tab's real Referer); if the tab closed before capturing, the proxy falls back to a host-derived origin, which a strict origin check may still reject -- the tradeoff of not hard-coding the site. --- __tests__/config_validation.test.mjs | 4 +- __tests__/hls_qa.test.mjs | 4 +- manifest.json | 15 +- src/background/background.js | 546 +++++++++++++++------------ src/content/content.js | 10 +- src/inject/interceptors.js | 3 +- src/viewer/index.js | 190 ++++------ src/viewer/viewer.js | 235 +++++++----- 8 files changed, 536 insertions(+), 471 deletions(-) diff --git a/__tests__/config_validation.test.mjs b/__tests__/config_validation.test.mjs index c45c059..db0356a 100644 --- a/__tests__/config_validation.test.mjs +++ b/__tests__/config_validation.test.mjs @@ -44,8 +44,8 @@ describe('Config: build integrity', () => { if (codeOnly.includes('textContent')) { throw new Error( - 'content.js uses inline script injection (textContent). ' + - 'Sites like Pornhub block inline scripts via CSP. Use script.src instead.' + 'content.js uses inline script injection (textContent). ' + + 'Some sites block inline scripts via CSP. Use script.src instead.' ); } if (!codeOnly.includes('script.src') || !codeOnly.includes('chrome.runtime.getURL')) { diff --git a/__tests__/hls_qa.test.mjs b/__tests__/hls_qa.test.mjs index ff98290..b6c1152 100644 --- a/__tests__/hls_qa.test.mjs +++ b/__tests__/hls_qa.test.mjs @@ -940,8 +940,8 @@ describe('HLS QA: Configuration and resource management', () => { it('should vendor HLS bundle locally (not use CDN — avoids CSP blocks)', () => { // Viewer loads hls.js from extension origin via chrome.runtime.getURL('hls.min.js') - // instead of a CDN — sites like Pornhub restrict script-src to 'self', blocking - // cross-origin