Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions fuzz_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""Fuzz harness for requests — Python HTTP library (8 GHSA advisories).

Tests URL parsing, header parsing, and response handling
with arbitrary attacker-controlled inputs.
"""
import sys
import atheris

with atheris.instrument_imports():
import requests
from requests import structures, cookies


def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)

# 1. URL parsing — core pre-auth boundary
try:
url = fdp.ConsumeString(512)
requests.utils.urlparse(url)
except Exception:
pass

# 2. Header parsing
try:
header_str = fdp.ConsumeString(256)
requests.utils.parse_header_links(header_str)
except Exception:
pass

# 3. Case-insensitive dict (used for headers)
try:
key = fdp.ConsumeString(64)
val = fdp.ConsumeString(128)
d = structures.CaseInsensitiveDict()
d[key] = val
_ = d.get(key, "")
except Exception:
pass

# 4. Cookie parsing
try:
cookie_str = fdp.ConsumeString(512)
cookies.MockRequest(cookie_str)
except Exception:
pass


def main():
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()


if __name__ == "__main__":
main()