html: escape single quotes in writeQuoted when both quote types present#245
html: escape single quotes in writeQuoted when both quote types present#245mohammadmseet-hue wants to merge 2 commits into
Conversation
|
This PR (HEAD: 6097f3c) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/net/+/760000. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/760000. |
|
Message from Nicholas Husin: Patch Set 1: (3 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/760000. |
writeQuoted selects single quotes when the string contains double quotes, but does not escape single quotes already in the string. When a DOCTYPE public or system identifier contains both quote types, the unescaped single quotes break out of the quoted context. For example, a public identifier like: foo"bar'baz renders as: PUBLIC 'foo"bar'baz' The inner single quote terminates the quoted string early. Escape single quotes as &golang#39; when the chosen delimiter is a single quote and the string contains both quote types. Add test cases that cover single-only, double-only, and both-quote-types inputs for DOCTYPE public and system identifiers. Change-Id: Id0394d2a52995267771c1a5c914c686d46315691
6097f3c to
8676a0e
Compare
|
This PR (HEAD: 8676a0e) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/net/+/760000. Important tips:
|
|
Message from Mohammad Seet: Patch Set 2: (4 comments) Addressed all feedback. PS2 adds tests and cleans up commit message. Please don’t reply on this GitHub thread. Visit golang.org/cl/760000. |
|
Message from Mohammad Seet: Patch Set 2: (4 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/760000. |
|
This PR (HEAD: aa31577) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/net/+/760000. Important tips:
|
writeQuoted selects single quotes when the string contains double
quotes, but does not handle the case where the string contains
both quote types. In that case, the single quotes inside the
string break out of the quoted context, allowing injection of
arbitrary HTML into the rendered output.
Root cause: when s contains both double and single quotes,
writeQuoted chooses single-quote as the delimiter but writes s
unescaped, so any single quote in s terminates the quoted
attribute and the remainder is interpreted as raw HTML.
Fix: when both quote types are present, escape the delimiter
character inside the string using the HTML entity for single
quote.
Security context: CVE-2023-3978 established that html.Render
is a security boundary. This fix addresses a remaining case
where Render can produce output that changes semantics when
re-parsed.