]> Cypherpunks repositories - gostls13.git/commit
encoding/xml: replace comments inside directives with a space
authorFilippo Valsorda <filippo@golang.org>
Mon, 26 Oct 2020 23:21:30 +0000 (00:21 +0100)
committerFilippo Valsorda <filippo@golang.org>
Mon, 15 Mar 2021 20:04:23 +0000 (20:04 +0000)
commita9cfd55e2b09735a25976d1b008a0a3c767494f8
treecb76f2208aee86469ea08ec824122c966c7342b3
parent4d014e723165f28b34458edb4aa9136e0fb4c702
encoding/xml: replace comments inside directives with a space

A Directive (like <!ENTITY xxx []>) can't have other nodes nested inside
it (in our data structure representation), so there is no way to
preserve comments. The previous behavior was to just elide them, which
however might change the semantic meaning of the surrounding markup.
Instead, replace them with a space which hopefully has the same semantic
effect of the comment.

Directives are not actually a node type in the XML spec, which instead
specifies each of them separately (<!ENTITY, <!DOCTYPE, etc.), each with
its own grammar. The rules for where and when the comments are allowed
are not straightforward, and can't be implemented without implementing
custom logic for each of the directives.

Simply preserving the comments in the body of the directive would be
problematic, as there can be unmatched quotes inside the comment.
Whether those quotes are considered meaningful semantically or not,
other parsers might disagree and interpret the output differently.

This issue was reported by Juho Nurminen of Mattermost as it leads to
round-trip mismatches. See #43168. It's not being fixed in a security
release because round-trip stability is not a currently supported
security property of encoding/xml, and we don't believe these fixes
would be sufficient to reliably guarantee it in the future.

Fixes CVE-2020-29510
Updates #43168

Change-Id: Icd86c75beff3e1e0689543efebdad10ed5178ce3
Reviewed-on: https://go-review.googlesource.com/c/go/+/277893
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/encoding/xml/xml.go
src/encoding/xml/xml_test.go