Skip to content

Commit 2da293a

Browse files
authored
Merge pull request #153 from github/fix/ghs-token-regex-new-format
Fix ghs_ redaction pattern to support new token format
2 parents 4fff5a4 + 17f270e commit 2da293a

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/patterns/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Patterns
1212
# https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
1313
/ghp_[A-Za-z0-9]{36,}|[0-9A-Fa-f]{40,}/,
1414
/github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}/, # Fine Grained
15-
/ghs_[a-zA-Z0-9]{36}/, # Temporary Actions Tokens
15+
/ghs_[A-Za-z0-9._-]{36,}/, # GitHub App installation tokens
1616

1717
# JWT Token
1818
# https://en.wikipedia.org/wiki/JSON_Web_Token

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.5.1"
5+
VERSION = "1.5.2"
66
end
77
end

spec/lib/redacting_logger_spec.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,39 @@
8282
expected_message: "token [REDACTED]"
8383
},
8484
{
85-
case: "github action pat",
85+
case: "github app installation token",
8686
message: "token ghs_1234567890abcdefghijklmnopqrstuvwxyz123456",
87-
expected_message: "token [REDACTED]123456"
87+
expected_message: "token [REDACTED]"
88+
},
89+
{
90+
case: "github app installation token with dots and underscores",
91+
message: "token ghs_Abcdef1234567890ghijklmnopqrstu.vw_xyz.1234567890",
92+
expected_message: "token [REDACTED]"
93+
},
94+
{
95+
case: "github app installation token with dashes",
96+
message: "token ghs_Abcdef-1234567890-ghijklmnopqrstu-vwxyz",
97+
expected_message: "token [REDACTED]"
98+
},
99+
{
100+
case: "github app installation token with mixed special chars",
101+
message: "token ghs_abc.DEF-123_ghi.JKL-456_mno.PQR-789_stu",
102+
expected_message: "token [REDACTED]"
103+
},
104+
{
105+
case: "github app installation token at minimum length (36 chars after prefix)",
106+
message: "token ghs_abcdefghijklmnopqrstuvwxyz1234567890",
107+
expected_message: "token [REDACTED]"
108+
},
109+
{
110+
case: "github app installation token longer than 36 chars",
111+
message: "token ghs_abcdefghijklmnopqrstuvwxyz1234567890.extra-chars_here.more",
112+
expected_message: "token [REDACTED]"
113+
},
114+
{
115+
case: "github app installation token too short to match",
116+
message: "token ghs_tooshort",
117+
expected_message: "token ghs_tooshort"
88118
},
89119
{
90120
case: "custom token",

0 commit comments

Comments
 (0)