fix(export): escape remaining role sinks + nonce-based CSP in HTML session export - #61769
Merged
Conversation
Addresses Copilot review on #61348: the HTML-escaped role, while safe from injection (quotes are escaped), still contains whitespace when a crafted role is supplied, which splits the class attribute into several unintended CSS classes. Keep the escaped role for the display badge, and reduce the raw role to a single safe CSS token (alnum/-/_) for the class name. Real roles (user/assistant/system/tool) are unchanged, so the existing .message-<role> rules still match.
Collaborator
Related: completes the HTML session-export XSS hardening from merged #61345 (which escaped only the tool-call name), consolidating OPEN #61348 (@briandevans — role escaping) and #61667 (@kohoj — nonce CSP), against issue #61343. Verified the message |
This was referenced Jul 10, 2026
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.
Summary
Completes the HTML session-export hardening that #61345 started: the two remaining externally-influenced sinks (role badge, message CSS class) are now escaped/sanitized, and the export ships a nonce-based Content-Security-Policy so any markup that slips a future sink is inert.
Consolidates two contributor PRs (cherry-picked, authorship preserved):
default-src 'none',script-src 'nonce-…',base-uri/object-src/frame-ancestors 'none') with the multi-session switcher refactored onto the nonce (dataset toggle), avoiding the blanket-CSP breakage that fix(export): escape tool-call name in HTML session export #61345 had to revertChanges
hermes_cli/session_export_html.py: role escaped in badge, role reduced to a single safe CSS token for the class attribute; nonce CSP meta + nonce'd inline scripttests/hermes_cli/test_session_export_html_escape.py(new) + additions totest_session_export.pyscripts/release.py: AUTHOR_MAP for kohojValidation
<img onerror=…>)Infographic