Repository navigation
fix(security): resolve profile update validation bypass and SSRF - #507
Open
prince-shakyaa wants to merge 6 commits into
Open
prince-shakyaa wants to merge 6 commits into
prince-shakyaa wants to merge 6 commits into
Conversation
prince-shakyaa
force-pushed
the
fix/profile-avatar-ssrf
branch
from
May 19, 2026 19:47
17c86b3 to
40740ff
Compare
Author
|
Hi @saikishu @e2hln , |
8 tasks done
…en SSRF checks - send the original hostname as SNI so the pinned-IP request verifies the real cert (drop verify=False) - block CGNAT, 0.0.0.0/8, IPv6 unspecified, IPv4-mapped IPv6 and other non-public ranges - return 400 instead of 500 for malformed ports, reject credentials in the URL - resolve DNS off the event loop - tests no longer hit real DNS
Author
|
Hi @saikishu @e2hln, I've updated this PR and it's ready for review.
I've also seen #610 for the same issue. |
Read the avatar body in chunks and drop it as soon as it goes over the limit, and reject a too-large Content-Length up front, so a huge response is never fully loaded into memory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #506
Problem
PUT /api/v1/profileonly checked thatavatar_urlstarts withhttps://whenavatar_type: "url"was in the same request. If your profile already hadavatar_type = "url", you could send justavatar_urland skip the check completely. Then/share/profile/{username}/card.pngfetches that URL from the server, so you get SSRF to loopback, internal services or cloud metadata (169.254.169.254). It followed redirects too.Fix
profile.py
get_safe_ssrf_ip()resolves the host withgetaddrinfo(IPv4 and IPv6) and rejects the URL if any answer is non-public. That covers loopback, RFC-1918, link-local/metadata, CGNAT100.64.0.0/10,0.0.0.0/8, IPv6 loopback/ULA/link-local/unspecified, IPv4-mapped IPv6 like::ffff:127.0.0.1, plus anything Python marks private/reserved/multicast.https://is allowed. Credentials in the URL and bad ports are rejected with a 400 (a bad port used to cause a 500).share.py
Hostheader and in SNI (httpx's publicsni_hostnameextension), so the cert is checked against the real domain. The earlier version of this PR usedverify=False. That's gone now.Content-Lengthalready says it's too big), so a huge response never gets fully loaded into memory.Testing
tests/unit/apps/ctf/test_profile_security.py: 26 tests covering the bypass, each blocked range, mixed public/private DNS answers, bad ports, credentials, and that the fetch pins the IP with redirects off, TLS verification on and the right Host/SNI, plus the 2 MiB cap. DNS is faked, so there are no network calls.tests/unitoverall: everything passes except 3 tests intests/unit/agents/test_specialized_agents.py, which fail the same way onmain.