Leaf-kit html escaping does not work on characters that are part of extended grapheme cluster
Date: 2026-02
Affected: swift/github.com/vapor/leaf-kit
Attack vector: xss
Category: vulnerability-disclosure
Severity: Medium
CVE: CVE-2026-27120
CWE: CWE-75
CWE-79
CWE-87
CVSS: 6.1 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

### Summary `htmlEscaped` in leaf-kit will only escape html special characters if the extended grapheme clusters match, which allows bypassing escaping by using an extended grapheme cluster containing both the special html character and some additional characters. In the case of html attributes, this can lead to XSS if there is a leaf variable in the attribute that is user controlled. ### Details Relevant code: https://github.com/vapor/leaf-kit/blob/main/Sources/LeafKit/String%2BHTMLEscape.swift#L14 Strings in Swift are based on extended grapheme clusters. HTML on the other hand is based on unicode characters. For example if you have the sequence "́ (U+0022 Quotation mark followed by U+0301 Combining Acute Accent). To HTML this is just a quote mark followed by some other random character. To swift this is one extended grapheme cluster that does not equal a quotation mark by itself which is a different extended grapheme cluster. Thus `"\"́".replacingOccurrences(of: "\"", with: "&quot;")` does not replace the quote mark. This allows you to break out of html attributes. I believe replacingOccurences takes an optional third parameter that allows you to specify options to make it work on UTF-8 characters instead of grapheme clusters, which would be a good fix for this issue. I see depending on version, leafkit might use `replacing` instead of `replacingOccurences`. I don't know swift that well and couldn't find docs on what replacing does, so I don't know if both versio


Mitigations:

Architectural layers (MAESTRO):