1
0
mirror of https://github.com/golang/go synced 2024-11-07 12:36:27 -07:00
go/src/encoding
Filippo Valsorda a9cfd55e2b 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>
2021-03-15 20:04:23 +00:00
..
ascii85 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
asn1 reflect: add Method.IsExported and StructField.IsExported methods 2021-02-25 21:21:51 +00:00
base32 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
base64 all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
binary encoding/binary: limit bytes read by Uvarint to <= 10 2021-03-08 18:49:14 +00:00
csv all: go fmt std cmd (but revert vendor) 2021-02-20 03:54:50 +00:00
gob encoding/gob: ensure "duplicate type received" decoder errors surface up 2021-03-13 11:52:17 +00:00
hex all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
json encoding/json: fix package shadowing in MarshalIndent example 2021-03-14 19:58:14 +00:00
pem all: update references to symbols moved from io/ioutil to io 2020-10-20 18:41:18 +00:00
xml encoding/xml: replace comments inside directives with a space 2021-03-15 20:04:23 +00:00
encoding.go