Documentation
¶
Overview ¶
Package xmlroundtrip rejects XML documents that encoding/xml would change if it decoded and re-encoded them.
Go's encoding/xml does not round-trip some namespace prefixes on elements and attributes, or some directives, unchanged (CVE-2020-29509, CVE-2020-29510, CVE-2020-29511). This package rejects any document with a token that is not stable under such a round trip. It makes the same check as github.com/mattermost/xml-roundtrip-validator, but without allocating a new encoder and decoder for every token, so the memory it allocates is a small multiple of the size of its input.
Index ¶
Constants ¶
const MaxDepth = 64
MaxDepth is the deepest nesting of elements Validate accepts. SAML messages and metadata nest a dozen or so levels.
const MaxNamespacesInScope = 64
MaxNamespacesInScope is the largest number of namespace declarations Validate accepts in scope at any element. SAML messages and metadata have about ten.
What a document costs to canonicalize and namespace-resolve grows with the number of elements times the declarations in scope at each, and that work happens before the digest of a signed element is checked: with a validly signed element replayed over a body of thousands of declarations and elements, a few tens of kilobytes cost seconds and gigabytes. Declarations repeated on sibling elements (xmlns:xs on every AttributeValue, say) do not add up, so the limit is on those in scope, not on the total.
Variables ¶
var ( ErrTooDeep = fmt.Errorf("xml: elements nested more than %d deep", MaxDepth) ErrTooManyNamespaces = fmt.Errorf("xml: more than %d namespace declarations in scope", MaxNamespacesInScope) )
ErrTooDeep and ErrTooManyNamespaces report a document over MaxDepth or MaxNamespacesInScope.
Functions ¶
func Validate ¶
Validate returns an error if any token of data does not survive a round trip through encoding/xml unchanged, or if data nests elements more than MaxDepth deep or has more than MaxNamespacesInScope namespace declarations in scope at an element. It does not check that data is well-formed beyond what encoding/xml's tokenizer requires.
Types ¶
type Error ¶
type Error struct {
// Line and Column give the position (1-based) of the start of the token.
Line, Column int64
Err error
}
Error reports the token of a document that does not survive a round trip, or that could not be checked.
type RoundTripError ¶
RoundTripError reports a token that encoding/xml decodes differently after encoding it.
func (*RoundTripError) Error ¶
func (e *RoundTripError) Error() string