mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #2382] [MERGED] Sanitize theme and extension CSS before injecting into document.head #5573
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5573
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2382
Author: @Romuromylus
Created: 6/5/2026
Status: ✅ Merged
Merged: 6/6/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/theme-css-sanitize📝 Commits (2)
946f02bSanitize theme and extension CSS before injecting into document.head863242dSanitize theme editor live-preview CSS📊 Changes
4 files changed (+81 additions, -15 deletions)
View changed files
📝
src/app/providers/CustomThemeInjector.tsx(+6 -2)📝
src/features/shell/settings/components/SettingsPanel.tsx(+4 -1)📝
src/shared/lib/chat-css.test.ts(+40 -1)📝
src/shared/lib/chat-css.ts(+31 -11)📄 Description
Linked issue
Closes #2365
Why this change
CustomThemeInjectorassigned the active theme's CSS and each enabled extension's CSS straight to a<style>element'stextContent, bypassing the card-CSS sanitizer. With the app CSP set tonull, a theme or extension could shipurl()beacons (exfil / IP tracking),@import,expression()/javascript:, or:visitedhistory probes that run on every render — and an imported profile can auto-activate a theme without user intent.What changed
stripDangerousCssout ofsanitizeChatCsscovering the constructs that are unsafe regardless of scope (remoteurl()->about:invalid,@import/@namespace/@font-face,expression/javascript:/vbscript:/behavior/-moz-binding,:visited), and run theme and extension CSS through it.sanitizeChatCssnow callsstripDangerousCssand keeps its card-only scope/theme-protection passes, so scoped card CSS is byte-for-byte unchanged (existing tests pass).!important, and positions elements, so only the always-dangerous vectors are stripped. Auto-activation of imported themes is tracked separately (#2366).Refactor impact
Primary owner: app shell / shared lib (
src/app/providers/CustomThemeInjector.tsx,src/shared/lib/chat-css.ts)Impact areas reviewed:
Boundary notes:
app/providersimportsstripDangerousCssfromshared/lib(downward dependency, allowed).Pressure points touched:
Validation
pnpm checkpasses before PR push/handoffManual verification notes
pnpm vitest run src/shared/lib/chat-css.test.ts— 46 passed (all existing card-sanitization tests + 6 newstripDangerousCsstests provingurl()/@import/expression/javascript:/:visitedare stripped while theme tokens,!important, andposition: fixedare preserved).pnpm exec tsc -b— clean.Feature Discoverability
Reason:
Docs and release impact
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.