CVE-2022-1642: Github.com/apple/swift corelibs foundation Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-239c-6cv2-wwx8
CVSS 7.5
CWE-704
Published
Advisory Summary

CVE-2022-1642 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-704: Incorrect Type Conversion or Cast) affecting Github.com/apple/swift corelibs foundation libraries in the SwiftURL ecosystem. The issue involves swift-corelibs-foundation denial of service in json decoding with jsondecoder. Remediation is available by upgrading affected packages to version 5.6.2.

CVE-2022-1642 at a Glance

CVE Identifier CVE-2022-1642
GHSA Identifier GHSA-239c-6cv2-wwx8
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-704: Incorrect Type Conversion or Cast
Affected Product Github.com/apple/swift corelibs foundation
Package Ecosystem SwiftURL
Published Date
Last Updated

Security Impact

CVSS: 7.5

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:N/S:U/C:N/I:N/A:H).

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

How to Fix CVE-2022-1642

To remediate this vulnerability, upgrade all affected Github.com/apple/swift corelibs foundation 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/apple/swift-corelibs-foundation fixed: 5.6.2
Upgrade github.com/apple/swift-corelibs-foundation to 5.6.2
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/apple/swift-corelibs-foundation

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-1642, inspect your project dependencies for Github.com/apple/swift corelibs foundation:

inspect dependencies for github.com/apple/swift-corelibs-foundation

Analyze the terminal output to locate any version of Github.com/apple/swift corelibs foundation in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.6.2), 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-704: Incorrect Type Conversion or Cast, where the product does not correctly convert an object, resource, or structure from one type to a different type. In Github.com/apple/swift corelibs foundation, 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

### Impact A program using swift-corelibs-foundation is vulnerable to a denial of service attack caused by a potentially malicious source producing a JSON document containing a type mismatch. This vulnerability is caused by the interaction between a deserialization mechanism offered by the Swift standard library, the Codable protocol; and the JSONDecoder class offered by swift-corelibs-foundation, which can deserialize types that adopt the Codable protocol based on the content of a provided JSON document. When a type that adopts Codable requests the initialization of a field with an integer value, the JSONDecoder class uses a type-erased container with different accessor methods to attempt and coerce a corresponding JSON value and produce an integer. In the case the JSON value was a numeric literal with a floating-point portion, JSONDecoder used different type-eraser methods during validation than it did during the final casting of the value. The checked casting produces a deterministic crash due to this mismatch. The JSONDecoder class is often wrapped by popular Swift-based web frameworks to parse the body of HTTP requests and perform basic type validation. This makes the attack low-effort: sending a specifically crafted JSON document during a request to these endpoints will cause them to crash. The attack does not have any confidentiality or integrity risks in and of itself; the crash is produced deterministically by an abort function that ensures that execution does not continue in the face of this violation of assumptions. However, unexpected crashes can lead to violations of invariants in services, so it's possible that this attack can be used to trigger error conditions that escalate the risk. Producing a denial of service may also be the goal of an attacker in itself. ### Resolution This issue is solved in Swift 5.6.2 for Linux and Windows. This issue was solved by ensuring that the same methods are invoked both when validating and during casting, so that no type mismatch occurs. Swift for Linux and Windows versions are not ABI-interchangeable. To upgrade a service, its owner must update to this version of the Swift toolchain, then recompile and redeploy their software. The new version of Swift includes an updated swift-corelibs-foundation package. The resolution is also included in recent development snapshots of Swift available on swift.org for those platforms. Versions of Swift running on Darwin-based operating systems are not affected. ### Workarounds Users that can control which payload is parsed with JSONDecoder can ensure that fields that are intended to initialize Swift integer types use a JSON numeric constant without a fractional part. This will avoid the crash, but it is rare that a user has full control on the JSON payload they will parse. As a workaround, users that can alter their current software but cannot perform an upgrade can perform JSON parsing directly (e.g., through the JSONSerialization class) rather than using the JSONDecoder class.

CVE-2022-1642 Affected Github.com/apple/swift corelibs foundation Versions

1 component(s)
Fixed Versions:
5.6.2
Product / Package Ecosystem Affected Versions Fixed Version
github.com/apple/swift-corelibs-foundation
SwiftURL
< 5.6.2
5.6.2

References

Frequently Asked Questions

