From 4998ad745b67edeadefe541c94ed029b53933d3b Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Tue, 22 Aug 2023 11:31:23 -0700 Subject: [PATCH] Avoid protocol relative redirects --- .../apache/catalina/authenticator/FormAuthenticator.java | 6 ++++++ webapps/docs/changelog.xml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/java/org/apache/catalina/authenticator/FormAuthenticator.java b/java/org/apache/catalina/authenticator/FormAuthenticator.java index a57db51776b6..d54cc62182e5 100644 --- a/java/org/apache/catalina/authenticator/FormAuthenticator.java +++ b/java/org/apache/catalina/authenticator/FormAuthenticator.java @@ -747,6 +747,12 @@ protected String savedRequestURL(Session session) { sb.append('?'); sb.append(saved.getQueryString()); } + + // Avoid protocol relative redirects + while (sb.length() > 1 && sb.charAt(1) == '/') { + sb.deleteCharAt(0); + } + return sb.toString(); } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index bacf432793ca..9eadbe2b8c72 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -117,6 +117,9 @@ Update code comments and Tomcat output to use MiB for 1024 * 1024 bytes and KiB for 1024 bytes rather than MB and kB. (martk) + + Avoid protocol relative redirects in FORM authentication. (markt) +