Skip to content

[FIX] Frontend CSP: add unsafe-eval for RJSF and blob: for PDF viewer - #1875

Merged
hari-kuriakose merged 1 commit into
mainfrom
fix/frontend-csp-unsafe-eval-blob
Mar 25, 2026
Merged

hari-kuriakose merged 1 commit into
mainfrom
fix/frontend-csp-unsafe-eval-blob

Conversation

@vishnuszipstack

@vishnuszipstack vishnuszipstack commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

What

  • Add 'unsafe-eval' to script-src in frontend nginx CSP header
  • Add blob: to connect-src in frontend nginx CSP header

Why

  • RJSF (React JSON Schema Form) uses new Function() to compile JSON schemas at runtime, which requires 'unsafe-eval'. Without it, the Adapter Test Connection dialog and API deployment pages throw CSP errors and fail to render forms.
  • PDF.js viewer loads documents via blob: URLs. Without blob: in connect-src, Prompt Studio shows "Failed to Load PDF" errors and documents cannot be displayed.

How

  • Modified frontend/nginx.conf CSP header:
    • Added 'unsafe-eval' to script-src directive
    • Added blob: to connect-src directive

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No breakage expected. This PR only relaxes two CSP directives to allow functionality that was being incorrectly blocked. No existing behavior is restricted or changed.

Database Migrations

  • None

Relevant Docs

Related Issues or PRs

Dependencies Versions

  • No new dependencies

Notes on Testing

  • Verify LLM adapter "Test Connection" dialog works without CSP errors in browser console
  • Verify API deployment page loads without white screen
  • Verify PDF documents display correctly in Prompt Studio
  • Check browser console for any remaining CSP violations

Screenshots

N/A

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

- Add 'unsafe-eval' to script-src: RJSF (React JSON Schema Form) uses
  new Function() to compile schemas, blocked without this directive
- Add blob: to connect-src: PDF.js viewer loads documents via blob: URLs
  which were being blocked, causing "Failed to Load PDF" errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Frontend Lint Report (Biome)

All checks passed! No linting or formatting issues found.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 094f8258-d637-4a12-bad2-c0b63100d422

📥 Commits

Reviewing files that changed from the base of the PR and between bf15e8d and 7f44be8.

📒 Files selected for processing (1)
  • frontend/nginx.conf

Summary by CodeRabbit

  • Chores
    • Updated web server security configuration to support additional application requirements and improve platform compatibility.

Walkthrough

Updated the Content-Security-Policy header in nginx configuration to allow 'unsafe-eval' for scripts and blob: protocol for connections, with corresponding inline documentation updates.

Changes

Cohort / File(s) Summary
CSP Security Configuration
frontend/nginx.conf
Updated Content-Security-Policy header: added 'unsafe-eval' to script-src directive and blob: to connect-src directive. Inline comments updated to document these new allowances.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: adding 'unsafe-eval' for RJSF and 'blob:' for PDF viewer to the frontend CSP.
Description check ✅ Passed The description comprehensively covers all required template sections with clear, detailed information about what, why, how, potential breakage, testing notes, and related documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/frontend-csp-unsafe-eval-blob

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR relaxes two CSP directives in frontend/nginx.conf to fix two separate runtime breakages introduced by the parent PR #1834:

  • 'unsafe-eval' in script-src: Unblocks RJSF (new Function() usage) so that the Adapter Test Connection dialog and API deployment pages render correctly.
  • blob: in connect-src: Unblocks PDF.js's internal fetch() of blob-URL documents so that Prompt Studio can display PDFs.

Key observations:

  • The blob: addition to connect-src is low-risk — blob: URLs are origin-scoped and cannot be used to exfiltrate data to external hosts.
  • The 'unsafe-eval' addition is functionally correct and well-commented, but it is a meaningful security trade-off: combined with the existing 'unsafe-inline' in script-src, the policy no longer restricts dynamic code execution at all — only script origins are enforced. Any future XSS vulnerability in the app would be more exploitable with this directive present.
  • It is worth investigating whether RJSF v5's configurable validators (e.g. ajv8) or nonce-based approaches could restore unsafe-eval restriction in a follow-up, rather than leaving it as a permanent exception.

