CVE-2022-46176: Cargo Cargo Did Not Verify SSH Vulnerability

MODERATE
Advisory Identifier: GHSA-r5w3-xm58-jv6j
CVSS 5.3
CWE-347
Published
Advisory Summary

CVE-2022-46176 is a MODERATE (CVSS 5.3) cargo did not verify ssh vulnerability (CWE-347: Improper Verification of Cryptographic Signature) affecting Cargo libraries in the crates.io ecosystem. The issue involves cargo did not verify ssh host keys. Remediation is available by upgrading affected packages to version 0.67.1.

CVE-2022-46176 at a Glance

CVE Identifier CVE-2022-46176
GHSA Identifier GHSA-r5w3-xm58-jv6j
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-347: Improper Verification of Cryptographic Signature
Affected Product Cargo
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 5.3

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

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

How to Fix CVE-2022-46176

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

cargo fixed: 0.67.1
Upgrade cargo to 0.67.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 cargo

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-46176, inspect your project dependencies for Cargo:

inspect dependencies for cargo

Analyze the terminal output to locate any version of Cargo in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.67.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-347: Improper Verification of Cryptographic Signature, where the product does not verify, or incorrectly verifies, the cryptographic signature for data. In Cargo, 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

The Rust Security Response WG was notified that Cargo did not perform SSH host key verification when cloning indexes and dependencies via SSH. An attacker could exploit this to perform man-in-the-middle (MITM) attacks. This vulnerability has been assigned CVE-2022-46176. ## Overview When an SSH client establishes communication with a server, to prevent MITM attacks the client should check whether it already communicated with that server in the past and what the server's public key was back then. If the key changed since the last connection, the connection must be aborted as a MITM attack is likely taking place. It was discovered that Cargo never implemented such checks, and performed no validation on the server's public key, leaving Cargo users vulnerable to MITM attacks. ## Affected Versions All Rust versions containing Cargo before 1.66.1 are vulnerable (prior to 0.67.1 for the crates.io package). Note that even if you don't explicitly use SSH for alternate registry indexes or crate dependencies, you might be affected by this vulnerability if you have configured git to replace HTTPS connections to GitHub with SSH (through git's [`url.<base>.insteadOf`][1] setting), as that'd cause you to clone the crates.io index through SSH. ## Mitigations We will be releasing Rust 1.66.1 today, 2023-01-10, changing Cargo to check the SSH host key and abort the connection if the server's public key is not already trusted. We recommend everyone to upgrade as soon as possible. Patch files for Rust 1.66.0 are also available [here][2] for custom-built toolchains. For the time being Cargo will not ask the user whether to trust a server's public key during the first connection. Instead, Cargo will show an error message detailing how to add that public key to the list of trusted keys. Note that this might break your automated builds if the hosts you clone dependencies or indexes from are not already trusted. If you can't upgrade to Rust 1.66.1 yet, we recommend configuring Cargo to use the `git` CLI instead of its built-in git support. That way, all git network operations will be performed by the `git` CLI, which is not affected by this vulnerability. You can do so by adding this snippet to your [Cargo configuration file](https://doc.rust-lang.org/cargo/reference/config.html): ```toml [net] git-fetch-with-cli = true ``` ## Acknowledgments Thanks to the Julia Security Team for disclosing this to us according to our [security policy][3]! We also want to thank the members of the Rust project who contributed to fixing this issue. Thanks to Eric Huss and Weihang Lo for writing and reviewing the patch, Pietro Albini for coordinating the disclosure and writing this advisory, and Josh Stone, Josh Triplett and Jacob Finkelman for advising during the disclosure. [1]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf [2]: https://github.com/rust-lang/wg-security-response/tree/main/patches/CVE-2022-46176 [3]: https://www.rust-lang.org/policies/security

CVE-2022-46176 Affected Cargo Versions

1 component(s)
Fixed Versions:
0.67.1
Product / Package Ecosystem Affected Versions Fixed Version
cargo
crates.io
< 0.67.1
0.67.1

References

Frequently Asked Questions

