-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhook status): redact authorization headers in webhook logs
- Loading branch information
Showing
5 changed files
with
74 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module PactBroker | ||
module Webhooks | ||
class RedactLogs | ||
def self.call logs | ||
logs.gsub(/(Authorization: )(.*)/i,'\1[REDACTED]') | ||
.gsub(/(Token: )(.*)/i,'\1[REDACTED]') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'pact_broker/webhooks/redact_logs' | ||
|
||
module PactBroker | ||
module Webhooks | ||
describe RedactLogs do | ||
describe ".call" do | ||
let(:string) do | ||
"Authorization: foo\nX-Thing: bar" | ||
end | ||
|
||
let(:x_auth_string) do | ||
"X-Authorization: bar foo\nX-Thing: bar" | ||
end | ||
|
||
let(:x_auth_token) do | ||
"X-Auth-Token: bar foo\nX-Thing: bar" | ||
end | ||
|
||
let(:x_authorization_token) do | ||
"X-Authorization-Token: bar foo\nX-Thing: bar" | ||
end | ||
|
||
let(:string_lower) do | ||
"authorization: foo\nX-Thing: bar" | ||
end | ||
|
||
it "hides the value of the Authorization header" do | ||
expect(RedactLogs.call(string)).to eq "Authorization: [REDACTED]\nX-Thing: bar" | ||
end | ||
|
||
it "hides the value of the X-Authorization header" do | ||
expect(RedactLogs.call(x_auth_string)).to eq "X-Authorization: [REDACTED]\nX-Thing: bar" | ||
end | ||
|
||
it "hides the value of the X-Auth-Token header" do | ||
expect(RedactLogs.call(x_auth_token)).to eq "X-Auth-Token: [REDACTED]\nX-Thing: bar" | ||
end | ||
|
||
it "hides the value of the X-Authorization-Token header" do | ||
expect(RedactLogs.call(x_authorization_token)).to eq "X-Authorization-Token: [REDACTED]\nX-Thing: bar" | ||
end | ||
|
||
it "hides the value of the authorization header" do | ||
expect(RedactLogs.call(string_lower)).to eq "authorization: [REDACTED]\nX-Thing: bar" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters