Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
acc453db
Commit
acc453db
authored
Feb 07, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
See gh-19999
parent
badc83d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
37 deletions
+52
-37
Sanitizer.java
.../org/springframework/boot/actuate/endpoint/Sanitizer.java
+19
-13
ConfigurationPropertiesReportEndpointTests.java
...roperties/ConfigurationPropertiesReportEndpointTests.java
+1
-2
SanitizerTests.java
...springframework/boot/actuate/endpoint/SanitizerTests.java
+24
-18
EnvironmentEndpointTests.java
...gframework/boot/actuate/env/EnvironmentEndpointTests.java
+8
-4
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/Sanitizer.java
View file @
acc453db
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -41,16 +43,22 @@ public class Sanitizer {
...
@@ -41,16 +43,22 @@ public class Sanitizer {
private
static
final
String
[]
REGEX_PARTS
=
{
"*"
,
"$"
,
"^"
,
"+"
};
private
static
final
String
[]
REGEX_PARTS
=
{
"*"
,
"$"
,
"^"
,
"+"
};
private
static
final
String
[]
DEFAULT_KEYS_TO_SANITIZE
=
{
"password"
,
"secret"
,
"key"
,
"token"
,
".*credentials.*"
,
"vcap_services"
,
"sun.java.command"
,
"uri"
,
"uris"
,
"address"
,
"addresses"
};
private
static
final
Set
<
String
>
DEFAULT_KEYS_TO_SANITIZE
=
new
LinkedHashSet
<>(
Arrays
.
asList
(
"password"
,
"secret"
,
"key"
,
"token"
,
".*credentials.*"
,
"vcap_services"
,
"sun.java.command"
));
private
static
final
String
[]
URI_USERINFO_KEYS
=
{
"uri"
,
"uris"
,
"address"
,
"addresses"
};
private
static
final
Set
<
String
>
URI_USERINFO_KEYS
=
new
LinkedHashSet
<>(
Arrays
.
asList
(
"uri"
,
"uris"
,
"address"
,
"addresses"
));
private
static
final
Pattern
URI_USERINFO_PATTERN
=
Pattern
.
compile
(
"[A-Za-z]+://.+:(.*)@.+$"
);
private
static
final
Pattern
URI_USERINFO_PATTERN
=
Pattern
.
compile
(
"[A-Za-z]+://.+:(.*)@.+$"
);
private
Pattern
[]
keysToSanitize
;
private
Pattern
[]
keysToSanitize
;
static
{
DEFAULT_KEYS_TO_SANITIZE
.
addAll
(
URI_USERINFO_KEYS
);
}
public
Sanitizer
()
{
public
Sanitizer
()
{
this
(
DEFAULT_KEYS_TO_SANITIZE
);
this
(
DEFAULT_KEYS_TO_SANITIZE
.
toArray
(
new
String
[
0
])
);
}
}
public
Sanitizer
(
String
...
keysToSanitize
)
{
public
Sanitizer
(
String
...
keysToSanitize
)
{
...
@@ -116,19 +124,17 @@ public class Sanitizer {
...
@@ -116,19 +124,17 @@ public class Sanitizer {
return
false
;
return
false
;
}
}
private
Object
sanitizeUris
(
String
uriString
)
{
private
Object
sanitizeUris
(
String
value
)
{
// Treat each uri value as possibly containing multiple uris (comma separated)
return
Arrays
.
stream
(
value
.
split
(
","
)).
map
(
this
::
sanitizeUri
).
collect
(
Collectors
.
joining
(
","
));
return
Arrays
.
stream
(
uriString
.
split
(
","
))
.
map
(
this
::
sanitizeUri
)
.
collect
(
Collectors
.
joining
(
","
));
}
}
private
String
sanitizeUri
(
String
uriString
)
{
private
String
sanitizeUri
(
String
value
)
{
Matcher
matcher
=
URI_USERINFO_PATTERN
.
matcher
(
uriString
);
Matcher
matcher
=
URI_USERINFO_PATTERN
.
matcher
(
value
);
String
password
=
matcher
.
matches
()
?
matcher
.
group
(
1
)
:
null
;
String
password
=
matcher
.
matches
()
?
matcher
.
group
(
1
)
:
null
;
if
(
password
!=
null
)
{
if
(
password
!=
null
)
{
return
StringUtils
.
replace
(
uriString
,
":"
+
password
+
"@"
,
":******@"
);
return
StringUtils
.
replace
(
value
,
":"
+
password
+
"@"
,
":******@"
);
}
}
return
uriString
;
return
value
;
}
}
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java
View file @
acc453db
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.context.properties;
...
@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.context.properties;
import
java.net.URI
;
import
java.net.URI
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java
View file @
acc453db
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,12 +16,12 @@
...
@@ -16,12 +16,12 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.MethodSource
;
import
org.junit.jupiter.params.provider.MethodSource
;
import
java.util.stream.Stream
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
/**
...
@@ -49,14 +49,15 @@ class SanitizerTests {
...
@@ -49,14 +49,15 @@ class SanitizerTests {
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithSingle
Entry
WithPasswordShouldBeSanitized
(
String
key
)
{
void
uriWithSingle
Value
WithPasswordShouldBeSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user:password@localhost:8080"
)).
isEqualTo
(
"http://user:******@localhost:8080"
);
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user:password@localhost:8080"
))
.
isEqualTo
(
"http://user:******@localhost:8080"
);
}
}
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithSingle
Entry
WithNoPasswordShouldNotBeSanitized
(
String
key
)
{
void
uriWithSingle
Value
WithNoPasswordShouldNotBeSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://localhost:8080"
)).
isEqualTo
(
"http://localhost:8080"
);
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://localhost:8080"
)).
isEqualTo
(
"http://localhost:8080"
);
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user@localhost:8080"
)).
isEqualTo
(
"http://user@localhost:8080"
);
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user@localhost:8080"
)).
isEqualTo
(
"http://user@localhost:8080"
);
...
@@ -64,22 +65,24 @@ class SanitizerTests {
...
@@ -64,22 +65,24 @@ class SanitizerTests {
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithSingle
Entry
WithPasswordMatchingOtherPartsOfStringShouldBeSanitized
(
String
key
)
{
void
uriWithSingle
Value
WithPasswordMatchingOtherPartsOfStringShouldBeSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user://@localhost:8080"
)).
isEqualTo
(
"http://user:******@localhost:8080"
);
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user://@localhost:8080"
))
.
isEqualTo
(
"http://user:******@localhost:8080"
);
}
}
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithMultiple
Entri
esEachWithPasswordShouldHaveAllSanitized
(
String
key
)
{
void
uriWithMultiple
Valu
esEachWithPasswordShouldHaveAllSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user1:password1@localhost:8080,http://user2:password2@localhost:8082"
))
assertThat
(
.
isEqualTo
(
"http://user1:******@localhost:8080,http://user2:******@localhost:8082"
);
sanitizer
.
sanitize
(
key
,
"http://user1:password1@localhost:8080,http://user2:password2@localhost:8082"
))
.
isEqualTo
(
"http://user1:******@localhost:8080,http://user2:******@localhost:8082"
);
}
}
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithMultiple
Entri
esNoneWithPasswordShouldHaveNoneSanitized
(
String
key
)
{
void
uriWithMultiple
Valu
esNoneWithPasswordShouldHaveNoneSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user@localhost:8080,http://localhost:8082"
))
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user@localhost:8080,http://localhost:8082"
))
.
isEqualTo
(
"http://user@localhost:8080,http://localhost:8082"
);
.
isEqualTo
(
"http://user@localhost:8080,http://localhost:8082"
);
...
@@ -87,22 +90,24 @@ class SanitizerTests {
...
@@ -87,22 +90,24 @@ class SanitizerTests {
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithMultiple
Entri
esSomeWithPasswordShouldHaveThoseSanitized
(
String
key
)
{
void
uriWithMultiple
Valu
esSomeWithPasswordShouldHaveThoseSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user1:password1@localhost:8080,http://user2@localhost:8082,http://localhost:8083"
))
assertThat
(
sanitizer
.
sanitize
(
key
,
.
isEqualTo
(
"http://user1:******@localhost:8080,http://user2@localhost:8082,http://localhost:8083"
);
"http://user1:password1@localhost:8080,http://user2@localhost:8082,http://localhost:8083"
)).
isEqualTo
(
"http://user1:******@localhost:8080,http://user2@localhost:8082,http://localhost:8083"
);
}
}
@ParameterizedTest
(
name
=
"key = {0}"
)
@ParameterizedTest
(
name
=
"key = {0}"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
@MethodSource
(
"matchingUriUserInfoKeys"
)
void
uriWithMultiple
Entri
esWithPasswordMatchingOtherPartsOfStringShouldBeSanitized
(
String
key
)
{
void
uriWithMultiple
Valu
esWithPasswordMatchingOtherPartsOfStringShouldBeSanitized
(
String
key
)
{
Sanitizer
sanitizer
=
new
Sanitizer
();
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user1://@localhost:8080,http://user2://@localhost:8082"
))
assertThat
(
sanitizer
.
sanitize
(
key
,
"http://user1://@localhost:8080,http://user2://@localhost:8082"
))
.
isEqualTo
(
"http://user1:******@localhost:8080,http://user2:******@localhost:8082"
);
.
isEqualTo
(
"http://user1:******@localhost:8080,http://user2:******@localhost:8082"
);
}
}
static
private
Stream
<
String
>
matchingUriUserInfoKeys
()
{
private
static
Stream
<
String
>
matchingUriUserInfoKeys
()
{
return
Stream
.
of
(
"uri"
,
"my.uri"
,
"myuri"
,
"uris"
,
"my.uris"
,
"myuris"
,
"address"
,
"my.address"
,
"myaddress"
,
"addresses"
,
"my.addresses"
,
"myaddresses"
);
return
Stream
.
of
(
"uri"
,
"my.uri"
,
"myuri"
,
"uris"
,
"my.uris"
,
"myuris"
,
"address"
,
"my.address"
,
"myaddress"
,
"addresses"
,
"my.addresses"
,
"myaddresses"
);
}
}
@Test
@Test
...
@@ -111,4 +116,5 @@ class SanitizerTests {
...
@@ -111,4 +116,5 @@ class SanitizerTests {
assertThat
(
sanitizer
.
sanitize
(
"verylOCkish"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"verylOCkish"
,
"secret"
)).
isEqualTo
(
"******"
);
assertThat
(
sanitizer
.
sanitize
(
"veryokish"
,
"secret"
)).
isEqualTo
(
"secret"
);
assertThat
(
sanitizer
.
sanitize
(
"veryokish"
,
"secret"
)).
isEqualTo
(
"secret"
);
}
}
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/env/EnvironmentEndpointTests.java
View file @
acc453db
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -257,9 +257,13 @@ class EnvironmentEndpointTests {
...
@@ -257,9 +257,13 @@ class EnvironmentEndpointTests {
@Test
@Test
void
addressesPropertyWithMultipleEntriesEachWithSensitiveInfo
()
{
void
addressesPropertyWithMultipleEntriesEachWithSensitiveInfo
()
{
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
ConfigurableEnvironment
environment
=
new
StandardEnvironment
();
TestPropertyValues
.
of
(
"sensitive.addresses=http://user:password@localhost:8080,http://user2:password2@localhost:8082"
).
applyTo
(
environment
);
TestPropertyValues
EnvironmentEntryDescriptor
descriptor
=
new
EnvironmentEndpoint
(
environment
).
environmentEntry
(
"sensitive.addresses"
);
.
of
(
"sensitive.addresses=http://user:password@localhost:8080,http://user2:password2@localhost:8082"
)
assertThat
(
descriptor
.
getProperty
().
getValue
()).
isEqualTo
(
"http://user:******@localhost:8080,http://user2:******@localhost:8082"
);
.
applyTo
(
environment
);
EnvironmentEntryDescriptor
descriptor
=
new
EnvironmentEndpoint
(
environment
)
.
environmentEntry
(
"sensitive.addresses"
);
assertThat
(
descriptor
.
getProperty
().
getValue
())
.
isEqualTo
(
"http://user:******@localhost:8080,http://user2:******@localhost:8082"
);
}
}
private
static
ConfigurableEnvironment
emptyEnvironment
()
{
private
static
ConfigurableEnvironment
emptyEnvironment
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment