openclaw - ✅(Solved) Fix Control UI CSP blocks tweakcn theme import fetch [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#78504Fetched 2026-05-07 03:36:09
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
3
Author
Timeline (top)
commented ×2cross-referenced ×1referenced ×1

Error Message

The error in the browser console is: 4. Observe "Failed to fetch" error 5. Check browser DevTools Console — CSP violation error appears

Root Cause

The CSP is set in two places:

  1. HTTP response header (Content-Security-Policy) in the gateway's Control UI handler — buildControlUiCspHeader() only allows connect-src 'self' ws: wss: https://api.openai.com
  2. Meta tag in the built Control UI JS bundle — same restrictive connect-src

Neither includes https://tweakcn.com, so the browser blocks the cross-origin fetch.

Fix Action

Workaround

Manually patching the CSP in the built bundle and restarting the gateway works temporarily, but is overwritten on update.

PR fix notes

PR #78543: fix(gateway): allow tweakcn.com in Control UI CSP connect-src

Description (problem / solution / changelog)

Summary

The Control UI fetches https://tweakcn.com/r/themes/<id> directly from the browser when importing custom themes, but the served CSP did not include that origin in connect-src. This aligns the CSP with the approved direct-fetch design documented in the tweakcn custom-theme import spec.

Changes

  • Added https://tweakcn.com to the connect-src directive in buildControlUiCspHeader()
  • Updated control-ui-csp.test.ts to expect the new origin in the CSP allowlist
  • Added changelog entry under Unreleased

Testing

  • pnpm test src/gateway/control-ui-csp.test.ts — CSP unit test updated to assert the new origin is present
  • pnpm test src/gateway/control-ui.http.test.ts — HTTP handler test passes (no CSP assertion changes needed)

Real behavior proof

Screen recording demonstrating the fix:

The video shows a local Control UI session where a tweakcn share link is imported via Appearance → Custom Theme → Import from tweakcn. Before the fix, this triggers a CSP connect-src violation in the browser console. With the patched CSP (adding https://tweakcn.com to connect-src), the fetch succeeds and the theme is applied without any CSP errors.

https://github.com/user-attachments/assets/d3443157-71b7-4955-ae10-cade0bb0e89c

Key frames in the recording:

  • Control UI loads with the patched Gateway CSP
  • importCustomThemeFromUrl() resolves the tweakcn link to https://tweakcn.com/r/themes/{id}
  • The browser fetch completes (no violates the following Content Security Policy directive error)
  • Custom theme tokens are applied to the UI

Fixes openclaw/openclaw#78504


AI-assisted: Yes. This fix was identified, implemented, and tested with assistance from OpenClaw.

  • Mark as AI-assisted in the PR title or description
  • Include human-run real behavior proof from your own setup
  • Confirm I understand what the code does: the CSP connect-src directive is a browser security policy that restricts which origins the Control UI can fetch from. The tweakcn theme import feature was documented but broken in practice because the CSP allowlist did not include the origin the UI actually fetches from. This is a narrowly scoped allowlist addition.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/gateway/control-ui-csp.test.ts (modified, +1/-0)
  • src/gateway/control-ui-csp.ts (modified, +1/-1)

Code Example

Connecting to 'https://tweakcn.com/r/themes/{id}' violates the following Content Security Policy directive: "connect-src 'self' ws: wss: https://api.openai.com". The action has been blocked.
RAW_BUFFERClick to expand / collapse

Bug description

The Control UI's Content-Security-Policy (CSP) blocks client-side fetches to https://tweakcn.com when attempting to import custom themes via a tweakcn share link.

The error in the browser console is:

Connecting to 'https://tweakcn.com/r/themes/{id}' violates the following Content Security Policy directive: "connect-src 'self' ws: wss: https://api.openai.com". The action has been blocked.

Reproduction

  1. Open OpenClaw Control UI → Settings → Appearance
  2. Paste a tweakcn share link (e.g. https://tweakcn.com/themes/cmlh0x713000104jrgmds6vcd) into the custom theme import field
  3. Click Import
  4. Observe "Failed to fetch" error
  5. Check browser DevTools Console — CSP violation error appears

Root cause

The CSP is set in two places:

  1. HTTP response header (Content-Security-Policy) in the gateway's Control UI handler — buildControlUiCspHeader() only allows connect-src 'self' ws: wss: https://api.openai.com
  2. Meta tag in the built Control UI JS bundle — same restrictive connect-src

Neither includes https://tweakcn.com, so the browser blocks the cross-origin fetch.

Environment

  • OpenClaw version: 2026.5.5
  • Gateway mode: local
  • Control UI served from: http://localhost:18789

Workaround

Manually patching the CSP in the built bundle and restarting the gateway works temporarily, but is overwritten on update.

Suggested fix

Options:

  1. Proxy approach: Route tweakcn fetches through a gateway endpoint (e.g. /api/proxy/tweakcn/...) so the client never hits tweakcn directly — stays within connect-src 'self'
  2. CSP extension: Add https://tweakcn.com and https://*.tweakcn.com to the connect-src directive in both the server CSP header and the meta tag
  3. Config-driven CSP: Allow the gateway config to specify additional connect-src origins, or auto-populate based on enabled integrations

Related

  • Design doc: docs/superpowers/specs/2026-04-22-tweakcn-custom-theme-import-design.md
  • The feature was designed to normalize tweakcn payloads into a browser-local customTheme slot, but the actual fetch step is blocked by this policy.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING