Skip to content

Commit 10ea15a

Browse files
committed
Remove sensitive information from URI query parameters
1 parent e2be18a commit 10ea15a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/java_buildpack/util/sanitizer.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,32 @@ class String
2222
#
2323
# @return [String] the sanitized uri
2424
def sanitize_uri
25+
keywords = /key|password|username|cred[entials]*[s]*|password|token|api[-_]token|api|auth[entication]*|access[-_]token|secret[-_]token/i
26+
2527
rich_uri = URI(self)
2628
rich_uri.user = nil
2729
rich_uri.password = nil
28-
rich_uri.query = rich_uri.query&.gsub(/(Api-Token=dt\w*\.\w*)\.\w*/, '\1.REDACTED')
30+
31+
if(rich_uri.query)
32+
params = Hash[URI.decode_www_form rich_uri.query]
33+
34+
query_params = ""
35+
36+
params.each do |key,value|
37+
match = key.match(keywords)
38+
39+
if(match)
40+
if(match[0] == "Api-Token" && value =~ /dt\w*/)
41+
params[key] = value.gsub(/(dt\w*\.\w*)\.\w*/, '\1.REDACTED')
42+
else
43+
params[key] = "***"
44+
end
45+
end
46+
47+
query_params += key + "=" + params[key] + "&"
48+
end
49+
rich_uri.query = query_params.chop
50+
end
2951
rich_uri.to_s
3052
end
31-
3253
end

0 commit comments

Comments
 (0)