Add {% style %} Markdoc tag for colored text and backgrounds#1220
Add {% style %} Markdoc tag for colored text and backgrounds#1220
{% style %} Markdoc tag for colored text and backgrounds#1220Conversation
Co-authored-by: Assem-Uber <137278762+Assem-Uber@users.noreply.github.com> Agent-Logs-Url: https://github.com/cadence-workflow/cadence-web/sessions/a8127137-8723-4181-bbc7-f5727e7f9fda
| return /^(#[0-9a-fA-F]{3,8}|rgb\(.*\)|rgba\(.*\)|hsl\(.*\)|hsla\(.*\)|[a-zA-Z]+)$/.test( | ||
| value.trim() | ||
| ); |
There was a problem hiding this comment.
💡 Security: CSS color validation regex is overly permissive with .*
The isValidCssColor regex uses .* inside the rgb()/rgba()/hsl()/hsla() patterns, which matches arbitrary content between the parentheses. For example, rgb(0,0,0;injected-property:value) would pass validation.
In practice, React's style prop sets values via the DOM element.style API (not innerHTML), so this can't be exploited for CSS injection. However, since the function is explicitly documented as a security validation layer, it should actually enforce valid values to match its stated purpose and serve as defense-in-depth.
Suggested fix:
function isValidCssColor(value: string): boolean {
return /^(#[0-9a-fA-F]{3,8}|rgba?\([\d\s,.%]+\)|hsla?\([\d\s,.%]+\)|[a-zA-Z]+)$/.test(
value.trim()
);
}
Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsAdds CSS style tag support for colored text and backgrounds in markdown rendering. Consider refining the 💡 Security: CSS color validation regex is overly permissive with
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
{% style %} Markdoc tag for colored text and backgrounds
Workflow query responses are limited to structural markdown formatting. This adds a
{% style %}Markdoc tag to support inline text color and background color, enabling richer status displays and visual hierarchy without custom UIs.Changes
markdoc-components/style/): Renders a<span>with inlinecolor/backgroundColorstyles. Includes CSS color value validation (named colors, hex, rgb/rgba, hsl/hsla) to reject unexpected patterns.styletag tomarkdoc-schema.tsandStyleto the component registry.## Styled Textsection tomarkdown-guide.tswith color, background, combined, and nesting examples.Syntax
{% style color="red" %}error: something failed{% /style %} {% style bg="yellow" %}highlighted{% /style %} {% style color="white" bg="blue" %}white on blue{% /style %} {% style color="blue" %} outer, {% style color="red" %}inner red{% /style %}, back to blue {% /style %}Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.