Skip to content

Commit

Permalink
https://github.com/jenkinsci/jenkins/pull/9672#issuecomment-2326277011
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Sep 3, 2024
1 parent c3ec4a1 commit 520776a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/main/java/hudson/security/csrf/CrumbIssuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package hudson.security.csrf;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.Util;
Expand All @@ -15,8 +16,10 @@
import hudson.model.Descriptor;
import hudson.util.MultipartFormDataParser;
import io.jenkins.servlet.ServletRequestWrapper;
import io.jenkins.servlet.http.HttpServletRequestWrapper;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -164,7 +167,15 @@ public boolean validateCrumb(ServletRequest request, MultipartFormDataParser par
*/
@Deprecated
public boolean validateCrumb(javax.servlet.ServletRequest request, MultipartFormDataParser parser) {
return validateCrumb(request != null ? ServletRequestWrapper.toJakartaServletRequest(request) : null, parser);
return validateCrumb(request != null ? wrap(request) : null, parser);
}

private static ServletRequest wrap(@NonNull javax.servlet.ServletRequest request) {
if (request instanceof javax.servlet.http.HttpServletRequest httpRequest) {
return HttpServletRequestWrapper.toJakartaHttpServletRequest(httpRequest);
} else {
return ServletRequestWrapper.toJakartaServletRequest(request);
}
}

/**
Expand All @@ -175,7 +186,7 @@ public boolean validateCrumb(javax.servlet.ServletRequest request, MultipartForm
public /* abstract */ boolean validateCrumb(ServletRequest request, String salt, String crumb) {
return Util.ifOverridden(
() -> validateCrumb(
request != null ? ServletRequestWrapper.fromJakartaServletRequest(request) : null,
request != null ? wrap(request) : null,
salt,
crumb),
CrumbIssuer.class,
Expand All @@ -186,6 +197,14 @@ public boolean validateCrumb(javax.servlet.ServletRequest request, MultipartForm
String.class);
}

private static javax.servlet.ServletRequest wrap(@NonNull ServletRequest request) {
if (request instanceof HttpServletRequest httpRequest) {
return HttpServletRequestWrapper.fromJakartaHttpServletRequest(httpRequest);
} else {
return ServletRequestWrapper.fromJakartaServletRequest(request);
}
}

/**
* @deprecated use {@link #validateCrumb(ServletRequest, String, String)}
*/
Expand Down

0 comments on commit 520776a

Please sign in to comment.