CVE-2026-27120: Github.com/vapor/leaf kit Leaf-kit Html Escaping Does Not Vulnerability

MODERATE
Advisory Identifier: GHSA-4hfh-fch3-5q7p
CVSS 6.1
CWE-87 CWE-79 CWE-75
Published
Advisory Summary

CVE-2026-27120 is a MODERATE (CVSS 6.1) leaf-kit html escaping does not vulnerability (CWE-87: Improper Neutralization of Alternate XSS Syntax) affecting Github.com/vapor/leaf kit libraries in the SwiftURL ecosystem. The issue involves leaf-kit html escaping does not work on characters that are part of extended grapheme cluster. Remediation is available by upgrading affected packages to version 1.4.1.

CVE-2026-27120 at a Glance

CVE Identifier CVE-2026-27120
GHSA Identifier GHSA-4hfh-fch3-5q7p
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-87: Improper Neutralization of Alternate XSS Syntax
Affected Product Github.com/vapor/leaf kit
Package Ecosystem SwiftURL
Published Date
Last Updated

Security Impact

CVSS: 6.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2026-27120

To remediate this vulnerability, upgrade all affected Github.com/vapor/leaf kit dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/vapor/leaf-kit fixed: 1.4.1
Upgrade github.com/vapor/leaf-kit to 1.4.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/vapor/leaf-kit

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-27120, inspect your project dependencies for Github.com/vapor/leaf kit:

inspect dependencies for github.com/vapor/leaf-kit

Analyze the terminal output to locate any version of Github.com/vapor/leaf kit in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.4.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-87: Improper Neutralization of Alternate XSS Syntax, where the product does not neutralize or incorrectly neutralizes user-controlled input for alternate script syntax. In Github.com/vapor/leaf kit, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 ```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.

CVE-2026-27120 Affected Github.com/vapor/leaf kit Versions

1 component(s)
Fixed Versions:
1.4.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/vapor/leaf-kit
SwiftURL
< 1.4.1
1.4.1

References

Frequently Asked Questions

What is CVE-2026-27120?
CVE-2026-27120 is a security vulnerability in Github.com/vapor/leaf kit involving Leaf-kit html escaping does not work on characters that are part of extended grapheme cluster under CWE-87: Improper Neutralization of Alternate XSS Syntax.
Which Github.com/vapor/leaf kit versions are affected?
Affected versions include releases prior to 1.4.1 across affected packages: github.com/vapor/leaf-kit.
What version fixes CVE-2026-27120?
Upgrading to 1.4.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/vapor/leaf-kit affected?
Yes, github.com/vapor/leaf-kit is affected in releases prior to 1.4.1. Upgrade your dependency to 1.4.1 or later.
What is the CVSS score of CVE-2026-27120?
CVE-2026-27120 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2026-27120?
CVE-2026-27120 is classified under CWE-87: Improper Neutralization of Alternate XSS Syntax (The product does not neutralize or incorrectly neutralizes user-controlled input for alternate script syntax.).
How can I check SwiftURL dependencies for CVE-2026-27120?
Run the dependency tree command: 'inspect dependencies for github.com/vapor/leaf-kit'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4hfh-fch3-5q7p",
  "modified" : "2026-04-22T16:24:14Z",
  "published" : "2026-02-19T19:40:08Z",
  "aliases" : [ "CVE-2026-27120" ],
  "summary" : "Leaf-kit html escaping does not work on characters that are part of extended grapheme cluster",
  "details" : "### Summary\n\n`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.\n\n### Details\n\nRelevant code:\nhttps://github.com/vapor/leaf-kit/blob/main/Sources/LeafKit/String%2BHTMLEscape.swift#L14\n\nStrings in Swift are based on extended grapheme clusters. HTML on the other hand is based on unicode characters. \n\nFor 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.\n\nThus `\"\\\"́\".replacingOccurrences(of: \"\\\"\", with: \"&quot;\")` does not replace the quote mark. This allows you to break out of html attributes.\n\nI 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.\n\nI 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\n\nIt 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.\n\n### PoC\n\nAn example vapor application that is vulnerable might look like\n\nroutes.swift\n```swift\nimport Vapor\n\nstruct Hello: Content {\n    var msg: String?\n}\n\nfunc routes(_ app: Application) throws {\n    app.post { req throws in\n\tlet Hello = try req.content.decode(Hello.self)\n        return req.view.render(\"hello\", [\n            \"msg\": Hello.msg ?? \"Hello World!\"\n        ])\n    }\n}\n```\n\nWith a hello.leaf that looks like\n```\n<div title=\"#(msg)\">Hover to see message</div>\n```\n\nAnd then you POST something like `msg=%22%cc%81=1%20autofocus%20tabindex=0%20onfocus=alert(1)%20`\n\n### Impact\nIf 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "SwiftURL",
      "name" : "github.com/vapor/leaf-kit"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.4.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vapor/leaf-kit/security/advisories/GHSA-4hfh-fch3-5q7p"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-27120"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vapor/leaf-kit/commit/8919e39476c3a4ba05c28b71546bb9195f87ef34"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vapor/leaf-kit"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-75", "CWE-79", "CWE-87" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-02-19T19:40:08Z",
    "nvd_published_at" : "2026-02-20T22:16:29Z"
  }
}