Repository navigation
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
Could you please add the Apache 2.0 license header ( <!DOCTYPE html>
<!--
Copyright 2019 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html lang="en">Thanks! |
|
Hi! I'd like to contribute to this PR by adding automated tests for Would you be open to a contribution focused on security test coverage? |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces URL validation to restrict user-supplied image URLs to HTTPS on storage.googleapis.com, mitigating SSRF and path traversal vulnerabilities. However, the validation logic contains two issues: it rejects URLs that explicitly specify port 443, and it is vulnerable to path traversal bypasses via percent-encoding (e.g., %2e%2e) because it uses getRawPath() instead of getPath().
| String rawPath = uri.getRawPath(); | ||
| if (!"https".equalsIgnoreCase(uri.getScheme()) | ||
| || !ALLOWED_IMAGE_HOST.equalsIgnoreCase(uri.getHost()) | ||
| || uri.getPort() != -1 | ||
| || uri.getUserInfo() != null | ||
| || rawPath == null | ||
| || rawPath.length() <= 1 | ||
| || !rawPath.startsWith("/") | ||
| || rawPath.contains("..")) { |
There was a problem hiding this comment.
There are two issues with the current URL validation logic:
- Explicit Port Restriction: The check
uri.getPort() != -1will reject valid HTTPS URLs that explicitly specify the default port 443 (e.g.,https://storage.googleapis.com:443/...). It is better to allow both-1and443. - Path Traversal Bypass via Percent-Encoding: Using
uri.getRawPath()returns the raw, percent-encoded path. If a user passes a URL containing encoded dots (e.g.,%2e%2e),rawPath.contains("..")will evaluate tofalse, potentially bypassing the path traversal check. Usinguri.getPath()instead will decode percent-encoded characters before performing the check.
String path = uri.getPath();
int port = uri.getPort();
if (!"https".equalsIgnoreCase(uri.getScheme())
|| !ALLOWED_IMAGE_HOST.equalsIgnoreCase(uri.getHost())
|| (port != -1 && port != 443)
|| uri.getUserInfo() != null
|| path == null
|| path.length() <= 1
|| !path.startsWith("/")
|| path.contains("..")) {|
Hi! I've opened a separate PR (#10392) adding automated security tests for the The tests cover allowed and rejected URLs, malformed URIs, unsupported schemes, host validation, and URL parsing bypass cases, including encoded path traversal attempts. Could you please take a look when you have a chance? I'd appreciate any feedback on the test coverage and whether the changes align with the original fix. Thanks! |
Prevents SSRF and local file reads via Spring ResourceLoader.getResource(imageUrl) in VisionController by restricting imageUrl to HTTPS URLs on storage.googleapis.com and updating index.html defaults to official cloud-samples-data Vision images.