Confidence Score: 3/5

  • Functional fix for real breakages, but unsafe-eval combined with unsafe-inline in script-src leaves CSP providing only origin-based script restriction — worth a follow-up investigation before treating as permanent.
  • The blob: addition to connect-src is safe and well-scoped. The unsafe-eval addition is the pragmatic fix for a genuine RJSF requirement, but it represents a cumulative security weakening (both unsafe-inline and unsafe-eval are now present). The change is in a configuration file only and introduces no runtime logic errors, but the security trade-off warrants careful consideration before merging into production.
  • frontend/nginx.conf — specifically the combination of 'unsafe-inline' and 'unsafe-eval' in script-src

Important Files Changed

Filename Overview
frontend/nginx.conf Adds 'unsafe-eval' to script-src (for RJSF) and blob: to connect-src (for PDF.js). The blob: addition is low-risk and well-justified; the unsafe-eval addition is functionally correct but materially weakens CSP XSS protection since 'unsafe-inline' was already present.

Sequence Diagram

sequenceDiagram
    participant Browser
    participant Nginx
    participant RJSF as RJSF (React JSON Schema Form)
    participant PDFjs as PDF.js Viewer

    Browser->>Nginx: GET /index.html
    Nginx-->>Browser: Response + CSP Header
    Note over Browser,Nginx: script-src now includes 'unsafe-eval'<br/>connect-src now includes blob:

    Browser->>RJSF: Render schema form
    RJSF->>Browser: new Function() to compile schema
    Note over Browser,RJSF: Previously blocked by CSP (no unsafe-eval)<br/>Now allowed ✓

    Browser->>PDFjs: Load PDF document
    PDFjs->>Browser: URL.createObjectURL() → blob: URL
    Browser->>Browser: fetch(blob:...) for PDF data
    Note over Browser,PDFjs: Previously blocked by CSP (no blob: in connect-src)<br/>Now allowed ✓
    PDFjs-->>Browser: PDF rendered successfully
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: frontend/nginx.conf
Line: 58

Comment:
**`unsafe-eval` significantly weakens XSS protection**

Adding `'unsafe-eval'` to `script-src` is a notable security relaxation. With both `'unsafe-inline'` and `'unsafe-eval'` now present in `script-src`, the CSP offers minimal protection against XSS: any injected string can be executed via `eval()` or `new Function()`, and inline scripts are also allowed. The CSP essentially only restricts script *sources* now.

Before accepting this as a permanent fix, it's worth investigating whether RJSF's dependency on `new Function()` can be scoped or avoided:

1. **RJSF v5** introduced a `noHtml5Validate` prop and custom validator support (`ajv8` validator) — check whether the specific RJSF feature triggering `new Function()` can be replaced with a stricter validator that avoids dynamic code generation.
2. Alternatively, some bundlers (e.g. webpack `nonce`-based approaches) can emit a CSP nonce so that only specific inline/eval uses are allowed rather than blanket-enabling it for all scripts.

If this is genuinely unavoidable, the comment is helpful, but it would be worth adding a TODO or linking the upstream RJSF issue so future contributors can re-evaluate when the library matures.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Fix frontend CSP: add unsafe-eval for RJ..." | Re-trigger Greptile

Comment thread frontend/nginx.conf

@hari-kuriakose hari-kuriakose left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishnuszipstack LGTM overall

@hari-kuriakose
hari-kuriakose merged commit d84b724 into main Mar 25, 2026
8 checks passed
@hari-kuriakose
hari-kuriakose deleted the fix/frontend-csp-unsafe-eval-blob branch March 25, 2026 05:15
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.

3 participants