-
Notifications
You must be signed in to change notification settings - Fork 250
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
Refactor Http Client implementation #1741
base: master
Are you sure you want to change the base?
Conversation
throws IOException { | ||
Request request = | ||
new Request.Builder() | ||
.url(buildUrl(url, params)) |
Check failure
Code scanning / CodeQL
Server-side request forgery
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 13 hours ago
To fix the SSRF vulnerability, we need to validate the user-provided input before incorporating it into the URL. One approach is to maintain a list of authorized URLs or URL prefixes and ensure that the constructed URL matches one of these authorized patterns. Alternatively, we can restrict the URL construction to a specific host or URL prefix.
In this case, we will implement a validation method that checks if the constructed URL starts with a predefined URL prefix. This ensures that the URL is within the expected domain and prevents SSRF attacks.
-
Copy modified lines R117-R123 -
Copy modified line R177
@@ -116,2 +116,9 @@ | ||
|
||
private void validateUrlPrefix(String url) { | ||
String allowedPrefix = "https://api.github.com"; // Example allowed prefix | ||
if (!url.startsWith(allowedPrefix)) { | ||
throw new IllegalArgumentException("URL is not allowed: " + url); | ||
} | ||
} | ||
|
||
private static OkHttpObservationInterceptor.Builder observationInterceptorBuilder() { | ||
@@ -169,2 +176,3 @@ | ||
public HttpUrl buildUrl(String url, Map<String, String> params) { | ||
validateUrlPrefix(url); | ||
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder(); |
Refactor the implementation using java.net with OkHttp.
Improvements