fix(frontend): escape HTML before markdown rendering in Kaizen mandate preview#17
Open
wstlima wants to merge 1 commit into
Open
fix(frontend): escape HTML before markdown rendering in Kaizen mandate preview#17wstlima wants to merge 1 commit into
wstlima wants to merge 1 commit into
Conversation
…e preview Kaizen.tsx's renderMarkdown() (used for the agent "mandate" preview via dangerouslySetInnerHTML at line 357) applies regex-based markdown substitutions directly to raw user-editable text, without escaping HTML first. The mandate field is user-editable free text (the agent's behavioral directive, edited in the same page) and is rendered as HTML whenever "Preview" is toggled. Flagged by CodeQL (js/xss-through-dom): DOM text reinterpreted as HTML without escaping meta-characters. Impact: stored XSS. Any mandate value containing raw HTML/script (e.g. `<img src=x onerror=alert(1)>`), whether entered directly in the UI or written via the API by an integration/compromised agent, executes in the browser of anyone who opens the Preview tab for that mandate. Fix: escape HTML special characters (&, <, >, ", ') before applying the markdown-to-HTML regex substitutions, so any embedded tags render as literal text instead of being interpreted as markup. Preserves all existing markdown formatting (headers, bold, italic, lists, hr, line breaks) since escaping runs before those regexes and none of them rely on raw angle brackets from the input. No backend change needed — this is purely a client-side rendering fix; the raw mandate value stored server-side is unaffected.
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.
Fixes #8
Summary
Kaizen.tsx'srenderMarkdown()(used for the agent "mandate" preview viadangerouslySetInnerHTML) applies regex-based markdown substitutions directly to raw user-editable text, without escaping HTML first. The mandate field is user-editable free text (the agent's behavioral directive) and is rendered as HTML whenever "Preview" is toggled.Flagged by CodeQL (
js/xss-through-dom): DOM text reinterpreted as HTML without escaping meta-characters.Impact
Stored XSS. Any mandate value containing raw HTML/script (e.g.
<img src=x onerror=alert(1)>), whether entered directly in the UI or written via the API by an integration/compromised agent, executes in the browser of anyone who opens the Preview tab for that mandate.Fix
Escape HTML special characters (
&,<,>,",') before applying the markdown-to-HTML regex substitutions, so any embedded tags render as literal text instead of being interpreted as markup. Preserves all existing markdown formatting since escaping runs before those regexes and none of them rely on raw angle brackets from the input.No backend change — purely client-side rendering fix.
Test plan
npx tsc --noEmitpasses