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
78295937
Commit
78295937
authored
Aug 24, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Sanitize password in URI properties"
See gh-17939
parent
d49a2ec9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
Sanitizer.java
.../org/springframework/boot/actuate/endpoint/Sanitizer.java
+7
-12
ConfigurationPropertiesReportEndpointTests.java
...roperties/ConfigurationPropertiesReportEndpointTests.java
+1
-1
SanitizerTests.java
...springframework/boot/actuate/endpoint/SanitizerTests.java
+13
-0
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/Sanitizer.java
View file @
78295937
...
...
@@ -16,7 +16,7 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.
net.URI
;
import
java.
util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.springframework.util.Assert
;
...
...
@@ -38,6 +38,8 @@ public class Sanitizer {
private
static
final
String
[]
REGEX_PARTS
=
{
"*"
,
"$"
,
"^"
,
"+"
};
private
static
final
Pattern
URI_USERINFO_PATTERN
=
Pattern
.
compile
(
"[A-Za-z]+://.+:(.*)@.+$"
);
private
Pattern
[]
keysToSanitize
;
public
Sanitizer
()
{
...
...
@@ -99,17 +101,10 @@ public class Sanitizer {
}
private
Object
sanitizeUri
(
Object
value
)
{
URI
uri
=
URI
.
create
(
value
.
toString
());
String
userInfo
=
uri
.
getUserInfo
();
if
(!
StringUtils
.
hasText
(
userInfo
)
||
userInfo
.
split
(
":"
).
length
==
0
)
{
return
value
;
}
String
[]
parts
=
userInfo
.
split
(
":"
);
String
userName
=
parts
[
0
];
if
(
StringUtils
.
hasText
(
userName
))
{
String
sanitizedPassword
=
"******"
;
return
uri
.
getScheme
()
+
"://"
+
userName
+
":"
+
sanitizedPassword
+
"@"
+
uri
.
getHost
()
+
":"
+
uri
.
getPort
()
+
uri
.
getPath
();
Matcher
matcher
=
URI_USERINFO_PATTERN
.
matcher
(
value
.
toString
());
String
password
=
matcher
.
matches
()
?
matcher
.
group
(
1
)
:
null
;
if
(
password
!=
null
)
{
return
StringUtils
.
replace
(
value
.
toString
(),
":"
+
password
+
"@"
,
":******@"
);
}
return
value
;
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java
View file @
78295937
...
...
@@ -286,7 +286,7 @@ class ConfigurationPropertiesReportEndpointTests {
private
URI
sensitiveUri
=
URI
.
create
(
"http://user:password@localhost:8080"
);
private
URI
noPasswordUri
=
URI
.
create
(
"http://user:
p
@localhost:8080"
);
private
URI
noPasswordUri
=
URI
.
create
(
"http://user:@localhost:8080"
);
TestProperties
()
{
this
.
secrets
.
put
(
"mine"
,
"myPrivateThing"
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/SanitizerTests.java
View file @
78295937
...
...
@@ -44,6 +44,19 @@ class SanitizerTests {
.
isEqualTo
(
"http://user:******@localhost:8080"
);
}
@Test
void
uriWithNoPasswordShouldNotBeSanitized
()
{
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
"my.uri"
,
"http://localhost:8080"
)).
isEqualTo
(
"http://localhost:8080"
);
}
@Test
void
uriWithPasswordMatchingOtherPartsOfString
()
{
Sanitizer
sanitizer
=
new
Sanitizer
();
assertThat
(
sanitizer
.
sanitize
(
"my.uri"
,
"http://user://@localhost:8080"
))
.
isEqualTo
(
"http://user:******@localhost:8080"
);
}
@Test
void
regex
()
{
Sanitizer
sanitizer
=
new
Sanitizer
(
".*lock.*"
);
...
...
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