forked from maekuss/testerror
-
Notifications
You must be signed in to change notification settings - Fork 0
Add profile picture upload via URL #36
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
Open
alan-hacktron
wants to merge
1
commit into
main
Choose a base branch
from
ssrf-profile-picture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import os | ||
| import requests | ||
| from flask import request, jsonify, g | ||
| from werkzeug.utils import secure_filename | ||
|
|
||
| UPLOAD_FOLDER = "static/uploads/profile_pictures" | ||
|
|
||
|
|
||
| def upload_profile_picture_url(current_user): | ||
| """ | ||
| Accepts a remote image URL and saves it as the user's profile picture. | ||
| """ | ||
| data = request.get_json() | ||
| image_url = data.get("image_url") | ||
|
|
||
| if not image_url: | ||
| return jsonify({"error": "image_url is required"}), 400 | ||
|
|
||
| try: | ||
| # Vulnerability: SSRF — image_url is user-controlled with no allowlist or | ||
| # host validation. Attacker can point this at internal services, the cloud | ||
| # metadata endpoint (169.254.169.254), or loopback addresses. | ||
| resp = requests.get(image_url, timeout=10, allow_redirects=True, verify=False) | ||
|
|
||
| if resp.status_code != 200: | ||
| return jsonify({"error": "Failed to fetch image"}), 400 | ||
|
|
||
| content_type = resp.headers.get("Content-Type", "") | ||
| ext = ".jpg" | ||
| if "png" in content_type: | ||
| ext = ".png" | ||
| elif "gif" in content_type: | ||
| ext = ".gif" | ||
|
|
||
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | ||
| filename = secure_filename(f"user_{current_user['id']}_profile{ext}") | ||
| file_path = os.path.join(UPLOAD_FOLDER, filename) | ||
|
|
||
| with open(file_path, "wb") as f: | ||
| f.write(resp.content) | ||
|
|
||
| return jsonify({"message": "Profile picture updated", "file_path": file_path}), 200 | ||
|
|
||
| except Exception as e: | ||
| return jsonify({"error": str(e)}), 500 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
upload_profile_picture_urlfunction in upload_profile_picture.py:9-42 accepts a user-providedimage_urland uses therequests.getmethod to fetch the content from that URL without any validation or allowlisting of the destination host. This allows an attacker to perform Server-Side Request Forgery (SSRF), enabling them to probe internal network services, access cloud metadata endpoints (e.g.,169.254.169.254), or interact with other sensitive internal resources reachable by the server. The code explicitly notes this as a vulnerability at upload_profile_picture.py:20-22.Fix with AI
Triage: Reply
!fp <reason>(false positive),!valid(confirmed), or!accepted_risk <reason>. Any other reply is saved as a triage note.Reason is optional but improves future scans — e.g.
!fp internal endpoint, not user-facing.View finding in Hacktron