Skip to content

fix: preserve authored CSP in relative HTML previews - #188013

Merged
shakkernerd merged 5 commits into
mainfrom
html-preview-csp
Oct 30, 2026
Merged

shakkernerd merged 5 commits into
mainfrom
html-preview-csp

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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:

Check Observed result
Authored policy and external assets Policy text unchanged; stylesheet applied and classic scripts execute in declared order
Inline script/style, connect, storage and parent access Disallowed execution/styles/network remain blocked; storage and parent document access denied
Source, Download and resource bytes Match the original UTF-8 files; resource responses use private, no-store without a CORS grant
Unknown resource, unadmitted query, escaped path and mixed preview locator HTTP 404, no resource bytes
Release and strict-mode replacement The previously working resource URL changes from HTTP 200 to 404
Revoked device token Current resource URL returns HTTP 404
Production ingress ownership Issuing ingress grant returns HTTP 200 with exact bytes; a different grant and disconnected issuer return 404; revoked ingress is rejected
Unsupported module or CSS import Explicit Source/Download recovery; no preview grant for the rejected import

The 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

Open preview

Before After
Baseline preview is unstyled with zero records and disabled controls Fixed preview applies its stylesheet, initializes three records and denies storage and network access

Add/export and Source recovery at half speed, with input captions

proof.mp4

Visual verification

  • Baseline: 9fa6391
  • Exact head: 0b82e020832d87f445595c3612b25c72b0189bee
  • Scenario: Open the same synthetic inspection page with relative CSS and deferred classic scripts; add a record and export JSON while preserving its policy and opaque sandbox.
  • Runtime/build: Real Gateway and headless Chromium; assets/index-x5QxQwTE.js; SHA256 2f05d8b396243e2c70edfaa559ca2751e73d397adc310b8ca80fa2ff2632fb99
  • Initialization: 0 → 3 records; external CSS applied and deferred script order preserved
  • Interaction: Add inspection produces 4 records; exported JSON includes Garden
  • Policy controls: Inline script/style, connect, storage and parent document access remain denied
  • Resource lifetime: Assertions confirm active resource HTTP 200 → 404 on release, strict-mode replacement and device-token revocation
  • Identical synthetic fixture, 1440 × 1000 viewport and light theme; baseline footer lacks the source-build badge outside the preview pane
  • The unchanged baseline fails the initialization assertion; the exact fixed-head real-Gateway scenario passes
  • The full recording and matched screenshots were inspected; original raw recordings retained
  • The video ends during a mode-change loading state; final reload, HTTP authorization and byte equality are assertion evidence
  • Original Source/Download bytes remain unchanged; storage-dependent applications retain their existing limitation

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: XL labels Oct 30, 2026
@shakkernerd shakkernerd self-assigned this Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 0b82e020832d87f445595c3612b25c72b0189bee
  • Maintainer: @shakkernerd
  • Repository role: maintain

These security sensitive changes were made:

  • src/gateway/mcp-app-sandbox-http.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/methods/core-descriptor-options.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/methods/core-descriptors.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-method-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/shared/session-method-scopes-base.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: The preview is unstyled, displays zero records, and leaves controls disabled.
  • After: The preview displays three records with styling and working controls while storage and prohibited network access remain denied.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, bounded repair with production-entry-point evidence and no discrete introduced defect; the failed CI gate still requires attribution before landing.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied exact-head real Gateway/Chromium results and inspected screenshots exercise Files Preview initialization, styling, deferred ordering, interaction, CSP denial, original bytes, and grant retirement; production ingress results additionally cover foreign-grant rejection and disconnected or revoked issuance.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Available relative styles and scripts are blocked after Preview converts them into inline content.
Reason: The maintainer-approved bounded repair restores useful previews while preserving authored policy, sandbox isolation, and original-file recovery.

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
Reviewed head: 0b82e020832d87f445595c3612b25c72b0189bee

Before merge

None.

Findings

None.

Agent review details

How this fits together

Control 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]
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +1112, Tests +1263, Docs +33, Other +2. Total +2410 across 49 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 29 3519 2407 +1112
Tests 18 1280 17 +1263
Docs 1 33 0 +33
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 49 4834 2424 +2410

Review metrics

Metric Value Why it matters
Gateway protocol additions 2 additive RPC methods Preview admission and explicit release extend the existing session-file method family without adding configuration or persisted state.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #187905
Summary: This PR implements the candidate repair for the linked authored-CSP preview defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The defect breaks relative-asset rendering for a bounded class of HTML previews while Source and Download remain available.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-30T01:36:00.075Z sha f161909 :: needs real behavior proof before merge. :: [P2] Keep the sandbox HTTP dependency graph off the state database | [P2] Update the browser-runner contract for the new Gateway scenario | [P2] Move the suppression inventory with the extracted file owner

Reviewed October 29, 2026, 11:35 PM ET / October 30, 2026, 03:35 UTC (Revision 2).

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 30, 2026
@shakkernerd

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 30, 2026
@shakkernerd
shakkernerd merged commit db60454 into main Oct 30, 2026
274 of 276 checks passed
@shakkernerd
shakkernerd deleted the html-preview-csp branch October 30, 2026 04:37
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: HTML previews with supported self-only CSP now load relative stylesheets and classic scripts within the existing sandbox.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTML Files Preview blocks allowed relative CSS and scripts under authored CSP

1 participant