Browse Source

Avoid request params access for form data in logRequest

Close gh-28587
pull/28862/head
rstoyanchev 3 years ago
parent
commit
b95362a3fd
  1. 9
      spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

9
spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -978,7 +978,8 @@ public class DispatcherServlet extends FrameworkServlet { @@ -978,7 +978,8 @@ public class DispatcherServlet extends FrameworkServlet {
private void logRequest(HttpServletRequest request) {
LogFormatUtils.traceDebug(logger, traceOn -> {
String params;
if (StringUtils.startsWithIgnoreCase(request.getContentType(), "multipart/")) {
String contentType = request.getContentType();
if (StringUtils.startsWithIgnoreCase(contentType, "multipart/")) {
params = "multipart";
}
else if (isEnableLoggingRequestDetails()) {
@ -987,7 +988,9 @@ public class DispatcherServlet extends FrameworkServlet { @@ -987,7 +988,9 @@ public class DispatcherServlet extends FrameworkServlet {
.collect(Collectors.joining(", "));
}
else {
params = (request.getParameterMap().isEmpty() ? "" : "masked");
// Avoid request body parsing for form data
params = (StringUtils.startsWithIgnoreCase(contentType, "application/x-www-form-urlencoded") ||
!request.getParameterMap().isEmpty() ? "masked" : "");
}
String queryString = request.getQueryString();

Loading…
Cancel
Save