Harden the streaming code-block guard and narrow provider serialization - #2417
Open
gary149 wants to merge 1 commit into
Open
Harden the streaming code-block guard and narrow provider serialization#2417gary149 wants to merge 1 commit into
gary149 wants to merge 1 commit into
Conversation
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.
What
Two small hardening follow-ups from an external security review of the perf series (#2409 to #2415). Neither is an exploitable issue today; both remove implicit contracts that current safety silently depends on.
Streaming code-block guard now enforces the highlighter's output alphabet directly. The guard introduced in Lazy-load KaTeX/highlight.js and cut per-token markdown costs #2411 skipped DOMPurify on open fences when the html contained only span tags, but its regex allowed arbitrary attributes on those spans (
<span onclick=...>would have passed). That was safe only via the implicit contract thathighlightCode()never emits attributes. The guard now lives inmarkedLight.tsasisTrustedHighlighterHtml()and accepts exactly</span>,<span>, or<span class="...">(double quotes, single space, no other attributes); anything else falls through to a full DOMPurify pass. Covered by unit tests including the attribute-injection cases.Per-model
providersserialization narrowed to the one field clients read.serializeModelDetailpassed the upstream router's provider objects through verbatim. On HuggingChat that content is public metadata, but for self-hosted deployments with a custom router it would forward arbitrary upstream fields across an unauthenticated API boundary. The endpoint now maps providers down to{ provider: string }, which is the only field the settings page uses, and theGETModelResponsetype is tightened to match.Verification
markedLight.spec.tscovering accepted hljs markup (including nested spans) and rejected payloads (onclickspans, single-quoted class, extra attributes, script/img/style tags, malformed closing tags)Independent of #2416 (disjoint files); the two merge in either order.