openclaw - ✅(Solved) Fix Bug: Control UI CSP blocks Zod Function() constructor — 'eval' violation + 401 config fetch [1 pull requests, 2 comments, 3 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#78362Fetched 2026-05-07 03:37:50
View on GitHub
Comments
2
Participants
3
Timeline
3
Reactions
3
Author
Timeline (top)
commented ×2cross-referenced ×1

When opening the Control UI (http://127.0.0.1:18789/) in Chrome, the DevTools console shows repeated Content Security Policy violations:

Content Security Policy of your site blocks the use of 'eval' in JavaScript
Affected: index-BS51oJri.js:182
Directive: script-src
Status: blocked

Additionally, a 401 Unauthorized error appears for /__openclaw/control-ui-config.json on initial page load.

Error Message

Additionally, a 401 Unauthorized error appears for /__openclaw/control-ui-config.json on initial page load. 3. Observe CSP eval violations and 401 config fetch error

Root Cause

Occurs in both normal and incognito windows. Not caused by browser extensions.

Fix Action

Fixed

PR fix notes

PR #78366: fix(gateway): add 'unsafe-eval' to Control UI CSP script-src

Description (problem / solution / changelog)

Problem

Closes #78362

The Control UI gateway sets script-src 'self' without 'unsafe-eval'. Zod v4's JIT compiler calls new Function() in the bundled JS, which browsers treat identically to eval(). This causes:

  • CSP violations logged in DevTools for every page load
  • Zod validators falling back to slower non-JIT evaluation paths

Fix

Add 'unsafe-eval' to script-src in buildControlUiCspHeader. This correctly reflects what the bundled JS requires and eliminates the CSP violation.

Files changed

  • src/gateway/control-ui-csp.ts — add 'unsafe-eval' to both hash and no-hash script-src variants
  • src/gateway/control-ui-csp.test.ts — update assertions to match new directive

Test

All existing buildControlUiCspHeader tests updated. The 'unsafe-inline' guard is preserved — only eval-equivalent dynamic code execution is permitted, not arbitrary inline scripts.

Changed files

  • src/gateway/control-ui-csp.test.ts (modified, +6/-6)
  • src/gateway/control-ui-csp.ts (modified, +2/-2)

Code Example

Content Security Policy of your site blocks the use of 'eval' in JavaScript
Affected: index-BS51oJri.js:182
Directive: script-src
Status: blocked

---

Content-Security-Policy: default-src 'self'; base-uri 'none'; object-src 'none'; 
frame-ancestors 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; ...

---

// From the bundled JS:
compile() {
    let e = Function, 
        t = this?.args, 
        n = [...(this?.content ?? [""]).map(e => `  ${e}`)]; 
    return new e(...t, n.join("\n"))
}
RAW_BUFFERClick to expand / collapse

Description

When opening the Control UI (http://127.0.0.1:18789/) in Chrome, the DevTools console shows repeated Content Security Policy violations:

Content Security Policy of your site blocks the use of 'eval' in JavaScript
Affected: index-BS51oJri.js:182
Directive: script-src
Status: blocked

Additionally, a 401 Unauthorized error appears for /__openclaw/control-ui-config.json on initial page load.

Reproduction

  1. Open Control UI at http://127.0.0.1:18789/
  2. Open Chrome DevTools → Console / Issues panel
  3. Observe CSP eval violations and 401 config fetch error

Occurs in both normal and incognito windows. Not caused by browser extensions.

Root Cause

CSP eval() violation

The Gateway sends this CSP header for Control UI:

Content-Security-Policy: default-src 'self'; base-uri 'none'; object-src 'none'; 
frame-ancestors 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; ...

The script-src 'self' directive (without 'unsafe-eval') blocks new Function() calls.

However, the bundled JS (index-BS51oJri.js) contains Zod's JIT compilation code that uses the Function constructor:

// From the bundled JS:
compile() {
    let e = Function, 
        t = this?.args, 
        n = [...(this?.content ?? [""]).map(e => `  ${e}`)]; 
    return new e(...t, n.join("\n"))
}

This is Zod compiling dynamic validation code via new Function() which CSP's script-src treats identically to eval().

401 control-ui-config.json

The JS fires the config fetch in connectedCallback (before WebSocket auth is established), causing a 401 on initial load. The token hasn't been passed as a Bearer header yet.

Environment

  • OpenClaw: 2026.5.4 (325df3e)
  • OS: macOS 26.4.1 (arm64)
  • Browser: Chrome
  • Gateway: loopback (127.0.0.1:18789)
  • Auth mode: token

Suggested Fix

  1. CSP: Either add 'unsafe-eval' to the script-src directive, or configure Zod to disable JIT compilation (e.g., zod.jitless = true or equivalent). The latter is preferred for security.

  2. 401 config fetch: Move the /__openclaw/control-ui-config.json fetch to after WebSocket connection/auth is established, or have the JS gracefully retry with proper auth headers.

Impact

  • The Zod JIT compilation failure may cause validators to fall back to slower non-JIT paths. Functional impact unknown but potential edge-case breakage.
  • The 401 is cosmetic and self-resolves after page load.

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

openclaw - ✅(Solved) Fix Bug: Control UI CSP blocks Zod Function() constructor — 'eval' violation + 401 config fetch [1 pull requests, 2 comments, 3 participants]