What is CVE-2022-46176?
CVE-2022-46176 is a security vulnerability in Cargo involving Cargo did not verify SSH host keys under CWE-347: Improper Verification of Cryptographic Signature.
Which Cargo versions are affected?
Affected versions include releases prior to 0.67.1 across affected packages: cargo.
What version fixes CVE-2022-46176?
Upgrading to 0.67.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cargo affected?
Yes, cargo is affected in releases prior to 0.67.1. Upgrade your dependency to 0.67.1 or later.
What is the CVSS score of CVE-2022-46176?
CVE-2022-46176 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2022-46176?
CVE-2022-46176 is classified under CWE-347: Improper Verification of Cryptographic Signature (The product does not verify, or incorrectly verifies, the cryptographic signature for data.).
How can I check crates.io dependencies for CVE-2022-46176?
Run the dependency tree command: 'inspect dependencies for cargo'. 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-r5w3-xm58-jv6j",
  "modified" : "2023-01-10T22:01:00Z",
  "published" : "2023-01-10T21:09:31Z",
  "aliases" : [ "CVE-2022-46176" ],
  "summary" : "Cargo did not verify SSH host keys",
  "details" : "The Rust Security Response WG was notified that Cargo did not perform SSH host key verification when cloning indexes and dependencies via SSH. An attacker could exploit this to perform man-in-the-middle (MITM) attacks.\n\nThis vulnerability has been assigned CVE-2022-46176.\n\n## Overview\n\nWhen an SSH client establishes communication with a server, to prevent MITM attacks the client should check whether it already communicated with that server in the past and what the server's public key was back then. If the key changed since the last connection, the connection must be aborted as a MITM attack is likely taking place.\n\nIt was discovered that Cargo never implemented such checks, and performed no validation on the server's public key, leaving Cargo users vulnerable to MITM attacks.\n\n## Affected Versions\n\nAll Rust versions containing Cargo before 1.66.1 are vulnerable (prior to 0.67.1 for the crates.io package).\n\nNote that even if you don't explicitly use SSH for alternate registry indexes or crate dependencies, you might be affected by this vulnerability if you have configured git to replace HTTPS connections to GitHub with SSH (through git's [`url.<base>.insteadOf`][1] setting), as that'd cause you to clone the crates.io index through SSH.\n\n## Mitigations\n\nWe will be releasing Rust 1.66.1 today, 2023-01-10, changing Cargo to check the SSH host key and abort the connection if the server's public key is not already trusted. We recommend everyone to upgrade as soon as possible.\n\nPatch files for Rust 1.66.0 are also available [here][2] for custom-built toolchains.\n\nFor the time being Cargo will not ask the user whether to trust a server's public key during the first connection. Instead, Cargo will show an error message detailing how to add that public key to the list of trusted keys. Note that this might break your automated builds if the hosts you clone dependencies or indexes from are not already trusted.\n\nIf you can't upgrade to Rust 1.66.1 yet, we recommend configuring Cargo to use the `git` CLI instead of its built-in git support. That way, all git network operations will be performed by the `git` CLI, which is not affected by this vulnerability. You can do so by adding this snippet to your [Cargo configuration file](https://doc.rust-lang.org/cargo/reference/config.html):\n\n```toml\n[net]\ngit-fetch-with-cli = true\n```\n\n## Acknowledgments\n\nThanks to the Julia Security Team for disclosing this to us according to our [security policy][3]!\n\nWe also want to thank the members of the Rust project who contributed to fixing this issue. Thanks to Eric Huss and Weihang Lo for writing and reviewing the patch, Pietro Albini for coordinating the disclosure and writing this advisory, and Josh Stone, Josh Triplett and Jacob Finkelman for advising during the disclosure.\n\n[1]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf\n[2]: https://github.com/rust-lang/wg-security-response/tree/main/patches/CVE-2022-46176\n[3]: https://www.rust-lang.org/policies/security",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "cargo"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.67.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.67.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/rust-lang/cargo/security/advisories/GHSA-r5w3-xm58-jv6j"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-46176"
  }, {
    "type" : "WEB",
    "url" : "https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rust-lang/cargo"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rust-lang/wg-security-response/tree/main/patches/CVE-2022-46176"
  }, {
    "type" : "WEB",
    "url" : "https://www.rust-lang.org/policies/security"
  }, {
    "type" : "WEB",
    "url" : "http://www.openwall.com/lists/oss-security/2023/11/05/6"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-347" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-01-10T21:09:31Z",
    "nvd_published_at" : "2023-01-11T21:15:00Z"
  }
}