File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,32 @@ class String
22
22
#
23
23
# @return [String] the sanitized uri
24
24
def sanitize_uri
25
+ keywords = /key|password|username|cred[entials]*[s]*|password|token|api[-_]token|api|auth[entication]*|access[-_]token|secret[-_]token/i
26
+
25
27
rich_uri = URI ( self )
26
28
rich_uri . user = nil
27
29
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
29
51
rich_uri . to_s
30
52
end
31
-
32
53
end
You can’t perform that action at this time.
0 commit comments