From 126701232d5eb6c373ffbf29421da90fc6571ad9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 28 Dec 2025 15:39:04 +0000 Subject: [PATCH 1/4] feat(security): disable external entity loading in SVG parser - Initializes `XMLDocument` with `.nodeLoadExternalEntitiesNever` in `SVGParser.swift`. - Prevents XML External Entity (XXE) attacks when parsing untrusted SVG files. - Hardens the codebase against local file inclusion and SSRF vulnerabilities via malicious SVGs. --- .jules/sentinel.md | 4 ++++ Sources/SVGKit/SVGParser.swift | 4 +++- mise.lock | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .jules/sentinel.md diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 00000000..b153641d --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 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. diff --git a/Sources/SVGKit/SVGParser.swift b/Sources/SVGKit/SVGParser.swift index 8f4e9d65..b4161dbd 100644 --- a/Sources/SVGKit/SVGParser.swift +++ b/Sources/SVGKit/SVGParser.swift @@ -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 } diff --git a/mise.lock b/mise.lock index 7dbbf666..13429c24 100644 --- a/mise.lock +++ b/mise.lock @@ -81,6 +81,7 @@ backend = "core:python" [[tools.swift]] version = "6.2.3" backend = "core:swift" +"platforms.linux-x64" = { checksum = "blake3:0857a2267c52dc00ff1b59b93530a4316d3f99884744f4f75661fcbbea8a414b"} [[tools.swiftformat]] version = "0.58.7" From 9bf3069ec1b6afb4827cbc39d06ff8581f9b7725 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 28 Dec 2025 19:21:05 +0000 Subject: [PATCH 2/4] feat(security): disable external entity loading in SVG parser - Initializes `XMLDocument` with `.nodeLoadExternalEntitiesNever` in `SVGParser.swift`. - Prevents XML External Entity (XXE) attacks when parsing untrusted SVG files. - Hardens the codebase against local file inclusion and SSRF vulnerabilities via malicious SVGs. - Verified `XMLDocument` usage across the codebase; `FileWriter.swift` only writes XML and is safe. --- .jules/sentinel.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.jules/sentinel.md b/.jules/sentinel.md index b153641d..97090ef1 100644 --- a/.jules/sentinel.md +++ b/.jules/sentinel.md @@ -1,4 +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. From b472fe2d19aee13c0a02bd499dcf6016e1a55565 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:32:09 +0000 Subject: [PATCH 3/4] feat(security): disable external entity loading in SVG parser - Initializes `XMLDocument` with `.nodeLoadExternalEntitiesNever` in `SVGParser.swift`. - Prevents XML External Entity (XXE) attacks when parsing untrusted SVG files. - Hardens the codebase against local file inclusion and SSRF vulnerabilities via malicious SVGs. - Verified `XMLDocument` usage across the codebase; `FileWriter.swift` only writes XML and is safe. --- mise.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/mise.lock b/mise.lock index 13429c24..7dbbf666 100644 --- a/mise.lock +++ b/mise.lock @@ -81,7 +81,6 @@ backend = "core:python" [[tools.swift]] version = "6.2.3" backend = "core:swift" -"platforms.linux-x64" = { checksum = "blake3:0857a2267c52dc00ff1b59b93530a4316d3f99884744f4f75661fcbbea8a414b"} [[tools.swiftformat]] version = "0.58.7" From eb478e5b00e74fecf9a0477432008653f560db9d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:51:05 +0000 Subject: [PATCH 4/4] feat(security): disable external entity loading in SVG parser - Initializes `XMLDocument` with `.nodeLoadExternalEntitiesNever` in `SVGParser.swift`. - Prevents XML External Entity (XXE) attacks when parsing untrusted SVG files. - Hardens the codebase against local file inclusion and SSRF vulnerabilities via malicious SVGs. - Verified `XMLDocument` usage across the codebase; `FileWriter.swift` only writes XML and is safe. - Verified `parse(contentsOf:)` delegates to the patched method.