fix: add data: to style-src and font-src CSP directives in serveAsset#2657
fix: add data: to style-src and font-src CSP directives in serveAsset#2657MohamedBassem merged 1 commit intokarakeep-app:mainfrom
Conversation
Monolith-generated full-page archives inline stylesheets and fonts as data: URIs. The previous CSP blocked these, causing broken rendering. Adding data: to style-src and a new font-src directive unblocks them, matching the precedent set by img-src which already includes data:. Fixes: karakeep-app#2621 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
WalkthroughUpdated the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 fixes missing CSP directives in the
Confidence Score: 5/5Safe to merge — the change is minimal, targeted, and correct; the additions are narrowly scoped to the asset-serving handler which already carries 'unsafe-inline' in style-src The only changes are two CSP token additions that directly address the reported browser-blocking issue. The No files require special attention Important Files Changed
Reviews (1): Last reviewed commit: "fix: add data: to style-src and font-src..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/api/utils/assets.ts (1)
37-38: LGTM! CSP directives correctly allow data URIs for fonts and styles.The additions of
data:tostyle-srcand the newfont-src https: data:directive solve the stated problem (browsers blocking inline data URIs in archived HTML). The changes are consistent with existing precedent—bothimg-src(line 36) andmedia-src(line 40) already allowdata:sources.Optional: Consider adding
blob:tofont-srcfor consistency.Note that
img-srcandmedia-srcboth allowblob:in addition todata:. If there's a possibility that fonts might be loaded from blob URLs in the future, you may want to addblob:tofont-srcas well:- "font-src https: data:", + "font-src https: data: blob:",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/api/utils/assets.ts` around lines 37 - 38, Update the Content-Security-Policy directive for fonts in packages/api/utils/assets.ts to also allow blob: URLs by appending "blob:" to the "font-src" entry (currently "font-src https: data:"); modify that directive to "font-src https: data: blob:" so it matches img-src/media-src precedent and permits future blob-based font loading.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/api/utils/assets.ts`:
- Around line 37-38: Update the Content-Security-Policy directive for fonts in
packages/api/utils/assets.ts to also allow blob: URLs by appending "blob:" to
the "font-src" entry (currently "font-src https: data:"); modify that directive
to "font-src https: data: blob:" so it matches img-src/media-src precedent and
permits future blob-based font loading.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: effea7ae-9e00-4d6a-bd00-cc9b1548d942
📒 Files selected for processing (1)
packages/api/utils/assets.ts
|
Thank you. |
Problem
The
serveAssethandler inpackages/api/utils/assets.tswas missingdata:in thestyle-srcCSP directive and had nofont-srcdirective at all. This caused browsers to block inline data URIs used by fonts and styles when assets are served through the API.Fix
Added
data:tostyle-srcand inserted a newfont-src https: data:directive betweenstyle-srcandconnect-srcin the Content-Security-Policy header built insideserveAsset.What this doesn't change
CSP directives for other handlers (e.g. the main app routes) are unaffected.