fix(security): resolve profile update validation bypass and SSRF#507
Open
prince-shakyaa wants to merge 1 commit into
Open
fix(security): resolve profile update validation bypass and SSRF#507prince-shakyaa wants to merge 1 commit into
prince-shakyaa wants to merge 1 commit into
Conversation
17c86b3 to
40740ff
Compare
Author
|
Hi @saikishu @e2hln , |
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.
fix(security): resolve profile update validation bypass and SSRF via insecure avatar URLs
Description
Fixes #506
This Pull Request resolves a high-severity security vulnerability in the user profile and sharing module.
The Problem
Previously, the
ProfileUpdateRequestallowed updating fields optionally. The route only validated that theavatar_urlstarted withhttps://ifavatar_typewas explicitly set to"url"in the current request payload:If a user's profile already had
avatar_type = "url"in the database, they could bypass this security check by sending a PUT request containing onlyavatar_url(omittingavatar_typeentirely). The backend successfully saved the insecure URL (e.g.http://127.0.0.1:8500/orhttp://169.254.169.254/).When generating the profile sharing card (
/share/profile/{username}/card.png), the backend issued an asynchronoushttpx.getrequest directly to this user-supplied insecure URL to fetch and base64-encode the image. This resulted in a Server-Side Request Forgery (SSRF) vulnerability, enabling attackers to scan local ports, query intranet systems, or access cloud metadata services.The Fix
This PR updates the validation check in profile.py to validate the
avatar_urlbased on the effective (resolved) avatar type (taking the incoming request's type, or falling back to the existing profile's saved type in the database if omitted).Key Changes
update_profileroute validation to compute theeffective_avatar_typeandeffective_avatar_urlbefore validating the schema."url", the effective avatar URL must use thehttps://protocol.Verification & Testing
Manual Verification
urlwith a valid secure URL:{ "avatar_type": "url", "avatar_url": "https://secure-avatar.com/image.png" }avatar_urlto an insecure address (http://127.0.0.1:8000orhttp://169.254.169.254) while omitting theavatar_typefield:{ "avatar_url": "http://127.0.0.1:8000" }400 Bad Request("Avatar URL must use HTTPS"), closing the validation bypass.