Repository navigation
fix: preserve authored CSP in relative HTML previews - #188013
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. What this changesThis PR preserves authored CSP while loading supported relative HTML resources through the existing isolated sandbox. Example: Open index.html referencing styles.css, data.js, and app.js under the supported self-only CSP.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a confirmed preview defect, resolves the three earlier findings, and has no new actionable code finding. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherControl UI sends preview HTML to the session-file owner, which admits relative resources and serves unchanged bytes through connection-bound grants on the isolated sandbox listener. flowchart LR
A[Files Preview] --> B[Session file owner]
B --> C[Relative resource admission]
C --> D[Existing download grants]
D --> E[Isolated sandbox listener]
E --> F[Opaque browser frame]
Technical reviewBest possible solution: Retain the bounded external-resource path under the existing file-read authority, grant lifecycle, and opaque sandbox. Do we have a high-confidence way to reproduce the issue? Current-main source explains the CSP rejection, and supplied matched browser evidence records the baseline initialization failure and fixed-head success; this review ran no target code. Is this the best way to solve the issue? The smallest coherent repair preserves external loading for the approved policy subset, shares resource parsing, and reuses existing authority and transport owners instead of weakening CSP. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 45893d3ee45e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +1112, Tests +1263, Docs +33, Other +2. Total +2410 across 49 files. Added test files: 2. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 29, 2026, 11:35 PM ET / October 30, 2026, 03:35 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Fixed: HTML previews with supported self-only CSP now load relative stylesheets and classic scripts within the existing sandbox. |
Restore relative classic-script and stylesheet loading for supported authored self-only CSP previews while preserving sandbox restrictions and original Source/Download bytes. Fixes openclaw#187905.
Fixes #187905
What Problem This Solves
Files Preview can fetch a document's relative CSS and JavaScript successfully and still show an uninitialized page when its authored Content Security Policy permits only same-origin scripts and styles. The existing preview converts those external files into inline content. The browser then blocks that content under the unchanged policy, leaving the document unstyled or its controls disabled even though the original files work together.
User Impact
The supported self-only policy subset can load its relative classic scripts and styles in Preview while the browser continues to enforce the authored policy. The preview remains an opaque sandbox: access to localStorage and the surrounding application remains unavailable, and Source and Download retain the original file bytes. Ordinary HTML previews keep their existing asset-inlining path.
Support is deliberately bounded. Complex policies, external modules, CSS imports, font loading, and integrity or cross-origin loading attributes use the existing Source/Download recovery with an explicit limitation message. Relative resources resolve at generated preview URLs; documents that depend on their original location or on persistent browser storage may still require downloading the files.
Why This Change Was Made
The correction retains the external-resource loading model that the policy author selected. The session-file owner admits a finite set of authorized relative resources, and the existing isolated sandbox listener serves them through the existing connection-bound grant lifecycle. The inner document inherits that generated resource base, so its policy and relative URL text do not need rewriting.
Resource requests reread through the current file/session authority and must still match the admitted bytes and MIME type. Closing or replacing the preview retires its grant, and client disconnection, access revocation, and expiry invalidate further reads. Admission rejects unsupported syntax before creating a grant; the browser remains responsible for applying the policy at the generated URL.
Evidence
A real Gateway/browser scenario opens a synthetic HTML inspection page through the Files panel with its authored self-only policy intact. On the unchanged baseline, the preview loads but remains unstyled with zero records and disabled controls; the decisive initialization assertion fails. On 0b82e02, the same scenario initializes three records, applies the external stylesheet, runs deferred scripts in order, and adds a fourth record that appears in the exported JSON. The fixture uses no persistent storage; storage-dependent applications retain the existing limitation.
The same scenario checks policy and lifecycle behavior through the actual preview path. The production ingress integration additionally exercises resource delivery through the real ingress factory and sandbox HTTP handler:
private, no-storewithout a CORS grantThe focused browser case and all eight production ingress integration cases passed. Selected Gateway/UI consumer tests, affected type graphs, declaration compilation, structural checks and the ordinary-preview comparison also passed. A malformed-CSS admission probe exposed repeated suffix scans; returning at the first conclusive rejection reduces the median for the same 64 KiB input from 319.7 ms to 0.05 ms while preserving rejection and the valid stylesheet control. These are bounded parser measurements, not general preview latency claims.
The matched screenshots below use a 1440 × 1000 light-theme viewport and identical synthetic data. The recording shows initialization, Add inspection, Export JSON and Source recovery at half speed with factual input captions; nonvisual authority checks are established by the assertions above. The baseline footer lacks the source-build branch badge present after the change; the preview framing is unchanged.
Hosted CI passes after one native rerun of the recurring-plugin cron job. The rerun used the same code, pinned runtime, seven selected files and worker limit; its native retry route used GitHub-hosted capacity instead of Blacksmith. The earlier cron failure also occurred in one native reproduction, while the base and later samples passed. Its cause remains unexplained: this PR does not claim a cron fix or an inherited-failure classification. Current CI run, rerun job.
Visual evidence
Add/export and Source recovery at half speed, with input captions
proof.mp4
Visual verification
0b82e020832d87f445595c3612b25c72b0189bee