CVE-2026-27120

CVE-2026-27120 is a medium-severity cross-site scripting (XSS) vulnerability in github.com/vapor/leaf-kit (swift), affecting versions < 1.4.1. It is fixed in 1.4.1.

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 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

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.

Untrusted input is rendered as active markup in a victim's browser, which can run script in their session. Typical impact: session or credential theft, and actions taken as the user.

CVE-2026-27120 has a CVSS score of 6.1 (Medium). The vector is network-reachable, no privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (1.4.1); upgrading removes the vulnerable code path.

Affected versions

github.com/vapor/leaf-kit (< 1.4.1)

Security releases

github.com/vapor/leaf-kit → 1.4.1 (swift)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

See it in your environment

Remediation advice

Upgrade github.com/vapor/leaf-kit to 1.4.1 or later to resolve this vulnerability.

Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.

Frequently Asked Questions

  1. What is CVE-2026-27120? CVE-2026-27120 is a medium-severity cross-site scripting (XSS) vulnerability in github.com/vapor/leaf-kit (swift), affecting versions < 1.4.1. It is fixed in 1.4.1. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
  2. How severe is CVE-2026-27120? CVE-2026-27120 has a CVSS score of 6.1 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which versions of github.com/vapor/leaf-kit are affected by CVE-2026-27120? github.com/vapor/leaf-kit (swift) versions < 1.4.1 is affected.
  4. Is there a fix for CVE-2026-27120? Yes. CVE-2026-27120 is fixed in 1.4.1. Upgrade to this version or later.
  5. Is CVE-2026-27120 exploitable, and should I be worried? Whether CVE-2026-27120 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2026-27120 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2026-27120? Upgrade github.com/vapor/leaf-kit to 1.4.1 or later.

Other vulnerabilities in github.com/vapor/leaf-kit

CVE-2026-28499CVE-2021-37634

Stop the waste.
Protect your environment with Kodem.