Skip to content

Commit ebdda29

Browse files
fix: URL validation for CodeQL recognition (#399)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4040484 commit ebdda29

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

backend-java/.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,31 @@ public static void main( String[] args )
131131
* - Canonicalizing hostnames (removing trailing dots, normalizing case)
132132
* - Restricting to HTTPS only
133133
* - Rejecting null, empty, or invalid hostnames
134+
* - Rejecting URLs with user info (user:pass@host)
134135
*
135136
* @param url the URL to validate
136137
* @return true if the URL is allowed, false otherwise
137138
*/
138139
private static boolean isAllowedUrl( URL url )
139140
{
140-
// Only allow HTTPS, and an EXACT host match after canonicalization.
141+
// Only allow HTTPS protocol
141142
if (!"https".equalsIgnoreCase(url.getProtocol())) {
142143
return false;
143144
}
145+
146+
// Reject URLs with user info (user:pass@host) - SSRF protection
147+
if (url.getUserInfo() != null) {
148+
return false;
149+
}
150+
144151
String actualHost = canonicalizeHost(url.getHost());
145152
// Reject null or invalid hostnames
146153
if (actualHost == null) {
147154
return false;
148155
}
156+
149157
// No subdomain allowed, just exact host match using pre-computed canonicalized hosts.
158+
// IP addresses and localhost are automatically rejected since they won't match allowed hostnames.
150159
return CANONICALIZED_ALLOWED_HOSTS.contains(actualHost);
151160
}
152161

0 commit comments

Comments
 (0)