[FIX] Frontend CSP: add unsafe-eval for RJSF and blob: for PDF viewer - #1875
Conversation
- 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>
Frontend Lint Report (Biome)✅ All checks passed! No linting or formatting issues found. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughUpdated the Content-Security-Policy header in nginx configuration to allow Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Greptile SummaryThis PR relaxes two CSP directives in
Key observations:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
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
Prompt To Fix All With AIThis 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 |
hari-kuriakose
left a comment
There was a problem hiding this comment.
@vishnuszipstack LGTM overall



What
'unsafe-eval'toscript-srcin frontend nginx CSP headerblob:toconnect-srcin frontend nginx CSP headerWhy
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.blob:URLs. Withoutblob:inconnect-src, Prompt Studio shows "Failed to Load PDF" errors and documents cannot be displayed.How
frontend/nginx.confCSP header:'unsafe-eval'toscript-srcdirectiveblob:toconnect-srcdirectiveCan 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)
Database Migrations
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
Screenshots
N/A
Checklist
I have read and understood the Contribution Guidelines.
🤖 Generated with Claude Code