-
Notifications
You must be signed in to change notification settings - Fork 2
[web] Self-host Monaco assets and harden CSP #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThis PR moves Monaco Editor assets to self-hosting, removes the monaco-editor-webpack-plugin, adds CopyPlugin patterns to copy Monaco runtime files into the build output, centralizes runtime loader configuration into a new loader-config module, adapts MonacoEditor to call that initializer, and tightens CSP by removing jsDelivr allowances. Changes
Sequence Diagram(s)mermaid Build->>Static: Copy monaco-editor/min/vs -> .next/static/monaco/vs\nCopy pdf.worker.min.mjs -> public/ Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 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)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip We've launched Issue Planner and it is currently in beta. Please try it out and share your feedback on Discord! 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/security/compliance-sovereignty-analysis.md`:
- Around line 342-345: The guidance currently recommends adding SRI hashes for
remaining third-party scripts but Stripe.js and Google One Tap
(accounts.google.com/gsi/client) do not support SRI; update the document to
remove or qualify the SRI recommendation for these two vendors by stating SRI
applies only where vendors publish/allow it (e.g., self-hosted Monaco and PDF.js
remain eligible), replace the SRI recommendation for Stripe.js and Google One
Tap with CSP allowlisting as the primary compensating control, and adjust the
"Effort" estimate to reflect low-medium for hardening plus minimal changes to
add CSP guidance and vendor-specific notes.
🧹 Nitpick comments (1)
apps/web/src/lib/editor/monaco/loader-config.ts (1)
11-11: Module-levelisMonacoLoaderConfiguredflag prevents resetting in tests.The singleton flag means
configureMonacoLoader()can only execute once per module lifetime (including across test runs in the same process). This is fine for production, but if you ever need to testconfigureMonacoLoaderdirectly, you'll need to usevi.resetModules()or expose a reset helper. Not blocking since the current test suite only covers the pure functions.
Eliminate external CDN dependency by self-hosting Monaco editor runtime assets. This improves security posture and enables air-gapped deployments. - Copy monaco-editor/min/vs to .next/static/monaco/vs at build time - Configure Monaco AMD loader to resolve from self-hosted path - Remove monaco-editor-webpack-plugin (no longer needed) - Remove cdn.jsdelivr.net from CSP script-src, style-src, font-src - Extract loader configuration to dedicated testable module Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
26dc56f to
85e4115
Compare
Summary
/_next/static/monaco/vsto eliminate external CDN dependencycdn.jsdelivr.netfrom CSPscript-src,style-src, andfont-srcdirectivesmonaco-editor-webpack-plugindependency (replaced by CopyPlugin)Security Impact
This change hardens the Content Security Policy by removing external CDN allowances that were only needed for Monaco loading. Self-hosting Monaco assets:
Test plan
/_next/static/monaco/vspnpm --filter web vitest run src/lib/editor/monaco/__tests__/pnpm --filter web vitest run src/middleware/__tests__/security-headers.test.ts🤖 Generated with Claude Code
Summary by CodeRabbit
Security Improvements
Refactor
Chores
Tests
Documentation