Skip to content

Commit 770cf01

Browse files
authored
Merge pull request #48 from github/more-patterns
Enhanced Secrets Redaction Support - More Patterns 🔑
2 parents 02b4c90 + de88d72 commit 770cf01

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/patterns/default.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ module Patterns
66
/ghp_[A-Za-z0-9]{36,}|[0-9A-Fa-f]{40,}/, # GitHub Personal Access Token
77
/github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}/, # GitHub Personal Access Token (fine-grained)
88
/ghs_[a-zA-Z0-9]{36}/, # Temporary GitHub Actions Tokens
9-
/\b(ey[a-zA-Z0-9]{17,}\.ey[a-zA-Z0-9\/\\_-]{17,}\.(?:[a-zA-Z0-9\/\\_-]{10,}={0,2})?)(?:['|\"|\n|\r|\s|\x60|;]|$)/, # JWT tokens
10-
/(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----/ # private keys
9+
%r{\b(ey[a-zA-Z0-9]{17,}\.ey[a-zA-Z0-9/\\_-]{17,}\.(?:[a-zA-Z0-9/\\_-]{10,}={0,2})?)(?:['|"|\n|\r|\s|\x60|;]|$)}, # JWT tokens
10+
/(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY( BLOCK)?-----[\s\S-]*KEY( BLOCK)?----/, # private keys
11+
%r{https://hooks\.slack\.com/services/[a-zA-Z0-9]{9,}/[a-zA-Z0-9]{9,}/[a-zA-Z0-9]{24}}, # Slack webhook
12+
%r{https://hooks\.slack\.com/workflows/[a-zA-Z0-9]{9,}/[a-zA-Z0-9]{9,}/[0-9]+?/[a-zA-Z0-9]{24}}, # Slack workflow
13+
/xoxp-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9a-f]{6,})|xoxb-(?:[0-9]{7,})-(?:[A-Za-z0-9]{14,})|xoxs-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9a-f]{7,})|xoxa-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9a-f]{7,})|xoxo-(?:[0-9]{7,})-(?:[A-Za-z0-9]{14,})|xoxa-2-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9a-f]{7,})|xoxr-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[0-9a-f]{7,})|xoxb-(?:[0-9]{7,})-(?:[0-9]{7,})-(?:[A-Za-z0-9]{14,})/, # Slack tokens
14+
/[sbr]\.[a-zA-Z0-9]{24,}/, # vault token for 1.9.x or earlier
15+
/hv[sbr]\.[a-zA-Z0-9]{24,}/, # vault token for 1.10 and later
16+
/rubygems_[0-9a-f]{48}/ # RubyGems token
1117
].freeze
1218
end

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module RedactingLogger
44
module Version
5-
VERSION = "1.2.1"
5+
VERSION = "1.3.0"
66
end
77
end

spec/lib/redacting_logger_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@
130130
case: "redacts from a Numeric match with extra numbers",
131131
message: 123_999_999_999_123,
132132
expected_message: "123[REDACTED]123"
133+
},
134+
{
135+
case: "redacts a Slack webhook",
136+
message: "posting slack message to: https://hooks.slack.com/services/T1BAAA111/B0111AAA111/MMMAAA333CCC222bbbAAA111",
137+
expected_message: "posting slack message to: [REDACTED]"
138+
},
139+
{
140+
case: "redacts a Slack workflow webhook",
141+
message: "workflow: https://hooks.slack.com/workflows/abc123XYZ/def456UVW/123456789/abcdefghijklmnopqrstuvwx",
142+
expected_message: "workflow: [REDACTED]"
143+
},
144+
{
145+
case: "redacts a Slack token",
146+
message: "using slack token: xoxb-2444333222111-2444333222111-123456789AbCdEfGHi123456",
147+
expected_message: "using slack token: [REDACTED]"
148+
},
149+
{
150+
case: "redacts a vault token",
151+
message: "logging into vault with token: s.FakeToken1234567890123456",
152+
expected_message: "logging into vault with token: [REDACTED]"
153+
},
154+
{
155+
case: "redacts a RubyGems token",
156+
message: "using rubygems token: rubygems_0123456789abcdef0123456789abcdef0123456789abcdef",
157+
expected_message: "using rubygems token: rubygems_[REDACTED]"
133158
}
134159
].each do |test|
135160
it "redacts #{test[:case]}" do

0 commit comments

Comments
 (0)