What is CVE-2022-1642?
CVE-2022-1642 is a security vulnerability in Github.com/apple/swift corelibs foundation involving Swift-corelibs-foundation denial of service in JSON decoding with JSONDecoder under CWE-704: Incorrect Type Conversion or Cast.
Which Github.com/apple/swift corelibs foundation versions are affected?
Affected versions include releases prior to 5.6.2 across affected packages: github.com/apple/swift-corelibs-foundation.
What version fixes CVE-2022-1642?
Upgrading to 5.6.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/apple/swift-corelibs-foundation affected?
Yes, github.com/apple/swift-corelibs-foundation is affected in releases prior to 5.6.2. Upgrade your dependency to 5.6.2 or later.
What is the CVSS score of CVE-2022-1642?
CVE-2022-1642 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2022-1642?
CVE-2022-1642 is classified under CWE-704: Incorrect Type Conversion or Cast (The product does not correctly convert an object, resource, or structure from one type to a different type.).
How can I check SwiftURL dependencies for CVE-2022-1642?
Run the dependency tree command: 'inspect dependencies for github.com/apple/swift-corelibs-foundation'. 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-239c-6cv2-wwx8",
  "modified" : "2023-06-07T16:07:36Z",
  "published" : "2023-06-07T16:07:36Z",
  "aliases" : [ "CVE-2022-1642" ],
  "summary" : "Swift-corelibs-foundation denial of service in JSON decoding with JSONDecoder",
  "details" : "### Impact\n\nA program using swift-corelibs-foundation is vulnerable to a denial of service attack caused by a potentially malicious source producing a JSON document containing a type mismatch.\n\nThis vulnerability is caused by the interaction between a deserialization mechanism offered by the Swift standard library, the Codable protocol; and the JSONDecoder class offered by swift-corelibs-foundation, which can deserialize types that adopt the Codable protocol based on the content of a provided JSON document. When a type that adopts Codable requests the initialization of a field with an integer value, the JSONDecoder class uses a type-erased container with different accessor methods to attempt and coerce a corresponding JSON value and produce an integer. In the case the JSON value was a numeric literal with a floating-point portion, JSONDecoder used different type-eraser methods during validation than it did during the final casting of the value. The checked casting produces a deterministic crash due to this mismatch.\n\nThe JSONDecoder class is often wrapped by popular Swift-based web frameworks to parse the body of HTTP requests and perform basic type validation. This makes the attack low-effort: sending a specifically crafted JSON document during a request to these endpoints will cause them to crash.\n\nThe attack does not have any confidentiality or integrity risks in and of itself; the crash is produced deterministically by an abort function that ensures that execution does not continue in the face of this violation of assumptions. However, unexpected crashes can lead to violations of invariants in services, so it's possible that this attack can be used to trigger error conditions that escalate the risk. Producing a denial of service may also be the goal of an attacker in itself.\n\n### Resolution\n\nThis issue is solved in Swift 5.6.2 for Linux and Windows. This issue was solved by ensuring that the same methods are invoked both when validating and during casting, so that no type mismatch occurs.\n\nSwift for Linux and Windows versions are not ABI-interchangeable. To upgrade a service, its owner must update to this version of the Swift toolchain, then recompile and redeploy their software. The new version of Swift includes an updated swift-corelibs-foundation package.\n\nThe resolution is also included in recent development snapshots of Swift available on swift.org for those platforms.\n\nVersions of Swift running on Darwin-based operating systems are not affected.\n\n### Workarounds\n\nUsers that can control which payload is parsed with JSONDecoder can ensure that fields that are intended to initialize Swift integer types use a JSON numeric constant without a fractional part. This will avoid the crash, but it is rare that a user has full control on the JSON payload they will parse.\n\nAs a workaround, users that can alter their current software but cannot perform an upgrade can perform JSON parsing directly (e.g., through the JSONSerialization class) rather than using the JSONDecoder class.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "SwiftURL",
      "name" : "github.com/apple/swift-corelibs-foundation"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.6.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/apple/swift-corelibs-foundation/security/advisories/GHSA-239c-6cv2-wwx8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-1642"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/apple/swift-corelibs-foundation/commit/b541491f73b39007a38f3ff5a0cbe89d09ef1614"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/apple/swift-corelibs-foundation"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-704" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-06-07T16:07:36Z",
    "nvd_published_at" : "2022-06-16T17:15:00Z"
  }
}