Skip to content

Commit f91604e

Browse files
committed
Merge pull request #27482 from billyto
* gh-27482: Polish "Sanitize URIs with non-alpha characters in their schemes" Sanitize URIs with non-alpha characters in their schemes Closes gh-27482
2 parents cff1827 + 388068c commit f91604e

File tree

2 files changed

+12
-3
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+12
-3
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]+://.+:(.*)@.+$");
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: 9 additions & 1 deletion
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.
@@ -56,6 +56,14 @@ void uriWithSingleValueWithPasswordShouldBeSanitized(String key) {
5656
.isEqualTo("http://user:******@localhost:8080");
5757
}
5858

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");
65+
}
66+
5967
@ParameterizedTest(name = "key = {0}")
6068
@MethodSource("matchingUriUserInfoKeys")
6169
void uriWithSingleValueWithNoPasswordShouldNotBeSanitized(String key) {

0 commit comments

Comments
 (0)