Skip to content

Regex-based HTML rewriting in document.write interception can fail-open #407

Closed

Description

@aram356

Summary

The GPT guard uses a regex to match and rewrite GPT domain script URLs in document.write calls. If the regex fails to match (escaped quotes, unusual spacing, mixed quote styles), the original unproxied URL is passed through, causing the browser to load the GPT script directly from Google's CDN instead of through the first-party proxy.

Refs

  • crates/js/lib/src/integrations/gpt/script_guard.ts lines 206-230 — rewriteHtmlString regex

Recommendation

Use DOM-based parsing (DOMParser) instead of regex, or fail-closed (block unmatched URLs rather than passing through).

Context

Production readiness audit — see #396

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

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions