fix(security): sanitize color_hex on output to prevent CSS injection (v1.38.2)#60
Merged
Merged
Conversation
…(v1.38.2) color_hex is a free-text field stored verbatim and interpolated into style="…" and SVG stroke attributes. Jinja autoescaping blocks attribute breakout but not CSS/SVG-value injection inside the attribute. New `hexcolor` Jinja filter only lets a valid #RGB/#RRGGBB through (else a neutral default), applied to every color swatch, donut stroke, and data-fill/data-color across spool/filament lists and details, search, label queue, and inventory. Low severity (write-only sets colors; the strict CSP already blocks external loads) but this is the correct output-layer fix and also covers legacy stored data. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses a background security-review finding on the color swatch.
Finding (real, low severity)
color_hexis a free-text field (<input type="text">), stored verbatim (no validation increate_filament/update_filament), then interpolated intostyle="…background:{{ color_hex }}…"and SVGstroke. Jinja autoescaping blocks attribute breakout (quotes escaped) but not CSS/SVG-value injection inside the attribute (e.g.#f00;background:url(…)).Why low severity: only admin/write users set colors; the strict CSP (
default-src 'self'; img-src 'self' data:) blocks external resource loads (no CSS exfiltration); noexpression()in modern browsers. Pre-existing pattern (spool list, both details, search) that the recent color column extended.Fix (output layer — covers legacy data too)
hexcolorJinja filter: only passes a valid#RGB/#RRGGBB, else a neutral default.data-fill/data-colorattributes read by JS.Verification
run-tests.ps1: 174 tests, all green (newtest_security_color.py: filter unit tests + a maliciouscolor_hexpayload proven neutralized in/spoolsand/filaments).Deploy
PATCH (1.38.1 → 1.38.2). After merge: release
v1.38.2and update via/admin/update.🤖 Generated with Claude Code