Skip to content

fix(frontend): drop exceptions from code injected into the page - #3278

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixfrontend-drop-exceptions-from-code-3a4ed5
Draft

fix(frontend): drop exceptions from code injected into the page#3278
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixfrontend-drop-exceptions-from-code-3a4ed5

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Problem

  • Error tracking opened a TypeError issue for a snippet run inside the /apps page (Array.from(document.querySelectorAll('td')).find(...).outerHTML) — that selector exists nowhere in our code.
  • A console paste, a browser extension, or an AI browser agent walking the DOM looks exactly like this: one in-app frame whose file is the page URL, function global code, line 1. Code we ship always runs from a hashed chunk under /assets/.
  • Cost is triage, not users (1 event, 1 user, 1 session): every injected snippet that throws mints a fresh issue with a first-seen alert, and someone burns time proving it is not ours.

Changes

  • shouldSuppressPostHogExceptionEvent matched message text only and never looked at frames. Added a frame-based rule: drop an $exception whose only in-app frame points at the document URL itself.
  • The rule compares each in-app frame filename against $current_url (both with query and hash stripped). A frame that is the page document, not an /assets/ chunk, is injected code.
  • This kills the whole class of injected-code exceptions, not just this one message.

Test plan

  • bunx vitest run tests/stale-asset-errors.unit.test.ts — new cases cover the console-paste TypeError (dropped), a genuine bundled-asset error on the same page (kept), and the empty / missing-URL / non-in-app edge cases.

Screenshots

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

Add a frame-based rule to the PostHog before_send noise filter. An $exception
whose only in-app frame points at the HTML document itself comes from a console
paste, a browser extension, or an AI browser agent, not from code we ship. Our
own code always runs from a hashed chunk under /assets/, so this rule drops the
whole class instead of matching one message.

Generated-By: PostHog Desktop
Task-Id: a5ed4288-9ed1-4dec-a4e8-9efa518685cf
@posthog-eu
posthog-eu Bot deployed to deepsec-pr September 8, 2026 11:40 Active
@codspeed-hq

codspeed-hq Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixfrontend-drop-exceptions-from-code-3a4ed5 (6cb24ae) with main (225fedb)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants