Skip to content
Info disclosure Disclosed report Intermediate CVE-2022-23607

Unsafe handling of user-specified cookies in treq

Treq's request methods accepted a cookies dictionary that was not scoped to any domain, so the cookies were sent to every domain the request touched. If a request was redirected to another domain, that domain would receive the cookies, potentially leaking sensitive session data.

twisted/treq

Originally disclosed on huntr

Impact

Treq's request methods (treq.get, treq.post, HTTPClient.request, HTTPClient.get, etc.) accept cookies as a dictionary, for example:

Python
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:

Python
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
  • A related issue in the handling of HTTP basic authentication was addressed in Twisted 22.1 (GHSA-92x2-jw7w-xvvx, CVE-2022-21712).

From the GitHub Advisory Database (GHSA-fhpf-pp6p-55qc, CC BY 4.0).

The original report as published on the GitHub Advisory Database. Images and videos are our own copies; raw HTML is shown as text. View it on GitHub Advisory Database.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the library stored user-supplied cookies without associating them with the request URL's origin, so its cookie handling treated them as valid for all domains.

Impact

Sensitive cookie values could be sent to an unrelated domain if the original request was redirected there, potentially leaking session information.

What the attacker needed

Application passes a cookies dictionary; request is redirected to another domain

The fix

Treq 2021.1.0 and later were fixed to bind cookies passed to request methods to the origin of the URL parameter.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A cookie is a small piece of data a website stores in your browser, often used to keep you logged in. Normally a cookie is only sent back to the website that set it. Here, a Python library let a programmer attach cookies to a request without saying which website they belonged to, so the library sent them to any website the request ended up visiting, including after a redirect.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.