CVE-2026-27120: Leaf-kit html escaping does not work on characters that are part of extended grapheme cluster

Published Feb 19, 2026
·
Updated

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: """) 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 versions of the function are affected. The version of swift i was testing on I believe was using replacingOccurences

It seems like replacingOccurences will skip past prefix characters of extended grapheme clusters, which is what would be needed in order to meaningfully bypass esaping of <. Thus i think this is mostly limited to attributes and not general text.

PoC

An example vapor application that is vulnerable might look like

routes.swift swift import Vapor

struct Hello: Content { var msg: String? }

func routes( app: Application) throws { app.post { req throws in let Hello = try req.content.decode(Hello.self) return req.view.render("hello", [ "msg": Hello.msg ?? "Hello World!" ]) } }

With a hello.leaf that looks like <div title="#(msg)">Hover to see message</div>

And then you POST something like msg=%22%cc%81=1%20autofocus%20tabindex=0%20onfocus=alert(1)%20

Impact If a website uses leaf to escape an attribute value based on user input, the attacker may be able to insert a malicious attribute. If a site is not using a secure CSP policy, then this can be used to execute malicious javascript (XSS). Impact is context dependent if a site is using a secure CSP policy.

Other sources

Leafkit is a templating language with Swift-inspired syntax. Prior to 1.4.1, 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. This vulnerability is fixed in 1.4.1.

— NVD

Affected Software

2 affected componentsFixes available
swift/leaf-kit<1.4.1
1.4.1
Vapor Leafkit<1.14.1

Event History

Feb 19, 2026
Advisory Published
via GitHub·07:40 PM
Data Sourced
via GitHub·07:40 PM
DescriptionSeverityWeaknessAffected Software
Feb 20, 2026
CVE Published
via MITRE·09:27 PM
Data Sourced
via MITRE·09:27 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:16 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:16 PM
RemedyAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-27120?

CVE-2026-27120 has a medium severity due to the potential for bypassing HTML escaping.

2

How do I fix CVE-2026-27120?

To fix CVE-2026-27120, upgrade leaf-kit to version 1.4.1 or later.

3

What type of attack does CVE-2026-27120 facilitate?

CVE-2026-27120 facilitates the possibility of XSS (Cross-Site Scripting) attacks through improper HTML escaping.

4

Which software is affected by CVE-2026-27120?

CVE-2026-27120 affects leaf-kit versions prior to 1.4.1.

5

Is CVE-2026-27120 related to input validation?

Yes, CVE-2026-27120 is related to insufficient input validation in handling extended grapheme clusters.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203