: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
fix(replay): give the rasterizer browser a minimal environment (#104785)
Tom Piccirellof6b6ea734ff8
diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.tsindex 508847d29f56..d1d1b947c2bd 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts@@ -78,6 +78,28 @@ describe('BrowserPool', () => {expect(launchArgs).toContain('--crash-dumps-dir=/tmp/chrome-crash-dumps')})+ it('launches chrome with an allowlisted environment, not the worker environment', async () => {+ process.env.SECRET_KEY = 'worker-secret-key'+ process.env.INTERNAL_API_SECRET = 'worker-internal-secret'+ process.env.AWS_WEB_IDENTITY_TOKEN_FILE = '/var/run/secrets/token'+ process.env.HTTPS_PROXY = 'http://smokescreen:4750'+ const browser = mockBrowser()+ browser.newPage.mockResolvedValue(mockPage())+ puppeteerCapture.launch.mockResolvedValue(browser)++ pool = new BrowserPool(100)+ await pool.getPage()++ const env = puppeteerCapture.launch.mock.calls[0][0].env as NodeJS.ProcessEnv+ expect(env).not.toHaveProperty('SECRET_KEY')+ expect(env).not.toHaveProperty('INTERNAL_API_SECRET')+ expect(env).not.toHaveProperty('AWS_WEB_IDENTITY_TOKEN_FILE')+ expect(env.PATH).toBe(process.env.PATH)+ // Without --proxy-server, Chrome reads the proxy environment. Passing it would route Chrome+ // through the proxy even after RASTERIZER_USE_PROXY=false asks for direct egress.+ expect(env).not.toHaveProperty('HTTPS_PROXY')+ })+it('launches separate browsers for concurrent pages', async () => {const browser1 = mockBrowser()const browser2 = mockBrowser()diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts b/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.tsindex c340b502259c..0d803e37fd7a 100644--- a/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts+++ b/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts@@ -34,6 +34,43 @@ function resolveProxyArgs(): string[] {]}+// Chrome renders recording content the customer's visitors produced, so it must not hold the+// worker's secrets in its address space. puppeteer-core defaults the browser environment to this+// process's own, which carries SECRET_KEY, INTERNAL_API_SECRET and the pod's AWS credentials, so the+// launch names what Chrome gets instead.+const CHROME_ENV_ALLOWLIST = [+ // Chrome resolves its helper binaries through PATH.+ 'PATH',+ // Chrome puts its profile, cache and crash state below HOME, or below the XDG paths when set.+ 'HOME',+ 'XDG_CONFIG_HOME',+ 'XDG_CACHE_HOME',+ 'XDG_RUNTIME_DIR',+ // The container root filesystem is read-only, so temporary files must go where TMPDIR points.+ 'TMPDIR',+ // The locale decides text shaping, and the timezone decides the timestamps the player draws.+ 'LANG',+ 'LANGUAGE',+ 'LC_ALL',+ 'LC_CTYPE',+ 'TZ',+ // fontconfig reads these when an image keeps its font configuration outside /etc/fonts. Without+ // the fonts, the rendered frames fall back to boxes.+ 'FONTCONFIG_PATH',+ 'FONTCONFIG_FILE',+]++function chromeEnv(): NodeJS.ProcessEnv {+ const env: NodeJS.ProcessEnv = {}+ for (const name of CHROME_ENV_ALLOWLIST) {+ const value = process.env[name]+ if (value !== undefined) {+ env[name] = value+ }+ }+ return env+}+interface BrowserSlot {browser: BrowserusageCount: number@@ -66,6 +103,7 @@ export class BrowserPool {const browser = await launchForCapture({executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,args: this.launchArgs(),+ env: chromeEnv(),})RasterizationMetrics.browserLaunched()const slot: BrowserSlot = { browser, usageCount: 0 }