Skip to content

Commit 62cb87b

Browse files
committed
Merge branch '2.2.x' into 2.3.x
Closes gh-23252
2 parents 7c13c01 + 775f0fa commit 62cb87b

File tree

3 files changed

+25
-4
lines changed
  • spring-boot-project

3 files changed

+25
-4
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/Sanitizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Stephane Nicoll
3838
* @author HaiTao Zhang
3939
* @author Chris Bono
40+
* @author David Good
4041
* @since 2.0.0
4142
*/
4243
public class Sanitizer {
@@ -49,7 +50,7 @@ public class Sanitizer {
4950
private static final Set<String> URI_USERINFO_KEYS = new LinkedHashSet<>(
5051
Arrays.asList("uri", "uris", "address", "addresses"));
5152

52-
private static final Pattern URI_USERINFO_PATTERN = Pattern.compile("[A-Za-z]+://.+:(.*)@.+$");
53+
private static final Pattern URI_USERINFO_PATTERN = Pattern.compile("\\[?[A-Za-z]+://.+:(.*)@.+$");
5354

5455
private Pattern[] keysToSanitize;
5556

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @author Phillip Webb
3131
* @author Stephane Nicoll
3232
* @author Chris Bono
33+
* @author David Good
3334
*/
3435
class SanitizerTests {
3536

@@ -105,6 +106,22 @@ void uriWithMultipleValuesWithPasswordMatchingOtherPartsOfStringShouldBeSanitize
105106
.isEqualTo("http://user1:******@localhost:8080,http://user2:******@localhost:8082");
106107
}
107108

109+
@ParameterizedTest(name = "key = {0}")
110+
@MethodSource("matchingUriUserInfoKeys")
111+
void uriKeyWithUserProvidedListLiteralShouldBeSanitized(String key) {
112+
Sanitizer sanitizer = new Sanitizer();
113+
assertThat(sanitizer.sanitize(key, "[amqp://username:password@host/]"))
114+
.isEqualTo("[amqp://username:******@host/]");
115+
assertThat(sanitizer.sanitize(key,
116+
"[http://user1:password1@localhost:8080,http://user2@localhost:8082,http://localhost:8083]")).isEqualTo(
117+
"[http://user1:******@localhost:8080,http://user2@localhost:8082,http://localhost:8083]");
118+
assertThat(sanitizer.sanitize(key,
119+
"[http://user1:password1@localhost:8080,http://user2:password2@localhost:8082]"))
120+
.isEqualTo("[http://user1:******@localhost:8080,http://user2:******@localhost:8082]");
121+
assertThat(sanitizer.sanitize(key, "[http://user1@localhost:8080,http://user2@localhost:8082]"))
122+
.isEqualTo("[http://user1@localhost:8080,http://user2@localhost:8082]");
123+
}
124+
108125
private static Stream<String> matchingUriUserInfoKeys() {
109126
return Stream.of("uri", "my.uri", "myuri", "uris", "my.uris", "myuris", "address", "my.address", "myaddress",
110127
"addresses", "my.addresses", "myaddresses");

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,10 +2242,13 @@ Information returned by the `env` and `configprops` endpoints can be somewhat se
22422242

22432243
The patterns to use can be customized using the `management.endpoint.env.keys-to-sanitize` and `management.endpoint.configprops.keys-to-sanitize` respectively.
22442244

2245-
Spring Boot uses sensible defaults for such keys: any key ending with the word "password", "secret", "key", "token", "vcap_services", "sun.java.command", "uri", "uris", "address" or "addresses" is sanitized.
2246-
Additionally, any key that holds the word `credentials` as part of the key is sanitized (configured as a regular expression, i.e. `+.*credentials.*+`).
2245+
Spring Boot uses sensible defaults for such keys: any key ending with the word "password", "secret", "key", "token", "vcap_services", "sun.java.command" is entirely sanitized.
2246+
Additionally, any key that holds the word `credentials` as part of the key is sanitized (configured as a regular expression, i.e. `+*credentials.*+`).
22472247

2248-
If any of the keys to sanitize are URI format (i.e. `<scheme>://<username>:<password>@<host>:<port>/`), only the password part is sanitized.
2248+
Furthermore, Spring Boot only sanitizes the sensitive portion of URIs for keys which end with "uri", "uris", "address", or "addresses".
2249+
The sensitive portion of the URI is identified using the format `<scheme>://<username>:<password>@<host>:<port>/`.
2250+
For example, for the property `myclient.uri=http://user1:password1@localhost:8081`, the resulting sanitized value is
2251+
`++http://user1:******@localhost:8081++`.
22492252

22502253

22512254

0 commit comments

Comments
 (0)