Skip to content

Commit a153938

Browse files
committed
Merge branch '5.3.x' into main
2 parents b5ffcfb + e9083d7 commit a153938

File tree

10 files changed

+56
-36
lines changed

10 files changed

+56
-36
lines changed

spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ private String decodeInternal(HttpServletRequest request, String source) {
577577
return UriUtils.decode(source, enc);
578578
}
579579
catch (UnsupportedCharsetException ex) {
580-
if (logger.isWarnEnabled()) {
581-
logger.warn("Could not decode request string [" + source + "] with encoding '" + enc +
580+
if (logger.isDebugEnabled()) {
581+
logger.debug("Could not decode request string [" + source + "] with encoding '" + enc +
582582
"': falling back to platform default encoding; exception message: " + ex.getMessage());
583583
}
584584
return URLDecoder.decode(source);

spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.core.io.ClassPathResource;
2929
import org.springframework.core.io.Resource;
3030
import org.springframework.core.io.UrlResource;
31+
import org.springframework.core.log.LogFormatUtils;
3132
import org.springframework.lang.Nullable;
3233
import org.springframework.util.StringUtils;
3334
import org.springframework.web.server.ServerWebExchange;
@@ -119,12 +120,12 @@ protected Mono<Resource> getResource(String resourcePath, Resource location) {
119120
return Mono.just(resource);
120121
}
121122
else if (logger.isWarnEnabled()) {
122-
Object allowedLocationsText = (getAllowedLocations() != null ? Arrays.asList(getAllowedLocations()) : "[]");
123-
logger.warn("""
124-
Resource path "%s" was successfully resolved, but resource \
125-
"%s" is neither under the current location "%s" nor under any \
126-
of the allowed locations %s"\
127-
""".formatted(resourcePath, resource.getURL(),location.getURL(), allowedLocationsText));
123+
Resource[] allowed = getAllowedLocations();
124+
logger.warn(LogFormatUtils.formatValue(
125+
"Resource path \"" + resourcePath + "\" was successfully resolved " +
126+
"but resource \"" + resource.getURL() + "\" is neither under the " +
127+
"current location \"" + location.getURL() + "\" nor under any of the " +
128+
"allowed locations " + (allowed != null ? Arrays.asList(allowed) : "[]"), -1, true));
128129
}
129130
}
130131
return Mono.empty();
@@ -200,7 +201,8 @@ private boolean isInvalidEncodedPath(String resourcePath) {
200201
try {
201202
String decodedPath = URLDecoder.decode(resourcePath, StandardCharsets.UTF_8);
202203
if (decodedPath.contains("../") || decodedPath.contains("..\\")) {
203-
logger.warn("Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath);
204+
logger.warn(LogFormatUtils.formatValue(
205+
"Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath, -1, true));
204206
return true;
205207
}
206208
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.core.codec.Hints;
3939
import org.springframework.core.io.Resource;
4040
import org.springframework.core.io.ResourceLoader;
41+
import org.springframework.core.log.LogFormatUtils;
4142
import org.springframework.http.CacheControl;
4243
import org.springframework.http.HttpHeaders;
4344
import org.springframework.http.HttpMethod;
@@ -567,22 +568,25 @@ private boolean isInvalidEncodedPath(String path) {
567568
protected boolean isInvalidPath(String path) {
568569
if (path.contains("WEB-INF") || path.contains("META-INF")) {
569570
if (logger.isWarnEnabled()) {
570-
logger.warn("Path with \"WEB-INF\" or \"META-INF\": [" + path + "]");
571+
logger.warn(LogFormatUtils.formatValue(
572+
"Path with \"WEB-INF\" or \"META-INF\": [" + path + "]", -1, true));
571573
}
572574
return true;
573575
}
574576
if (path.contains(":/")) {
575577
String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path);
576578
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) {
577579
if (logger.isWarnEnabled()) {
578-
logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
580+
logger.warn(LogFormatUtils.formatValue(
581+
"Path represents URL or has \"url:\" prefix: [" + path + "]", -1, true));
579582
}
580583
return true;
581584
}
582585
}
583586
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
584587
if (logger.isWarnEnabled()) {
585-
logger.warn("Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]");
588+
logger.warn(LogFormatUtils.formatValue(
589+
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));
586590
}
587591
return true;
588592
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,9 +69,8 @@ protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request)
6969
if (uriVars != null) {
7070
uriVars.forEach((name, value) -> {
7171
if (mpvs.contains(name)) {
72-
if (logger.isWarnEnabled()) {
73-
logger.warn("Skipping URI variable '" + name +
74-
"' because request contains bind value with same name.");
72+
if (logger.isDebugEnabled()) {
73+
logger.debug("URI variable '" + name + "' overridden by request bind value.");
7574
}
7675
}
7776
else {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ReactiveTypeHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -202,7 +202,7 @@ private void logExecutorWarning(MethodParameter returnType) {
202202
"-------------------------------\n" +
203203
"Controller:\t" + returnType.getContainingClass().getName() + "\n" +
204204
"Method:\t\t" + returnType.getMethod().getName() + "\n" +
205-
"Returning:\t" + ResolvableType.forMethodParameter(returnType).toString() + "\n" +
205+
"Returning:\t" + ResolvableType.forMethodParameter(returnType) + "\n" +
206206
"!!!");
207207
this.taskExecutorWarning = false;
208208
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.core.io.ClassPathResource;
3333
import org.springframework.core.io.Resource;
3434
import org.springframework.core.io.UrlResource;
35+
import org.springframework.core.log.LogFormatUtils;
3536
import org.springframework.http.server.PathContainer;
3637
import org.springframework.lang.Nullable;
3738
import org.springframework.util.StringUtils;
@@ -189,11 +190,12 @@ protected Resource getResource(String resourcePath, Resource location) throws IO
189190
return resource;
190191
}
191192
else if (logger.isWarnEnabled()) {
192-
Resource[] allowedLocations = getAllowedLocations();
193-
logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " +
194-
"but resource \"" + resource.getURL() + "\" is neither under the " +
195-
"current location \"" + location.getURL() + "\" nor under any of the " +
196-
"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
193+
Resource[] allowed = getAllowedLocations();
194+
logger.warn(LogFormatUtils.formatValue(
195+
"Resource path \"" + resourcePath + "\" was successfully resolved " +
196+
"but resource \"" + resource.getURL() + "\" is neither under " +
197+
"the current location \"" + location.getURL() + "\" nor under any of " +
198+
"the allowed locations " + (allowed != null ? Arrays.asList(allowed) : "[]"), -1, true));
197199
}
198200
}
199201
return null;
@@ -296,7 +298,8 @@ private boolean isInvalidEncodedPath(String resourcePath) {
296298
try {
297299
String decodedPath = URLDecoder.decode(resourcePath, StandardCharsets.UTF_8);
298300
if (decodedPath.contains("../") || decodedPath.contains("..\\")) {
299-
logger.warn("Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath);
301+
logger.warn(LogFormatUtils.formatValue(
302+
"Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath, -1, true));
300303
return true;
301304
}
302305
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.context.EmbeddedValueResolverAware;
3939
import org.springframework.core.io.Resource;
4040
import org.springframework.core.io.UrlResource;
41+
import org.springframework.core.log.LogFormatUtils;
4142
import org.springframework.http.HttpHeaders;
4243
import org.springframework.http.HttpMethod;
4344
import org.springframework.http.HttpRange;
@@ -729,22 +730,25 @@ private boolean isInvalidEncodedPath(String path) {
729730
protected boolean isInvalidPath(String path) {
730731
if (path.contains("WEB-INF") || path.contains("META-INF")) {
731732
if (logger.isWarnEnabled()) {
732-
logger.warn("Path with \"WEB-INF\" or \"META-INF\": [" + path + "]");
733+
logger.warn(LogFormatUtils.formatValue(
734+
"Path with \"WEB-INF\" or \"META-INF\": [" + path + "]", -1, true));
733735
}
734736
return true;
735737
}
736738
if (path.contains(":/")) {
737739
String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path);
738740
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) {
739741
if (logger.isWarnEnabled()) {
740-
logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
742+
logger.warn(LogFormatUtils.formatValue(
743+
"Path represents URL or has \"url:\" prefix: [" + path + "]", -1, true));
741744
}
742745
return true;
743746
}
744747
}
745748
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
746749
if (logger.isWarnEnabled()) {
747-
logger.warn("Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]");
750+
logger.warn(LogFormatUtils.formatValue(
751+
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));
748752
}
749753
return true;
750754
}

spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.commons.logging.LogFactory;
3030

3131
import org.springframework.context.Lifecycle;
32+
import org.springframework.core.log.LogFormatUtils;
3233
import org.springframework.http.HttpMethod;
3334
import org.springframework.http.HttpStatus;
3435
import org.springframework.http.server.ServerHttpRequest;
@@ -291,15 +292,17 @@ public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse r
291292

292293
protected void handleInvalidUpgradeHeader(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
293294
if (logger.isErrorEnabled()) {
294-
logger.error("Handshake failed due to invalid Upgrade header: " + request.getHeaders().getUpgrade());
295+
logger.error(LogFormatUtils.formatValue(
296+
"Handshake failed due to invalid Upgrade header: " + request.getHeaders().getUpgrade(), -1, true));
295297
}
296298
response.setStatusCode(HttpStatus.BAD_REQUEST);
297299
response.getBody().write("Can \"Upgrade\" only to \"WebSocket\".".getBytes(StandardCharsets.UTF_8));
298300
}
299301

300302
protected void handleInvalidConnectHeader(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
301303
if (logger.isErrorEnabled()) {
302-
logger.error("Handshake failed due to invalid Connection header " + request.getHeaders().getConnection());
304+
logger.error(LogFormatUtils.formatValue(
305+
"Handshake failed due to invalid Connection header" + request.getHeaders().getConnection(), -1, true));
303306
}
304307
response.setStatusCode(HttpStatus.BAD_REQUEST);
305308
response.getBody().write("\"Connection\" must be \"upgrade\".".getBytes(StandardCharsets.UTF_8));
@@ -323,8 +326,9 @@ protected String[] getSupportedVersions() {
323326
protected void handleWebSocketVersionNotSupported(ServerHttpRequest request, ServerHttpResponse response) {
324327
if (logger.isErrorEnabled()) {
325328
String version = request.getHeaders().getFirst("Sec-WebSocket-Version");
326-
logger.error("Handshake failed due to unsupported WebSocket version: " + version +
327-
". Supported versions: " + Arrays.toString(getSupportedVersions()));
329+
logger.error(LogFormatUtils.formatValue(
330+
"Handshake failed due to unsupported WebSocket version: " + version +
331+
". Supported versions: " + Arrays.toString(getSupportedVersions()), -1, true));
328332
}
329333
response.setStatusCode(HttpStatus.UPGRADE_REQUIRED);
330334
response.getHeaders().set(WebSocketHttpHeaders.SEC_WEBSOCKET_VERSION,

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.commons.logging.Log;
3232
import org.apache.commons.logging.LogFactory;
3333

34+
import org.springframework.core.log.LogFormatUtils;
3435
import org.springframework.http.HttpHeaders;
3536
import org.springframework.http.HttpMethod;
3637
import org.springframework.http.HttpStatus;
@@ -376,7 +377,8 @@ public final void handleRequest(ServerHttpRequest request, ServerHttpResponse re
376377

377378
if (sockJsPath == null) {
378379
if (logger.isWarnEnabled()) {
379-
logger.warn("Expected SockJS path. Failing request: " + request.getURI());
380+
logger.warn(LogFormatUtils.formatValue(
381+
"Expected SockJS path. Failing request: " + request.getURI(), -1, true));
380382
}
381383
response.setStatusCode(HttpStatus.NOT_FOUND);
382384
return;
@@ -446,7 +448,8 @@ else if (requestInfo != null) {
446448
String[] pathSegments = StringUtils.tokenizeToStringArray(sockJsPath.substring(1), "/");
447449
if (pathSegments.length != 3) {
448450
if (logger.isWarnEnabled()) {
449-
logger.warn("Invalid SockJS path '" + sockJsPath + "' - required to have 3 path segments");
451+
logger.warn(LogFormatUtils.formatValue("Invalid SockJS path '" + sockJsPath + "' - " +
452+
"required to have 3 path segments", -1, true));
450453
}
451454
if (requestInfo != null) {
452455
logger.debug("Ignoring transport request: " + requestInfo);

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
3030
import java.util.concurrent.ScheduledFuture;
3131

3232
import org.springframework.context.Lifecycle;
33+
import org.springframework.core.log.LogFormatUtils;
3334
import org.springframework.http.HttpMethod;
3435
import org.springframework.http.HttpStatus;
3536
import org.springframework.http.server.ServerHttpRequest;
@@ -234,7 +235,7 @@ protected void handleTransportRequest(ServerHttpRequest request, ServerHttpRespo
234235
TransportType transportType = TransportType.fromValue(transport);
235236
if (transportType == null) {
236237
if (logger.isWarnEnabled()) {
237-
logger.warn("Unknown transport type for " + request.getURI());
238+
logger.warn(LogFormatUtils.formatValue("Unknown transport type for " + request.getURI(), -1, true));
238239
}
239240
response.setStatusCode(HttpStatus.NOT_FOUND);
240241
return;
@@ -243,7 +244,7 @@ protected void handleTransportRequest(ServerHttpRequest request, ServerHttpRespo
243244
TransportHandler transportHandler = this.handlers.get(transportType);
244245
if (transportHandler == null) {
245246
if (logger.isWarnEnabled()) {
246-
logger.warn("No TransportHandler for " + request.getURI());
247+
logger.warn(LogFormatUtils.formatValue("No TransportHandler for " + request.getURI(), -1, true));
247248
}
248249
response.setStatusCode(HttpStatus.NOT_FOUND);
249250
return;

0 commit comments

Comments
 (0)