Skip to content

Fix oversized preview response headers - #60

Merged
ruibaby merged 2 commits into
mainfrom
fix/preview-response-header-size
Nov 5, 2026
Merged

ruibaby merged 2 commits into
mainfrom
fix/preview-response-header-size

Conversation

@ruibaby

@ruibaby ruibaby commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Preview responses include every allowed public API path in the Content-Security-Policy header. A large API catalog can exceed reverse-proxy response-header buffers and cause preview requests to return 502.

Move the variable-size policy into a CSP meta element at the start of the document head, before theme resources and scripts. Keep sandbox allow-scripts in the HTTP response header because meta-delivered CSP cannot enforce sandboxing. Apply this to both Console previews and token previews while preserving the complete API allowlist and token isolation.

Ordinary previews locate the head insertion point using parser source positions and insert the policy into the original HTML. This preserves CSS-sensitive whitespace and leading newlines in <pre> without reserializing the document. Six regression cases cover explicit and implicit heads, comments, quoted attributes, and script text containing a literal <head>.

Regression coverage renders both preview types with 300 public API paths. Before the fix, the CSP header exceeds 16 KiB. After the fix, response headers remain below 1 KiB, every allowed path remains in the document policy, and Content-Length matches the rewritten UTF-8 body.

Validation:

  • 174 related backend tests passed, covering preview rendering, isolation, endpoints, API discovery, storage, asset CORS, and content validation.
  • Java formatting and git diff --check passed.
  • A local Chromium policy fixture verified both preview forms: allowlisted API requests succeed, Console API requests are blocked, and cookie access throws SecurityError.
  • A local Chromium rendering fixture verified that preserved whitespace and leading <pre> newlines match the original document after the fix.
  • The reported production response headers were not captured, and the fix has not been deployed or verified behind the production Nginx instance.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T07:40:15.847381Z e86c18e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ruibaby
ruibaby merged commit e756fb1 into main Nov 5, 2026
1 check passed
@ruibaby
ruibaby deleted the fix/preview-response-header-size branch November 5, 2026 07:47
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.

1 participant