Skip to content

: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.

fix(session-replay): reject invalid configuration text (#88245)

Robbieb714480cfac6
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
index b5aa1b92f01d..cd15a4fb393a 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/README.md
@@ -191,6 +191,8 @@ XMP is an opt-out for that image when it has one of these values:
**3.22** The lane uses separate cache entries for robots.txt, tdmrep.json, and each URL crawl result. A robots.txt or tdmrep.json success, absence, or valid refusal has a 24-hour TTL. An unreachable result without a cached version has a 1-hour TTL. A terminal URL result has a minimum TTL of 30 days. If the response's explicit freshness lifetime is longer, the entry uses that longer TTL.
+**3.23** A retained configuration body must be valid UTF-8. If the 500KiB robots.txt prefix ends inside a UTF-8 code point, the lane discards that incomplete code point. Any other invalid UTF-8 makes the configuration file unreachable.
+
### 4. Web Bot Auth
**4.1** Our User Agent starts with `PostHogImageFetcherBot` and contains a link to https://posthog.com/docs/ai-research/image-fetcher-bot. An example value is `PostHogImageFetcherBot/1.0 (+https://posthog.com/docs/ai-research/image-fetcher-bot)`
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
index 5676391c2080..7a1921d2c125 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
@@ -329,7 +329,13 @@ describe('HttpConfigurationFetcher', () => {
it('uses the retained prefix when robots.txt exceeds its byte limit', async () => {
fetchStreamedMock.mockResolvedValue(
- response(200, [], { bytes: Buffer.from('User-agent: *\nDisallow: /private'), overLimit: true })
+ response(200, [], {
+ bytes: Buffer.concat([
+ Buffer.from('User-agent: *\nDisallow: /private'),
+ Buffer.from([0xf0, 0x9f, 0x98]),
+ ]),
+ overLimit: true,
+ })
)
await expect(httpFetcher().fetch(ORIGIN, 'robots')).resolves.toMatchObject({
@@ -338,6 +344,14 @@ describe('HttpConfigurationFetcher', () => {
})
})
+ it('treats invalid UTF-8 configuration text as unreachable', async () => {
+ fetchStreamedMock.mockResolvedValue(
+ response(200, [], { bytes: Buffer.from([0x75, 0x73, 0x65, 0x72, 0xff]), overLimit: false })
+ )
+
+ await expect(httpFetcher().fetch(ORIGIN, 'robots')).resolves.toMatchObject({ outcome: 'unreachable' })
+ })
+
it('treats an oversized or invalid TDMRep document as unreachable', async () => {
fetchStreamedMock
.mockResolvedValueOnce(response(200, [], { bytes: Buffer.from('[]'), overLimit: true }))
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
index 42ef18c9c5b8..9f1b33ec1c98 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
@@ -163,7 +163,12 @@ export class HttpConfigurationFetcher {
if (body.overLimit && file === 'tdmrep') {
return complete({ kind: 'done', result: { outcome: 'unreachable', cache } })
}
- const text = body.bytes.toString('utf8')
+ let text: string
+ try {
+ text = new TextDecoder('utf-8', { fatal: true }).decode(body.bytes, { stream: body.overLimit })
+ } catch {
+ return complete({ kind: 'done', result: { outcome: 'unreachable', cache } })
+ }
if (file === 'tdmrep' && !isValidTdmrepDocument(text)) {
return complete({ kind: 'done', result: { outcome: 'unreachable', cache } })
}