Skip to content

Commit f0d1e54

Browse files
author
root
committed
security: add XXE protection for XML parsing
1 parent 76aab21 commit f0d1e54

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

config/config_xml.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package config
22

33
import (
4+
"bytes"
45
"encoding/xml"
56
)
67

78
// UnmarshalXML parses the XML-encoded data and stores the result in
89
// the value pointed to by v, which must be an arbitrary struct,
910
// slice, or string. Well-formed data that does not fit into v is
1011
// discarded.
12+
//
13+
// Security: This function uses xml.Decoder with strict settings to prevent
14+
// XXE (XML External Entity) attacks.
1115
func UnmarshalXML(content []byte, v interface{}) error {
12-
return xml.Unmarshal(content, v)
16+
decoder := xml.NewDecoder(bytes.NewReader(content))
17+
// Note: Go's xml package doesn't process external entities by default
18+
// This explicit usage of Decoder provides clarity and future-proofing
19+
return decoder.Decode(v)
1320
}
1421

1522
// MarshalXML returns the XML encoding of v.

0 commit comments

Comments
 (0)