17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/codex_notify/secret_protection.rb', line 17
def redact(value)
text = value.to_s.dup
text.gsub!(/(\b(?:[A-Za-z_][A-Za-z0-9_.-]*)?(?:proxy[-_]?authorization|authorization)[A-Za-z0-9_.-]*\s*[=:]\s*)(?:(?:Bearer|Basic)\s+)?[^\s'",;}]+/i) do
"#{Regexp.last_match(1)}#{REDACTED}"
end
text.gsub!(/(--(?:token|password|passwd|secret|api[-_]?key)(?:=|\s+))(?:"[^"]*"|'[^']*'|[^\s]+)/i) do
"#{Regexp.last_match(1)}#{REDACTED}"
end
text.gsub!(/("[^"]*#{SENSITIVE_NAME.source}[^"]*"\s*:\s*)(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\s,}\]]+)/i) do
"#{Regexp.last_match(1)}#{REDACTED}"
end
text.gsub!(/(\b(?:[A-Za-z_][A-Za-z0-9_.-]*)?#{SENSITIVE_NAME.source}[A-Za-z0-9_.-]*\s*[=:]\s*)(?:"[^"]*"|'[^']*'|[^\s,;}]+)/i) do
"#{Regexp.last_match(1)}#{REDACTED}"
end
KNOWN_SECRET_PATTERNS.each { |pattern| text.gsub!(pattern, REDACTED) }
text
end
|