Skip to content

Add Authorization Bearer token pattern #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/patterns/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ module Patterns
# Vault Tokens
# https://github.com/hashicorp/vault/issues/27151
/[sbr]\.[a-zA-Z0-9]{24,}/, # <= 1.9.x
/hv[sbr]\.[a-zA-Z0-9]{24,}/ # >= 1.10
/hv[sbr]\.[a-zA-Z0-9]{24,}/, # >= 1.10

# Authorization bearer tokens
# https://datatracker.ietf.org/doc/html/rfc6750#section-2.1
/(?i)authorization:\s+bearer\s+[A-Za-z0-9\-_\.=~+\/]+/,
].freeze
end
10 changes: 10 additions & 0 deletions spec/lib/redacting_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
case: "redacts a RubyGems token",
message: "using rubygems token: rubygems_0123456789abcdef0123456789abcdef0123456789abcdef",
expected_message: "using rubygems token: [REDACTED]"
},
{
case: "redacts authorization bearer token",
message: '-H "Authorization: Bearer ab123456789a1abcd1~_.-+456ABCDE=" -H "Content-Type: application/json"',
expected_message: '-H "[REDACTED]" -H "Content-Type: application/json"'
},
{
case: "redacts authorization bearer token with case insensitivity",
message: '-H "authorizAtion: beaRer ab123456789a1abcd1~_.-+456ABCDE=" -H "Content-Type: application/json"',
expected_message: '-H "[REDACTED]" -H "Content-Type: application/json"'
}
].each do |test|
it "redacts #{test[:case]}" do
Expand Down