CVE-2023-23931: Cryptography Cipher.update_into Can Corrupt Memory If Vulnerability

MODERATE
Advisory Identifier: GHSA-w7pp-m8wf-vj6r
CVSS 6.5
CWE-754
Published
Advisory Summary

CVE-2023-23931 is a MODERATE (CVSS 6.5) cipher.update_into can corrupt memory if vulnerability (CWE-754: Improper Check for Unusual or Exceptional Conditions) affecting Cryptography libraries in the PyPI ecosystem. The issue involves cipher.update_into can corrupt memory if passed an immutable python object as the outbuf. Remediation is available by upgrading affected packages to version 39.0.1.

CVE-2023-23931 at a Glance

CVE Identifier CVE-2023-23931
GHSA Identifier GHSA-w7pp-m8wf-vj6r
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-754: Improper Check for Unusual or Exceptional Conditions
Affected Product Cryptography
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.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:L/A:L).

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 Low (I:L)
Availability Low (A:L)

How to Fix CVE-2023-23931

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

cryptography fixed: 39.0.1
pip install cryptography>=39.0.1
Verify Direct and Transitive Dependencies

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

pip show cryptography

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-23931, inspect your installed packages using pip:

pip show cryptography

Analyze the terminal output to locate any version of Cryptography in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 39.0.1), your application is affected.

Note: The pip show cryptography command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-754: Improper Check for Unusual or Exceptional Conditions, where the product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product. In Cryptography, 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

Previously, `Cipher.update_into` would accept Python objects which implement the buffer protocol, but provide only immutable buffers: ```pycon >>> outbuf = b"\x00" * 32 >>> c = ciphers.Cipher(AES(b"\x00" * 32), modes.ECB()).encryptor() >>> c.update_into(b"\x00" * 16, outbuf) 16 >>> outbuf b'\xdc\x95\xc0x\xa2@\x89\x89\xadH\xa2\x14\x92\x84 \x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' ``` This would allow immutable objects (such as `bytes`) to be mutated, thus violating fundamental rules of Python. This is a soundness bug -- it allows programmers to misuse an API, it cannot be exploited by attacker controlled data alone. This now correctly raises an exception. This issue has been present since `update_into` was originally introduced in cryptography 1.8.

CVE-2023-23931 Affected Cryptography Versions

1 component(s)
Fixed Versions:
39.0.1
Product / Package Ecosystem Affected Versions Fixed Version
cryptography
PyPI
≥ 1.8
< 39.0.1
39.0.1

References

Frequently Asked Questions

What is CVE-2023-23931?
CVE-2023-23931 is a security vulnerability in Cryptography involving Cipher.update_into can corrupt memory if passed an immutable python object as the outbuf under CWE-754: Improper Check for Unusual or Exceptional Conditions.
Which Cryptography versions are affected?
Affected versions include releases prior to 39.0.1 across affected packages: cryptography.
What version fixes CVE-2023-23931?
Upgrading to 39.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cryptography affected?
Yes, cryptography is affected in releases prior to 39.0.1. Upgrade your dependency to 39.0.1 or later.
What is the CVSS score of CVE-2023-23931?
CVE-2023-23931 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L.
What CWE is associated with CVE-2023-23931?
CVE-2023-23931 is classified under CWE-754: Improper Check for Unusual or Exceptional Conditions (The product does not check or incorrectly checks for unusual or exceptional conditions that are not expected to occur frequently during day to day operation of the product.).
How can I check PyPI dependencies for CVE-2023-23931?
Run the dependency tree command: 'pip show cryptography'. 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-w7pp-m8wf-vj6r",
  "modified" : "2025-11-04T16:43:33Z",
  "published" : "2023-02-07T20:54:10Z",
  "aliases" : [ "CVE-2023-23931" ],
  "summary" : "Cipher.update_into can corrupt memory if passed an immutable python object as the outbuf",
  "details" : "Previously, `Cipher.update_into` would accept Python objects which implement the buffer protocol, but provide only immutable buffers:\n\n```pycon\n>>> outbuf = b\"\\x00\" * 32\n>>> c = ciphers.Cipher(AES(b\"\\x00\" * 32), modes.ECB()).encryptor()\n>>> c.update_into(b\"\\x00\" * 16, outbuf)\n16\n>>> outbuf\nb'\\xdc\\x95\\xc0x\\xa2@\\x89\\x89\\xadH\\xa2\\x14\\x92\\x84 \\x87\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n```\n\nThis would allow immutable objects (such as `bytes`) to be mutated, thus violating fundamental rules of Python. This is a soundness bug -- it allows programmers to misuse an API, it cannot be exploited by attacker controlled data alone.\n\nThis now correctly raises an exception.\n\nThis issue has been present since `update_into` was originally introduced in cryptography 1.8.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "cryptography"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.8"
      }, {
        "fixed" : "39.0.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pyca/cryptography/security/advisories/GHSA-w7pp-m8wf-vj6r"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-23931"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pyca/cryptography/pull/8230"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pyca/cryptography/commit/d6951dca25de45abd52da51b608055371fbcde4e"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pyca/cryptography"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/cryptography/PYSEC-2023-11.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/10/msg00012.html"
  }, {
    "type" : "WEB",
    "url" : "https://security.netapp.com/advisory/ntap-20230324-0007"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-754" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-02-07T20:54:10Z",
    "nvd_published_at" : "2023-02-07T21:15:00Z"
  }
}