fix(web): remove inline style schema allowance for markdown security - #5896
fix(web): remove inline style schema allowance for markdown security#5896mohamedmastouri-hue wants to merge 1 commit into
Conversation
Removes 'style' and 'className' from the permitted sanitization schema for span elements to prevent potential CSS injection attacks, while keeping the dataColorSwatch attribute which is safely processed by the React components. Fixes pingdotgg#5815
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 10b8289. Configure here.
| /> | ||
| <span {...props} className={className}>{children}</span> | ||
| </span> | ||
| ); |
There was a problem hiding this comment.
Unvalidated swatch color styling
COLOR_LITERAL_REGEX treats # plus 3, 4, 6, or 8 hex digits as colors in ordinary prose. In this coding chat UI that also matches common issue and PR references such as #123, #5815, and #abcd, so remarkColorSwatches wraps them in swatches and the renderer shows a color chip beside normal ticket mentions.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 10b8289. Configure here.
ApprovabilityVerdict: Needs human review This PR adds new color swatch rendering behavior to markdown. An open review comment correctly identifies that the regex will match GitHub issue references (e.g., #123, #5815) as color codes, causing incorrect rendering. This functional bug and the new feature scope warrant human review. You can customize Macroscope's approvability policy. Learn more. |


Fixes #5815b
Note
Medium Risk
Touches XSS-sensitive markdown sanitization and applies user-derived strings to
backgroundColor; scope is limited to regex-matched color literals and controlled rendering.Overview
Chat markdown now detects color literals in plain text (hex,
rgb/rgba,hsl/hsla) via a newremarkColorSwatchesplugin and marks them with a sanitizeddata-color-swatchattribute onspanelements instead of trusting raw HTMLstylein the document.The sanitize schema allows only
dataColorSwatchonspan(alongside existing code data attrs), and a customspanrenderer draws a small preview chip whosebackgroundColoris set in React from that attribute—so users still see swatches next to the color text without wideningrehype-sanitizeto permit arbitrary inline styles from markdown.Reviewed by Cursor Bugbot for commit 10b8289. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add inline color swatch rendering for CSS color literals in chat markdown
remarkColorSwatchesremark plugin scans markdown text nodes for CSS color literals (hex and functional forms) usingCOLOR_LITERAL_REGEXand wraps matches in annotatedspanelements with adata-color-swatchattribute.spanelements withdata-color-swatchthrough sanitization.ChatMarkdowncomponent renders a small bordered square with the matchingbackgroundColorbefore each color literal in chat messages.styleattributes are no longer permitted (per the PR title), hardening markdown sanitization while the swatch feature avoids needing them viadata-*attributes instead.Macroscope summarized 10b8289.