Skip to content

fix(console): message formatting XSS vulnerability#2247

Open
jwueller wants to merge 1 commit into
mainsail-crew:developfrom
jwueller:fix-console-xss
Open

fix(console): message formatting XSS vulnerability#2247
jwueller wants to merge 1 commit into
mainsail-crew:developfrom
jwueller:fix-console-xss

Conversation

@jwueller

@jwueller jwueller commented Aug 17, 2025

Copy link
Copy Markdown

Description

Having HTML characters like < in a message will currently break it's rendering. An example would be a standard Python object __repr__, like it might show up in an error message:

<klippy.extras.gcode_macro.GetStatusWrapperPython object at 0x7f67eb2cd0>

This is an XSS vulnerability. Making Klippy echo a message containing HTML could run arbitrary code in the browser of everyone currently monitoring the console.

But even if you consider this an unlikely attack vector, this will still fix quirky visual behavior in current message rendering, though.

Related Tickets & Documents

None as far as I can tell, but I can create one for this vulnerability, if required.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 17, 2025
Having HTML characters like `<` in a message will currently break it's
rendering. An example would be a standard Python object `__repr__`,
like it might show up in an error message:

    <klippy.extras.gcode_macro.GetStatusWrapperPython object at 0x7f67eb2cd0>

This is an XSS vulnerability. By making Klippy `M118` a message
containing HTML, you could hijack the browser of everyone currently
monitoring the console.

But even if you consider this an unlikely attack vector, this will
still fix quirky visual behavior in current message rendering, though.
@meteyou

meteyou commented Aug 18, 2025

Copy link
Copy Markdown
Member

@jwueller Thank you very much! Pls also add an option in the Interface Settings to disable this feature/fix?

Some projects like AFC-Klipper-Add-On or HappyHare use this for "HTML-Outputs". I would enable the escape per default, but users which use plugins like these, can disable it for "better format html outputs".

@meteyou

meteyou commented Jun 17, 2026

Copy link
Copy Markdown
Member

Closed, because i got no answer...

@meteyou meteyou closed this Jun 17, 2026
@jwueller

jwueller commented Jun 19, 2026

Copy link
Copy Markdown
Author

@meteyou My apologies, I must have missed this among my flurry of notifications.

I suppose this could be toggled, but the core issue is that we have no way to be certain about the intended message format. Either setting would produce broken output in some circumstances.

The real fix would be a native format that's attached to an individual message, so it can be rendered appropriately. However, that would likely require support from Klipper, as well as coordination with other frontends.

Since the PR no longer seems to be feasible as-is, my proposal would be to do HTML sanitization instead, to strip out any unrecognized tags (e.g. https://github.com/cure53/DOMPurify). This would allow authors to keep using common rich text elements like text styles or links, but also significantly reduce the potential attack surface.

If you're happy with the proposal, feel free to reopen this and I'll make the required changes.

@jwueller

jwueller commented Jun 19, 2026

Copy link
Copy Markdown
Author

Addendum: I just realized that Klipper already has a message type prefix, so maybe we should encourage standardizing around something like this?

RESPOND TYPE=echo_html MSG="<message>"       # will likely error due to unknown value in Klipper, but:
RESPOND PREFIX="echo_html:" MSG="<message>"  # takes precedence over TYPE
RESPOND PREFIX="echo:html:" MSG="<message>"  # better backwards compatibility

And then consider regular echo: to be plain text.

Although I should add, that even in this case, HTML sanitization should still happen.

@meteyou meteyou reopened this Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @jwueller, thanks for your interest in contributing to Mainsail! 👋

This pull request has been automatically closed because pull requests may only be opened by vouched contributors, and you are not yet on our vouched list.

This is not a rejection of your work. A maintainer can vouch for you and once that happens, simply reopen this PR or comment /recheck.

Please see our contributing guidelines for more details:

@github-actions github-actions Bot closed this Jun 19, 2026
@github-actions github-actions Bot added the unvouched Closed automatically: Author is not a vouched contributor label Jun 19, 2026
@meteyou

meteyou commented Jun 19, 2026

Copy link
Copy Markdown
Member

vouch @jwueller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files. unvouched Closed automatically: Author is not a vouched contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants