Sanitize SPRING_APPLICATION_JSON by default

Update `Sanitizer` default keys to include `SPRING_APPLICATION_JSON`.

Fixes gh-28045
pull/28086/head
Phillip Webb 3 years ago
parent ec12d51f30
commit bbb4ac1542

@ -44,8 +44,9 @@ public class Sanitizer {
private static final String[] REGEX_PARTS = { "*", "$", "^", "+" }; private static final String[] REGEX_PARTS = { "*", "$", "^", "+" };
private static final Set<String> DEFAULT_KEYS_TO_SANITIZE = new LinkedHashSet<>(Arrays.asList("password", "secret", private static final Set<String> DEFAULT_KEYS_TO_SANITIZE = new LinkedHashSet<>(
"key", "token", ".*credentials.*", "vcap_services", "sun.java.command")); Arrays.asList("password", "secret", "key", "token", ".*credentials.*", "vcap_services", "sun.java.command",
"^spring[\\._]application[\\\\._]json$"));
private static final Set<String> URI_USERINFO_KEYS = new LinkedHashSet<>( private static final Set<String> URI_USERINFO_KEYS = new LinkedHashSet<>(
Arrays.asList("uri", "uris", "address", "addresses")); Arrays.asList("uri", "uris", "address", "addresses"));

@ -46,6 +46,8 @@ class SanitizerTests {
assertThat(sanitizer.sanitize("sometoken", "secret")).isEqualTo("******"); assertThat(sanitizer.sanitize("sometoken", "secret")).isEqualTo("******");
assertThat(sanitizer.sanitize("find", "secret")).isEqualTo("secret"); assertThat(sanitizer.sanitize("find", "secret")).isEqualTo("secret");
assertThat(sanitizer.sanitize("sun.java.command", "--spring.redis.password=pa55w0rd")).isEqualTo("******"); assertThat(sanitizer.sanitize("sun.java.command", "--spring.redis.password=pa55w0rd")).isEqualTo("******");
assertThat(sanitizer.sanitize("SPRING_APPLICATION_JSON", "{password:123}")).isEqualTo("******");
assertThat(sanitizer.sanitize("spring.application.json", "{password:123}")).isEqualTo("******");
} }
@ParameterizedTest(name = "key = {0}") @ParameterizedTest(name = "key = {0}")

Loading…
Cancel
Save