Skip to content

Commit 388068c

Browse files
committed
Polish "Sanitize URIs with non-alpha characters in their schemes"
See gh-27482
1 parent bafa9c4 commit 388068c

File tree

2 files changed

+14
-5
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+14
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-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.
@@ -50,7 +50,8 @@ public class Sanitizer {
5050
private static final Set<String> URI_USERINFO_KEYS = new LinkedHashSet<>(
5151
Arrays.asList("uri", "uris", "address", "addresses"));
5252

53-
private static final Pattern URI_USERINFO_PATTERN = Pattern.compile("^[A-Za-z][A-Za-z0-9\\+\\.\\-]+://.+:(.*)@.+$");
53+
private static final Pattern URI_USERINFO_PATTERN = Pattern
54+
.compile("^\\[?[A-Za-z][A-Za-z0-9\\+\\.\\-]+://.+:(.*)@.+$");
5455

5556
private Pattern[] keysToSanitize;
5657

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-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.
@@ -52,8 +52,16 @@ void defaultNonUriKeys() {
5252
@MethodSource("matchingUriUserInfoKeys")
5353
void uriWithSingleValueWithPasswordShouldBeSanitized(String key) {
5454
Sanitizer sanitizer = new Sanitizer();
55-
assertThat(sanitizer.sanitize(key, "view-source://user:password@localhost:8080"))
56-
.isEqualTo("view-source://user:******@localhost:8080");
55+
assertThat(sanitizer.sanitize(key, "http://user:password@localhost:8080"))
56+
.isEqualTo("http://user:******@localhost:8080");
57+
}
58+
59+
@ParameterizedTest(name = "key = {0}")
60+
@MethodSource("matchingUriUserInfoKeys")
61+
void uriWithNonAlphaSchemeCharactersAndSingleValueWithPasswordShouldBeSanitized(String key) {
62+
Sanitizer sanitizer = new Sanitizer();
63+
assertThat(sanitizer.sanitize(key, "s-ch3m.+-e://user:password@localhost:8080"))
64+
.isEqualTo("s-ch3m.+-e://user:******@localhost:8080");
5765
}
5866

5967
@ParameterizedTest(name = "key = {0}")

0 commit comments

Comments
 (0)