:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(security): log out-of-band interaction domains in the node guards (#118874)
Tom Piccirellob20d5e68bf77
diff --git a/.agents/security.md b/.agents/security.mdindex 7f33977ee4c1..cbe3498226e3 100644--- a/.agents/security.md+++ b/.agents/security.md@@ -205,6 +205,13 @@ adapter emits `security.oob_domain_seen` and takes its team from the activity's`posthog/security/url_validation.py` emits the same event with no team at all, because no team isin scope there, so those lines are attributable to a host and not to a project.+In Node, `validateHostnameIPLiteral` (`nodejs/src/common/utils/request.ts`) and `EmailValidationService.getSkipReason` emit `security.oob_domain_seen` too, under the guard `node_request` or `node_email_validation`.+Both read the hand-written mirror in `nodejs/src/common/utils/oob-domains.ts`, which a parity test holds against the JSON.+Both log `team_id`, the field the Python guards bind.+The email guard always has a team.+The request guard has one only when the fetch runs under `fetchAttribution`, as a CDP destination fetch and a recording export's stylesheet fetch do, and logs `team_id: null` for any other caller.+`noteOobDomain` logs one line per host, team and guard every 15 minutes, because a retrying destination would otherwise log per attempt.+The check runs on cloud only, and it runs before each guard's own DNS resolution, because thelookup alone confirms the path to whoever runs the collaborator.diff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.ymlindex 9d1dd2e45fa8..7342c39577e2 100644--- a/.github/workflows/ci-nodejs.yml+++ b/.github/workflows/ci-nodejs.yml@@ -164,6 +164,7 @@ jobs:# readFileSync, so jest cannot reach the parity test through --findRelatedTests.- 'products/cdp/backend/filter_globals.json'- 'common/hogvm/typescript/src/**'+ - '**/crosslang/**'- '.github/scripts/jest-retries.cjs'- 'patches/[email protected]'- 'nodejs/jest*.config.js'diff --git a/nodejs/src/cdp/services/messaging/email-validation.service.test.ts b/nodejs/src/cdp/services/messaging/email-validation.service.test.tsindex 463d5c5070fb..e4a0b95a3f32 100644--- a/nodejs/src/cdp/services/messaging/email-validation.service.test.ts+++ b/nodejs/src/cdp/services/messaging/email-validation.service.test.ts@@ -1,6 +1,7 @@import { register } from 'prom-client'import { RedisV2 } from '~/common/redis/redis-v2'+import { logger } from '~/common/utils/logger'import { CyclotronJobInvocationHogFunction } from '../../types'import { EmailValidationService, MAX_LOCAL_CACHE_DOMAINS } from './email-validation.service'@@ -237,4 +238,37 @@ describe('EmailValidationService', () => {expect(mockResolveMx).not.toHaveBeenCalled()})})+ describe('out-of-band domain detection', () => {+ const originalCloudDeployment = process.env.CLOUD_DEPLOYMENT+ let info: jest.SpyInstance++ beforeEach(() => {+ process.env.CLOUD_DEPLOYMENT = 'US'+ info = jest.spyOn(logger, 'info').mockImplementation(() => undefined)+ })++ afterEach(() => {+ info.mockRestore()+ if (originalCloudDeployment === undefined) {+ delete process.env.CLOUD_DEPLOYMENT+ } else {+ process.env.CLOUD_DEPLOYMENT = originalCloudDeployment+ }+ })++ it('logs a listed recipient domain and still lets the send through', async () => {+ const reason = await service.getSkipReason(emailInvocation('[email protected]'), emailAction)++ expect(info).toHaveBeenCalledWith(+ 'security.oob_domain_seen',+ expect.objectContaining({+ host: 'abc.oast.me',+ domain: 'oast.me',+ guard: 'node_email_validation',+ })+ )+ expect(mockResolveMx).toHaveBeenCalledWith('abc.oast.me')+ expect(reason).toBeNull()+ })+ })})diff --git a/nodejs/src/cdp/services/messaging/email-validation.service.ts b/nodejs/src/cdp/services/messaging/email-validation.service.tsindex 29bb984b6968..a74baae00586 100644--- a/nodejs/src/cdp/services/messaging/email-validation.service.ts+++ b/nodejs/src/cdp/services/messaging/email-validation.service.ts@@ -5,6 +5,7 @@ import { Counter } from 'prom-client'import { HogFlowAction } from '~/cdp/schema/hogflow'import { RedisV2 } from '~/common/redis/redis-v2'+import { noteOobDomain } from '~/common/utils/oob-domains'import { CyclotronJobInvocationHogFunction } from '../../types'@@ -121,6 +122,10 @@ export class EmailValidationService {// open, which is the safe direction.const rawDomain = email.slice(email.lastIndexOf('@') + 1)const domain = domainToASCII(rawDomain) || rawDomain.toLowerCase()+ // Above resolveDeliverability on purpose: one verdict is cached and shared across teams for+ // up to a day, so a check inside the lookup would miss every send that hits the cache.+ noteOobDomain(domain, 'node_email_validation', { teamId: invocation.teamId })+const deliverable = await this.resolveDeliverability(domain)if (!deliverable) {return this.skip(diff --git a/nodejs/src/common/utils/oob-domains.test.ts b/nodejs/src/common/utils/oob-domains.test.tsnew file mode 100644index 000000000000..4f9ef38d7f7b--- /dev/null+++ b/nodejs/src/common/utils/oob-domains.test.ts@@ -0,0 +1,97 @@+import { readFileSync } from 'fs'+import path from 'path'++import { parseJSON } from './json-parse'+import { logger } from './logger'+import { OOB_DOMAINS, matchedOobDomain, noteOobDomain } from './oob-domains'++// Python reads this file at runtime, so it is the one source of truth for the list. Reading the+// file itself, rather than parsing Python, keeps the test green through a rename or a reformat on+// either side and red only when the two lists differ.+const DOMAINS_JSON = path.resolve(__dirname, '../../../../posthog/security/crosslang/oob_domains.json')++describe('oob-domains', () => {+ it('mirrors posthog/security/crosslang/oob_domains.json', () => {+ const listed: string[] = parseJSON(readFileSync(DOMAINS_JSON, 'utf8')).domains++ expect(new Set(OOB_DOMAINS)).toEqual(new Set(listed))+ })++ it.each([+ ['the listed domain itself', 'oast.me', 'oast.me'],+ ['a subdomain', 'abc123.oast.me', 'oast.me'],+ ['a deep subdomain', 'a.b.interact.sh', 'interact.sh'],+ ['an uppercase host', 'ABC.OAST.ME', 'oast.me'],+ ['an absolute host carrying the DNS root dot', 'abc.oast.me.', 'oast.me'],+ ['a host carrying more than one trailing dot', 'abc.oast.me..', 'oast.me'],+ ['a fullwidth host that IDNA maps onto a listed one', 'oast.me', 'oast.me'],+ ['a host that only ends in the same letters', 'notoast.me', null],+ ['a listed name used as a prefix', 'oast.me.evil.example', null],+ ['a listed name behind userinfo', '[email protected]', null],+ ['a listed name behind fullwidth userinfo', 'user@abc.oast.me', null],+ ['a listed name behind a fullwidth slash', 'user/abc.oast.me', null],+ ['a listed name behind a colon the codec rejects', 'client:secret.abc.oast.me', null],+ ['a raw URL whose path ends in a listed name', 'https://evil.example/abc.oast.me', null],+ ['an unlisted host', 'example.com', null],+ ['an empty host', '', null],+ ])('matches %s', (_description, host, expected) => {+ expect(matchedOobDomain(host)).toBe(expected)+ })++ describe('noteOobDomain', () => {+ const originalCloudDeployment = process.env.CLOUD_DEPLOYMENT+ let info: jest.SpyInstance++ beforeEach(() => {+ info = jest.spyOn(logger, 'info').mockImplementation(() => undefined)+ })++ afterEach(() => {+ info.mockRestore()+ if (originalCloudDeployment === undefined) {+ delete process.env.CLOUD_DEPLOYMENT+ } else {+ process.env.CLOUD_DEPLOYMENT = originalCloudDeployment+ }+ })++ it('logs the match with the caller attribution under the team_id the python guards bind', () => {+ process.env.CLOUD_DEPLOYMENT = 'US'++ noteOobDomain('attribution.oast.me', 'node_request', { teamId: 2 })++ expect(info).toHaveBeenCalledWith('security.oob_domain_seen', {+ team_id: 2,+ host: 'attribution.oast.me',+ domain: 'oast.me',+ guard: 'node_request',+ })+ })++ it('logs one line per host and team in the window, so a retrying caller cannot flood', () => {+ process.env.CLOUD_DEPLOYMENT = 'US'++ noteOobDomain('flood.oast.me', 'node_request', { teamId: 3 })+ noteOobDomain('flood.oast.me', 'node_request', { teamId: 3 })++ expect(info).toHaveBeenCalledTimes(1)+ })++ it('logs a second team hitting the same host, so one noisy team cannot mask another', () => {+ process.env.CLOUD_DEPLOYMENT = 'US'++ noteOobDomain('shared.oast.me', 'node_request', { teamId: 4 })+ noteOobDomain('shared.oast.me', 'node_request', { teamId: 5 })++ expect(info).toHaveBeenCalledTimes(2)+ })++ it('stays silent off cloud, so self-hosted behavior does not change', () => {+ delete process.env.CLOUD_DEPLOYMENT++ noteOobDomain('abc.oast.me', 'node_request')++ expect(info).not.toHaveBeenCalled()+ })+ })+})diff --git a/nodejs/src/common/utils/oob-domains.ts b/nodejs/src/common/utils/oob-domains.tsnew file mode 100644index 000000000000..2e68c53a7244--- /dev/null+++ b/nodejs/src/common/utils/oob-domains.ts@@ -0,0 +1,130 @@+import { domainToASCII } from 'node:url'++import { isCloud } from './env-utils'+import { logger } from './logger'++/**+ * Mirror of posthog/security/crosslang/oob_domains.json. Edit that file first, then this list. The+ * parity test in oob-domains.test.ts fails when they differ.+ */+export const OOB_DOMAINS: readonly string[] = [+ '1u.ms',+ 'burpcollaborator.net',+ 'ceye.io',+ 'dnslog.cn',+ 'interact.sh',+ 'oast.fun',+ 'oast.live',+ 'oast.me',+ 'oast.online',+ 'oast.pro',+ 'oast.site',+ 'oastify.com',+ 'rbndr.us',+]++/** The guard that saw the host. One value per call site, so a log line names the path. */+export type OobGuard = 'node_request' | 'node_email_validation'++/**+ * One line per host, team and guard in this window. A CDP destination retries, and undici reuses a+ * keep-alive socket without a fresh lookup, so an undeduped count tracks request volume rather than+ * probing. The window stays short enough that a sustained campaign still reads as repeated activity.+ */+const DEDUPE_WINDOW_MS = 15 * 60 * 1000+const DEDUPE_MAX_ENTRIES = 10_000++const lastLoggedAt = new Map<string, number>()++/** Whether this key was last logged outside the window. Bounded by size, so it needs no timer. */+function firstSightInWindow(key: string, now: number): boolean {+ const seenAt = lastLoggedAt.get(key)+ if (seenAt !== undefined && now - seenAt < DEDUPE_WINDOW_MS) {+ return false+ }+ // Deleting before setting moves the key to the end, so iteration order stays recency order and+ // the front of the map is always the oldest entry.+ lastLoggedAt.delete(key)+ lastLoggedAt.set(key, now)+ while (lastLoggedAt.size > DEDUPE_MAX_ENTRIES) {+ const oldest = lastLoggedAt.keys().next().value+ if (oldest === undefined) {+ break+ }+ lastLoggedAt.delete(oldest)+ }+ return true+}++// A host of letters, digits, dots, hyphens and underscores needs no IDNA pass, because+// domainToASCII would only lowercase it.+const PLAIN_HOST_RE = /^[A-Za-z0-9._-]+$/++function canonicalizeHost(host: string): string | null {+ // domainToASCII applies the IDNA mapping the resolver queries, so a fullwidth or uppercase form+ // of a listed name reaches the same entry. It returns an empty string for a name the codec+ // rejects. Such a string is not a host, and matching it would put a form the parser refused,+ // such as one carrying a fullwidth @ or a colon, into a log line.+ const canonical = PLAIN_HOST_RE.test(host) ? host.toLowerCase() : domainToASCII(host)+ if (!canonical) {+ return null+ }+ // An absolute FQDN carries the DNS root dot, which the list does not. A loop strips it, because+ // /\.+$/ backtracks in quadratic time on a long run of dots inside the host, and an email+ // recipient puts no limit on that run.+ let end = canonical.length+ while (end > 0 && canonical[end - 1] === '.') {+ end--+ }+ return canonical.slice(0, end)+}++/**+ * The listed out-of-band interaction domain this host belongs to, or null.+ *+ * The caller passes a parsed hostname. A raw URL or a credential never matches, because a match+ * puts the string in a log line.+ */+export function matchedOobDomain(host: string | null | undefined): string | null {+ if (!host || host.includes('@') || host.includes('/')) {+ return null+ }+ const canonical = canonicalizeHost(host)+ if (canonical === null) {+ return null+ }+ return OOB_DOMAINS.find((domain) => canonical === domain || canonical.endsWith(`.${domain}`)) ?? null+}++/**+ * Record a lookup of an out-of-band interaction domain, without refusing it.+ *+ * These names resolve to ordinary public IPs, so every IP check passes them, while the lookup alone+ * confirms the path to whoever runs the collaborator. Detection only: this never throws and never+ * changes what the caller does. Call it before the resolve, so the later blocking phase is a small+ * change.+ *+ * `context.teamId` is logged as `team_id`, which is the field the Python guards bind.+ */+export function noteOobDomain(+ host: string | null | undefined,+ guard: OobGuard,+ context: Record<string, unknown> = {}+): void {+ if (!isCloud()) {+ return+ }+ try {+ const domain = matchedOobDomain(host)+ if (domain === null) {+ return+ }+ const { teamId, ...rest } = context+ if (!firstSightInWindow(`${guard}\u0000${teamId ?? 'none'}\u0000${host}`, Date.now())) {+ return+ }+ logger.info('security.oob_domain_seen', { ...rest, team_id: teamId ?? null, host, domain, guard })+ } catch (error) {+ logger.warn('security.oob_domain_check_failed', { host, guard, error })+ }+}diff --git a/nodejs/src/common/utils/request.test.ts b/nodejs/src/common/utils/request.test.tsindex 1d3df2e2c991..f184d2ff8ab7 100644--- a/nodejs/src/common/utils/request.test.ts+++ b/nodejs/src/common/utils/request.test.ts@@ -7,6 +7,7 @@ import { register } from 'prom-client'import { getExternalRequestConfig } from '~/common/config'import { parseJSON } from './json-parse'+import { logger } from './logger'import {FetchOptions,SecureRequestError,@@ -153,6 +154,56 @@ describe('fetch', () => {})})+ describe('out-of-band domain detection', () => {+ const originalCloudDeployment = process.env.CLOUD_DEPLOYMENT+ let info: jest.SpyInstance++ beforeEach(() => {+ process.env.CLOUD_DEPLOYMENT = 'US'+ info = jest.spyOn(logger, 'info').mockImplementation(() => undefined)+ // A real lookup of a listed name is the interaction this detection reports, so answer+ // it here instead of letting the suite query the collaborator.+ jest.mocked(dns.lookup).mockResolvedValue([{ address: '93.184.216.34', family: 4 }] as any)+ })++ afterEach(() => {+ info.mockRestore()+ if (originalCloudDeployment === undefined) {+ delete process.env.CLOUD_DEPLOYMENT+ } else {+ process.env.CLOUD_DEPLOYMENT = originalCloudDeployment+ }+ })++ // Both modes run the check, because it sits above the `allowUnsafe` early return. Every+ // caller passes `!isProdEnv()`, so a check below that return never runs in a test.+ it.each(['production', 'test'])(+ 'logs a listed host in NODE_ENV=%s and still allows the request',+ async (nodeEnv) => {+ const originalNodeEnv = process.env.NODE_ENV+ process.env.NODE_ENV = nodeEnv+ try {+ // A host per case: noteOobDomain logs one line per host, team and guard per+ // window, so a shared host would suppress the second case.+ await expect(+ raiseIfUserProvidedUrlUnsafe(`https://${nodeEnv}.abc.oast.me/path`)+ ).resolves.not.toThrow()+ } finally {+ process.env.NODE_ENV = originalNodeEnv+ }++ expect(info).toHaveBeenCalledWith(+ 'security.oob_domain_seen',+ expect.objectContaining({+ host: `${nodeEnv}.abc.oast.me`,+ domain: 'oast.me',+ guard: 'node_request',+ })+ )+ }+ )+ })+describe('fetch call', () => {// By default security features are only enabled in production but for tests we want to enable themdiff --git a/nodejs/src/common/utils/request.ts b/nodejs/src/common/utils/request.tsindex fdd0cbb2ec52..1e810ebcc6a6 100644--- a/nodejs/src/common/utils/request.ts+++ b/nodejs/src/common/utils/request.ts@@ -28,6 +28,7 @@ import { isProdEnv } from './env-utils'import { fetchAttribution } from './fetch-attribution'import { parseJSON } from './json-parse'import { logger } from './logger'+import { noteOobDomain } from './oob-domains'const requestConfig = getExternalRequestConfig()@@ -199,6 +200,10 @@ function validateUrl(url: string): URL {* We must check these before passing the URL to undici.*/function validateHostnameIPLiteral(hostname: string, allowUnsafe: boolean): void {+ // Above the early return on purpose: every caller passes `!isProdEnv()`, so a check below it+ // would never run in a test and would reach production unexercised.+ noteOobDomain(hostname, 'node_request', fetchAttribution.getStore())+if (allowUnsafe) {return}diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/player.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/player.test.tsindex ceecf64ce305..ba813f4aff2a 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/player.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/player.test.ts@@ -70,7 +70,7 @@ function basePlayerConfig(overrides: Partial<PlayerConfig> = {}): PlayerConfig {describe('PlayerController', () => {it('load() sets up exposeFunction, evaluateOnNewDocument, and navigates', async () => {const { capturePage, page } = mockCapturePage()- const controller = new PlayerController(capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())@@ -88,7 +88,7 @@ describe('PlayerController', () => {it('waitForStart() resolves when player sends started message', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())const startPromise = controller.waitForStart(basePlayerConfig(), 5000)@@ -101,7 +101,7 @@ describe('PlayerController', () => {it('waitForStart() resets timeout on loading_progress messages', async () => {jest.useFakeTimers()const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())const startPromise = controller.waitForStart(basePlayerConfig(), 1000)@@ -123,7 +123,7 @@ describe('PlayerController', () => {it('waitForStart() rejects on timeout when no progress', async () => {jest.useFakeTimers()const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())const startPromise = controller.waitForStart(basePlayerConfig({ sessionId: 'sess-abc' }), 1000)@@ -137,7 +137,7 @@ describe('PlayerController', () => {it('waitForStart() surfaces an error that arrived before it was called', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())// Error lands between load() and waitForStart(); previously it was shelved and the wait@@ -157,7 +157,7 @@ describe('PlayerController', () => {it('waitForStart() rejects when player sends error message', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())const startPromise = controller.waitForStart(basePlayerConfig(), 5000)@@ -178,7 +178,7 @@ describe('PlayerController', () => {// succeeds on a later attempt. Downgrading NO_SNAPSHOTS to non-retryable here would strand those recordings as// permanently ineligible, so the player's own verdict has to survive.const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())const startPromise = controller.waitForStart(basePlayerConfig(), 5000)@@ -195,7 +195,7 @@ describe('PlayerController', () => {it('isEnded() returns true after ended message', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())expect(controller.isEnded()).toBe(false)@@ -205,7 +205,7 @@ describe('PlayerController', () => {it('getError() returns stored error from message received outside active promise', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())expect(controller.getError()).toBeNull()@@ -226,7 +226,7 @@ describe('PlayerController', () => {it('getInactivityPeriods() returns periods from player', async () => {const mp = mockCapturePage()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())expect(controller.getInactivityPeriods()).toEqual([])@@ -243,7 +243,7 @@ describe('PlayerController', () => {it('onProgress is called on loading_progress messages', async () => {const mp = mockCapturePage()const onProgress = jest.fn()- const controller = new PlayerController(mp.capturePage, mockBlockProxy, onProgress)+ const controller = new PlayerController(mp.capturePage, mockBlockProxy, 1, onProgress)await controller.load(basePlayerConfig())mp._emit({ type: 'loading_progress', loaded: 1, total: 5 })@@ -255,7 +255,7 @@ describe('PlayerController', () => {it('startPlayback() dispatches the start event', async () => {const { capturePage, page } = mockCapturePage()- const controller = new PlayerController(capturePage, mockBlockProxy, jest.fn())+ const controller = new PlayerController(capturePage, mockBlockProxy, 1, jest.fn())await controller.load(basePlayerConfig())await controller.startPlayback()diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/request-interceptor.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/request-interceptor.test.tsindex c9fa69180efd..7287cc030a97 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/request-interceptor.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/request-interceptor.test.ts@@ -1,6 +1,7 @@import { brotliCompressSync, deflateSync, gzipSync } from 'node:zlib'import { Frame, HTTPRequest, Page } from 'puppeteer'+import { fetchAttribution } from '~/common/utils/fetch-attribution'import { BlockProxy } from '~/session-replay/recording-rasterizer/capture/block-proxy'import { CapturePage } from '~/session-replay/recording-rasterizer/capture/capture-page'import { RequestInterceptor } from '~/session-replay/recording-rasterizer/capture/request-interceptor'@@ -92,6 +93,8 @@ function respondedWith(req: HTTPRequest): Promise<unknown> {)}+const teamId = 42+const mockLog = {info: jest.fn(),warn: jest.fn(),@@ -116,7 +119,7 @@ async function createInterceptor(const mp = page ? { page, emitRequestFinished: () => {}, emitRequestFailed: () => {} } : mockPage()const bp = blockProxy || mockBlockProxy()const cp = mockCapturePage(mp.page)- const interceptor = new RequestInterceptor(cp, bp, mockLog, enablePlayerCsp)+ const interceptor = new RequestInterceptor(cp, bp, teamId, mockLog, enablePlayerCsp)await interceptor.install()return { interceptor, page: mp as ReturnType<typeof mockPage>, blockProxy: bp }}@@ -192,7 +195,7 @@ describe('RequestInterceptor', () => {])('serves a 500 with no CSP when $name', async ({ html }) => {const mp = mockPage()const cp = { page: mp.page, playerUrl, playerHtml: html } as unknown as CapturePage- const interceptor = new RequestInterceptor(cp, mockBlockProxy(), mockLog, true)+ const interceptor = new RequestInterceptor(cp, mockBlockProxy(), teamId, mockLog, true)await interceptor.install()const handler = getRequestHandler(mp.page)const req = mockRequest('document', mainFrame, playerUrl)@@ -230,7 +233,11 @@ describe('RequestInterceptor', () => {})it('proxies sub-frame stylesheet requests through Node.js', async () => {- mockFetch.mockResolvedValue(streamedResponse({ body: 'body { color: red }' }))+ let attribution: Record<string, unknown> | undefined+ mockFetch.mockImplementation(() => {+ attribution = fetchAttribution.getStore()+ return Promise.resolve(streamedResponse({ body: 'body { color: red }' }))+ })const { page } = await createInterceptor()const handler = getRequestHandler(page.page)@@ -249,6 +256,7 @@ describe('RequestInterceptor', () => {headers: { 'access-control-allow-origin': '*' },body: Buffer.from('body { color: red }'),})+ expect(attribution).toEqual({ teamId })})it('aborts sub-frame media requests immediately', async () => {@@ -413,7 +421,7 @@ describe('RequestInterceptor', () => {const mp = mockPage()const bp = mockBlockProxy()const cp = mockCapturePage(mp.page)- const interceptor = new RequestInterceptor(cp, bp, mockLog)+ const interceptor = new RequestInterceptor(cp, bp, teamId, mockLog)await interceptor.install()const handler = getRequestHandler(mp.page)@@ -442,7 +450,7 @@ describe('RequestInterceptor', () => {const mp = mockPage()const bp = mockBlockProxy()const cp = mockCapturePage(mp.page)- const interceptor = new RequestInterceptor(cp, bp, mockLog)+ const interceptor = new RequestInterceptor(cp, bp, teamId, mockLog)await interceptor.install()const handler = getRequestHandler(mp.page)@@ -468,7 +476,7 @@ describe('RequestInterceptor', () => {const mp = mockPage()const bp = mockBlockProxy()const cp = mockCapturePage(mp.page)- const interceptor = new RequestInterceptor(cp, bp, mockLog)+ const interceptor = new RequestInterceptor(cp, bp, teamId, mockLog)await interceptor.install()const handler = getRequestHandler(mp.page)@@ -498,7 +506,7 @@ describe('RequestInterceptor', () => {const mp = mockPage()const bp = mockBlockProxy()const cp = mockCapturePage(mp.page)- const interceptor = new RequestInterceptor(cp, bp, mockLog)+ const interceptor = new RequestInterceptor(cp, bp, teamId, mockLog)await interceptor.install()const handler = getRequestHandler(mp.page)diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/player.ts b/nodejs/src/session-replay/recording-rasterizer/capture/player.tsindex 79f5fca60e52..cef4ee786e79 100644--- a/nodejs/src/session-replay/recording-rasterizer/capture/player.ts+++ b/nodejs/src/session-replay/recording-rasterizer/capture/player.ts@@ -43,13 +43,14 @@ export class PlayerController {constructor(capturePage: CapturePage,blockProxy: BlockSource,+ teamId: number,onProgress: () => void,log: Logger = createLogger()) {this.capturePage = capturePagethis.log = logthis.onProgress = onProgress- this.interceptor = new RequestInterceptor(capturePage, blockProxy, this.log)+ this.interceptor = new RequestInterceptor(capturePage, blockProxy, teamId, this.log)}get page(): Page {diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/recorder.ts b/nodejs/src/session-replay/recording-rasterizer/capture/recorder.tsindex 5f334d1cd680..99775ab951e4 100644--- a/nodejs/src/session-replay/recording-rasterizer/capture/recorder.ts+++ b/nodejs/src/session-replay/recording-rasterizer/capture/recorder.ts@@ -119,7 +119,7 @@ export async function rasterizeRecording(}const playerConfig = buildPlayerConfig(input, captureConfig.playbackSpeed, blockCount)- player = new PlayerController(capturePage, blockProxy, onProgress, log)+ player = new PlayerController(capturePage, blockProxy, input.team_id, onProgress, log)log.info('loading player')await player.load(playerConfig)diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/request-interceptor.ts b/nodejs/src/session-replay/recording-rasterizer/capture/request-interceptor.tsindex 4a6b1693260d..546aab669538 100644--- a/nodejs/src/session-replay/recording-rasterizer/capture/request-interceptor.ts+++ b/nodejs/src/session-replay/recording-rasterizer/capture/request-interceptor.ts@@ -3,6 +3,7 @@ import { promisify } from 'node:util'import { brotliDecompress, gunzip, inflate } from 'node:zlib'import { Frame, HTTPRequest } from 'puppeteer'+import { fetchAttribution } from '~/common/utils/fetch-attribution'import { fetchStreamed } from '~/common/utils/request'import { config } from '~/session-replay/recording-rasterizer/config'import { type Logger, createLogger } from '~/session-replay/recording-rasterizer/logger'@@ -42,6 +43,7 @@ export class RequestInterceptor {constructor(private capturePage: CapturePage,private blockProxy: BlockSource,+ private teamId: number,private log: Logger = createLogger(),private enablePlayerCsp: boolean = config.enablePlayerCsp) {@@ -176,7 +178,10 @@ export class RequestInterceptor {headers[name] = browserHeaders[name]}}- const resp = await fetchStreamed(url, { headers, timeoutMs: PROXY_TIMEOUT_MS })+ // The URL checks inside fetchStreamed read the team for their log lines from this store.+ const resp = await fetchAttribution.run({ teamId: this.teamId }, () =>+ fetchStreamed(url, { headers, timeoutMs: PROXY_TIMEOUT_MS })+ )const { bytes, overLimit } = await resp.read(MAX_STYLESHEET_BYTES, false)if (overLimit) {throw new Error(`stylesheet is larger than ${MAX_STYLESHEET_BYTES} bytes`)diff --git a/posthog/test/repo_invariants/oob_denylist_coverage_baseline.txt b/posthog/test/repo_invariants/oob_denylist_coverage_baseline.txtindex a1127a33e4a5..335c4662fb2d 100644--- a/posthog/test/repo_invariants/oob_denylist_coverage_baseline.txt+++ b/posthog/test/repo_invariants/oob_denylist_coverage_baseline.txt@@ -1,5 +1,3 @@-nodejs/src/cdp/services/messaging/email-validation.service.ts-nodejs/src/common/utils/request.tsnodejs/src/ingestion/pipelines/errortracking/cymbal/client.tsposthog/api/proxy_record_diagnostics.pyposthog/api/utils.pydiff --git a/posthog/test/repo_invariants/test_oob_denylist_coverage.py b/posthog/test/repo_invariants/test_oob_denylist_coverage.pyindex a0222ee79839..37ec8fc15c21 100644--- a/posthog/test/repo_invariants/test_oob_denylist_coverage.py+++ b/posthog/test/repo_invariants/test_oob_denylist_coverage.py@@ -36,7 +36,15 @@ RESOLUTION_MARKERS = ("trust_dns",)-CHECK_MARKERS = ("matched_oob_domain", "note_oob_domain", "OOB_DOMAINS", "oob_domains")+CHECK_MARKERS = (+ "matched_oob_domain",+ "note_oob_domain",+ "OOB_DOMAINS",+ "oob_domains",+ # The TypeScript mirror names the same two helpers in camel case.+ "matchedOobDomain",+ "noteOobDomain",+)SKIPPED_PARTS = ("node_modules", "__pycache__", "target", "dist", "migrations")