CVE-2022-23607: Treq Unsafe Handling Of User-specified Cookies Vulnerability

HIGH
Advisory Identifier: GHSA-fhpf-pp6p-55qc
CVSS 6.5
CWE-425 CWE-601 CWE-200
Published
Advisory Summary

CVE-2022-23607 is a HIGH (CVSS 6.5) unsafe handling of user-specified cookies vulnerability (CWE-425: Direct Request ('Forced Browsing')) affecting Treq libraries in the PyPI ecosystem. The issue involves unsafe handling of user-specified cookies in treq. Remediation is available by upgrading affected packages to version 22.1.0.

CVE-2022-23607 at a Glance

CVE Identifier CVE-2022-23607
GHSA Identifier GHSA-fhpf-pp6p-55qc
Severity HIGH
CVSS v3.1 Base Score 6.5
CWE Classification CWE-425: Direct Request ('Forced Browsing')
Affected Product Treq
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:R/S:U/C:H/I:N/A:N).

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

How to Fix CVE-2022-23607

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

treq fixed: 22.1.0
pip install treq>=22.1.0
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 treq

How to Check if You Are Affected

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

pip show treq

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-425: Direct Request ('Forced Browsing'), where the web application does not adequately enforce appropriate authorization on all restricted urls, scripts, or files. In Treq, 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 Treq's request methods (`treq.get`, `treq.post`, `HTTPClient.request`, `HTTPClient.get`, etc.) accept cookies as a dictionary, for example: ```py treq.get('https://example.com/', cookies={'session': '1234'}) ``` Such cookies are not bound to a single domain, and are therefore sent to *every* domain ("supercookies"). This can potentially cause sensitive information to leak upon an HTTP redirect to a different domain., e.g. should `https://example.com` redirect to `http://cloudstorageprovider.com` the latter will receive the cookie `session`. ### Patches Treq 2021.1.0 and later bind cookies given to request methods (`treq.request`, `treq.get`, `HTTPClient.request`, `HTTPClient.get`, etc.) to the origin of the *url* parameter. ### Workarounds Instead of passing a dictionary as the *cookies* argument, pass a `http.cookiejar.CookieJar` instance with properly domain- and scheme-scoped cookies in it: ```py from http.cookiejar import CookieJar from requests.cookies import create_cookie jar = CookieJar() jar.add_cookie( create_cookie( name='session', value='1234', domain='example.com', secure=True, ), ) client = HTTPClient(cookies=jar) client.get('https://example.com/') ``` ### References * Originally reported at [huntr.dev](https://huntr.dev/bounties/3c9204fc-a3d1-4441-8599-924c5f57e7ae/?token=06d930e37046c914bcb037e85cc227dc7b510b475989fc69837566562ba899277d46b0fb4b1e21cdcb6ddc1b7d9b1ded632cf3a3551ecb89afca16a63b34641284b50479d5195bba2ac09b116f3dd4fad27f54404c2de922c05c8c8b744aec27bb4d4d198cb8b3abf479af0c2d5fbaa10412da7922594ac3eb39) * A related issue in the handling of HTTP basic authentication was addressed in Twisted 22.1 ([GHSA-92x2-jw7w-xvvx](https://github.com/twisted/twisted/security/advisories/GHSA-92x2-jw7w-xvvx), CVE-2022-21712).

CVE-2022-23607 Affected Treq Versions

1 component(s)
Fixed Versions:
22.1.0
Product / Package Ecosystem Affected Versions Fixed Version
treq
PyPI
< 22.1.0
22.1.0

References

Frequently Asked Questions

