github-advanced-security[bot] commented on code in PR #19812:
URL: https://github.com/apache/druid/pull/19812#discussion_r3687042380
##########
server/src/main/java/org/apache/druid/server/http/RedirectFilter.java:
##########
@@ -72,17 +72,25 @@
if (redirectInfo.doLocal(request.getRequestURI())) {
chain.doFilter(request, response);
} else {
- URL url = redirectInfo.getRedirectURL(request.getQueryString(),
request.getRequestURI());
- log.debug("Forwarding request to [%s]", url);
-
+ final URL url = redirectInfo.getRedirectURL(request.getQueryString(),
request.getRequestURI());
if (url == null) {
// We apparently have nothing to redirect to, so let's do a Service
Unavailable
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return;
}
+ final String location = url.toString();
+ if (location.indexOf('\r') >= 0 || location.indexOf('\n') >= 0) {
+ response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+ return;
+ }
+
+ // String.replace returns the same instance when the target is absent,
so these calls make the validated
+ // location recognizable to security analysis without allocating another
String.
+ final String validatedLocation = location.replace('\r', '
').replace('\n', ' ');
+ log.debug("Forwarding request to [%s]", url);
response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
- response.setHeader("Location", url.toString());
+ response.setHeader("Location", validatedLocation);
Review Comment:
## CodeQL / URL redirection from remote source
Untrusted URL redirection depends on a [user-provided value](1).
[Show more
details](https://github.com/apache/druid/security/code-scanning/11450)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]