Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism for denying specific IPs after they have been resolved #2105

Open
simonw opened this issue Feb 6, 2025 · 2 comments
Open

Mechanism for denying specific IPs after they have been resolved #2105

simonw opened this issue Feb 6, 2025 · 2 comments
Assignees
Labels
Type: Enhancement Most issues will probably ask for additions or changes.

Comments

@simonw
Copy link

simonw commented Feb 6, 2025

Please describe your feature request:

I want to use httpx to retrieve URLs that have been provided for me by end users.

I don't want those end users to be able to hit private URLs - like the AWS private http://169.254.169.254/latest/meta-data/ endpoint.

I can check the URLs that they are providing, but I can't easily guarantee that they haven't set up their own something.evil.com DNS entry that resolves to 169.254.169.254. Even if I resolve the hostname myself and verify its IP there's an advanced form of attack called DNS rebinding where they could potentially use a short-TTL DNS server of their own and swap the IP for an evil IP after I've checked it but before httpx fetches it.

It would be great if HTTPX had some kind of documented mechanism - subclassing a transport, or some kind of event hook perhaps? - which was specifically designed to help me run my own check against the resolved IP address before the request was sent to it.

Once I've validated the IP I'd like to be confident that HTTPX was hitting that specific IP with host: hostname.com such that I know it's not hitting some private IP address.

Describe the use case of this feature:

Helping people safely build systems that make requests against URLs provided by untrusted users.

@simonw simonw added the Type: Enhancement Most issues will probably ask for additions or changes. label Feb 6, 2025
@GeorginaReeder
Copy link

Thanks for your feature request @simonw , we'll take a look into this!

@dogancanbakir dogancanbakir self-assigned this Feb 6, 2025
@dogancanbakir
Copy link
Member

@simonw Thanks for raising this issue. We already have a mechanism that enables you to allow or deny specific IPs or CIDRs:

-allow string[]                  list of allowed IPs/CIDRs for processing (can be specified as a file or comma-separated)
-deny string[]                   list of denied IPs/CIDRs for processing (can be specified as a file or comma-separated)

Does this meet your needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

No branches or pull requests

3 participants