Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2024-05-22 - [XXE Protection in SVG Parser]

**Vulnerability:** The `XMLDocument` initializer in `SVGParser.swift` used empty options `[]`, which potentially allows XML External Entity (XXE) attacks if the underlying parser defaults are permissive.
**Learning:** Even when using higher-level abstractions like `XMLDocument`, one must explicitly disable dangerous features like external entity loading when processing untrusted input.
**Prevention:** Always use `.nodeLoadExternalEntitiesNever` (or equivalent flags in other parsers) when parsing XML/SVG data from external sources.
4 changes: 3 additions & 1 deletion Sources/SVGKit/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ public final class SVGParser: @unchecked Sendable { // swiftlint:disable:this ty
data
}

let document = try XMLDocument(data: svgData, options: [])
// Disable external entity loading to prevent XXE attacks
let options: XMLNode.Options = [.nodeLoadExternalEntitiesNever]
let document = try XMLDocument(data: svgData, options: options)
guard let root = document.rootElement(), elementName(root) == "svg" else {
throw SVGParserError.invalidSVGRoot
}
Expand Down
Loading