-
Notifications
You must be signed in to change notification settings - Fork 472
add feature to download image or video file created locally #1606
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @varungup90, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the system by enabling the download of locally created media files. It establishes a new Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a feature to download files, but in doing so, it adds two critical security vulnerabilities: a Server-Side Request Forgery (SSRF) in the Go code and a Path Traversal vulnerability in the Python code. Both of these issues could allow an attacker to access internal services or sensitive files on the server. These must be addressed before merging. Additionally, there are a few medium-severity issues related to maintainability and an unused dependency that should be cleaned up.
pkg/metadata/handlers.go
Outdated
if req.IP == "" { | ||
http.Error(w, "missing required parameter: ip", http.StatusBadRequest) | ||
return | ||
} | ||
if req.Port == "" { | ||
http.Error(w, "missing required parameter: port", http.StatusBadRequest) | ||
return | ||
} | ||
if req.Path == "" { | ||
http.Error(w, "missing required parameter: path", http.StatusBadRequest) | ||
return | ||
} | ||
if !strings.HasPrefix(req.Path, "/") { | ||
req.Path = "/" + req.Path | ||
} | ||
|
||
// Construct the download URL | ||
downloadURL := fmt.Sprintf("http://%s:%s/view%s", req.IP, req.Port, req.Path) | ||
klog.Infof("Attempting to download file from: %s", downloadURL) |
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.
This handler introduces a critical Server-Side Request Forgery (SSRF) vulnerability. The IP
and Port
parameters are taken directly from the user's request body and used to construct a downloadURL
. An attacker can abuse this to make the server send requests to arbitrary internal services, including localhost, or scan the internal network. You should never trust user input to construct request URLs directly.
To fix this, you must validate the IP
against an allowlist of trusted hosts, or at a minimum, block requests to private, loopback, and link-local IP address ranges.
python/aibrix/aibrix/app.py
Outdated
@router.get("/view/{file_path:path}") | ||
async def view_file_complete(file_path: str): | ||
""" | ||
Return the entire file for download using path parameter. | ||
Usage: GET /view/etc/hosts or GET /view/tmp/myfile.txt | ||
""" | ||
try: | ||
# Ensure absolute path | ||
if not file_path.startswith('/'): | ||
file_path = '/' + file_path | ||
|
||
# Validate that the file exists | ||
if not os.path.exists(file_path): | ||
raise HTTPException(status_code=404, detail=f"File not found: {file_path}") |
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.
This endpoint introduces a critical Path Traversal vulnerability. It allows a user to specify an arbitrary file_path
in the URL, which is then used to serve a file from the server's filesystem. An attacker could use this to read sensitive files like /etc/passwd
, configuration files, or source code by providing payloads like ../../../../etc/passwd
.
To fix this, you must restrict file access to a designated, safe directory. The user-provided path should be treated as relative and joined with a secure base directory. You must also ensure that the final resolved path is still within this safe directory to prevent traversal attacks.
pkg/metadata/handlers.go
Outdated
if req.IP == "" { | ||
http.Error(w, "missing required parameter: ip", http.StatusBadRequest) | ||
return | ||
} | ||
if req.Port == "" { | ||
http.Error(w, "missing required parameter: port", http.StatusBadRequest) | ||
return | ||
} | ||
if req.Path == "" { | ||
http.Error(w, "missing required parameter: path", http.StatusBadRequest) | ||
return |
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.
_, ok := jsonMap["save_disk_path"] | ||
if ok && routingCtx.Algorithm == routing.RouterNotSet { | ||
routingCtx.Algorithm = routing.RouterRandom | ||
} |
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.
This logic implicitly changes the routing algorithm to RouterRandom
if save_disk_path
is present in the request. This behavior is not obvious and could be surprising for future maintainers. For better maintainability, please add a comment explaining the reason for this logic.
_, ok := jsonMap["save_disk_path"] | |
if ok && routingCtx.Algorithm == routing.RouterNotSet { | |
routingCtx.Algorithm = routing.RouterRandom | |
} | |
_, ok := jsonMap["save_disk_path"] | |
// If `save_disk_path` is specified, the request may need to be routed to a specific pod | |
// that can save the file. If no routing algorithm is set, default to random routing. | |
if ok && routingCtx.Algorithm == routing.RouterNotSet { | |
routingCtx.Algorithm = routing.RouterRandom | |
} |
ca209df
to
e559291
Compare
Signed-off-by: varungupta <varungup90@gmail.com>
Signed-off-by: varungupta <varungup90@gmail.com>
Signed-off-by: varungupta <varungup90@gmail.com>
Signed-off-by: varungupta <varungup90@gmail.com>
24905ca
to
f1f1cba
Compare
Signed-off-by: varungupta <varungup90@gmail.com>
f1f1cba
to
f4a9655
Compare
Pull Request Description
Create an image or video
Related Issues
Resolves: #[Insert issue number(s)]
Important: Before submitting, please complete the description above and review the checklist below.
Contribution Guidelines (Expand for Details)
We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:
Pull Request Title Format
Your PR title should start with one of these prefixes to indicate the nature of the change:
[Bug]
: Corrections to existing functionality[CI]
: Changes to build process or CI pipeline[Docs]
: Updates or additions to documentation[API]
: Modifications to aibrix's API or interface[CLI]
: Changes or additions to the Command Line Interface[Misc]
: For changes not covered above (use sparingly)Note: For changes spanning multiple categories, use multiple prefixes in order of importance.
Submission Checklist
By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.