What is CVE-2022-23607?
CVE-2022-23607 is a security vulnerability in Treq involving Unsafe handling of user-specified cookies in treq under CWE-425: Direct Request ('Forced Browsing').
Which Treq versions are affected?
Affected versions include releases prior to 22.1.0 across affected packages: treq.
What version fixes CVE-2022-23607?
Upgrading to 22.1.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is treq affected?
Yes, treq is affected in releases prior to 22.1.0. Upgrade your dependency to 22.1.0 or later.
What is the CVSS score of CVE-2022-23607?
CVE-2022-23607 has a CVSS v3.1 base score of 6.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2022-23607?
CVE-2022-23607 is classified under CWE-425: Direct Request ('Forced Browsing') (The web application does not adequately enforce appropriate authorization on all restricted URLs, scripts, or files.).
How can I check PyPI dependencies for CVE-2022-23607?
Run the dependency tree command: 'pip show treq'. 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-fhpf-pp6p-55qc",
  "modified" : "2024-11-13T23:03:05Z",
  "published" : "2022-02-01T00:43:38Z",
  "aliases" : [ "CVE-2022-23607" ],
  "summary" : "Unsafe handling of user-specified cookies in treq",
  "details" : "### Impact\n\nTreq's request methods (`treq.get`, `treq.post`, `HTTPClient.request`, `HTTPClient.get`, etc.) accept cookies as a dictionary, for example:\n\n```py\ntreq.get('https://example.com/', cookies={'session': '1234'})\n```\n\nSuch cookies are not bound to a single domain, and are therefore sent to *every* domain (\"supercookies\"). This can potentially cause sensitive information to leak upon an HTTP redirect to a different domain., e.g. should `https://example.com` redirect to `http://cloudstorageprovider.com` the latter will receive the cookie `session`.\n\n### Patches\n\nTreq 2021.1.0 and later bind cookies given to request methods (`treq.request`, `treq.get`, `HTTPClient.request`, `HTTPClient.get`, etc.) to the origin of the *url* parameter.\n\n### Workarounds\n\nInstead of passing a dictionary as the *cookies* argument, pass a `http.cookiejar.CookieJar` instance with properly domain- and scheme-scoped cookies in it:\n\n```py\nfrom http.cookiejar import CookieJar\nfrom requests.cookies import create_cookie\n\njar = CookieJar()\njar.add_cookie(\n    create_cookie(\n        name='session',\n        value='1234',\n        domain='example.com',\n        secure=True,\n    ),\n)\nclient = HTTPClient(cookies=jar)\nclient.get('https://example.com/')\n```\n\n### References\n\n* Originally reported at [huntr.dev](https://huntr.dev/bounties/3c9204fc-a3d1-4441-8599-924c5f57e7ae/?token=06d930e37046c914bcb037e85cc227dc7b510b475989fc69837566562ba899277d46b0fb4b1e21cdcb6ddc1b7d9b1ded632cf3a3551ecb89afca16a63b34641284b50479d5195bba2ac09b116f3dd4fad27f54404c2de922c05c8c8b744aec27bb4d4d198cb8b3abf479af0c2d5fbaa10412da7922594ac3eb39)\n* A related issue in the handling of HTTP basic authentication was addressed in Twisted 22.1 ([GHSA-92x2-jw7w-xvvx](https://github.com/twisted/twisted/security/advisories/GHSA-92x2-jw7w-xvvx), CVE-2022-21712).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "treq"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "22.1.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twisted/treq/security/advisories/GHSA-fhpf-pp6p-55qc"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-23607"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/treq/commit/1da6022cc880bbcff59321abe02bf8498b89efb2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/treq/PYSEC-2022-26.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twisted/treq"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/treq/releases/tag/release-22.1.0"
  }, {
    "type" : "WEB",
    "url" : "https://huntr.dev/bounties/3c9204fc-a3d1-4441-8599-924c5f57e7ae/?token=06d930e37046c914bcb037e85cc227dc7b510b475989fc69837566562ba899277d46b0fb4b1e21cdcb6ddc1b7d9b1ded632cf3a3551ecb89afca16a63b34641284b50479d5195bba2ac09b116f3dd4fad27f54404c2de922c05c8c8b744aec27bb4d4d198cb8b3abf479af0c2d5fbaa10412da7922594ac3eb39"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2022/03/msg00025.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200", "CWE-425", "CWE-601" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-01-31T22:05:38Z",
    "nvd_published_at" : "2022-02-01T11:15:00Z"
  }
}