-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Add hashing of sensitive data to the Ruby gem (#952)
| 🚥 Resolves CX-674 | | :------------------- | ## 🧰 Changes Masks the `Authorization` header and API keys sent via the Ruby Rack middleware. ## 🧬 QA & Testing Added automated tests to verify the sensitive data gets hashed properly and matches the same expected output as the Node.js app --------- Co-authored-by: Kenny Hoxworth <[email protected]>
- Loading branch information
Showing
6 changed files
with
64 additions
and
4 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
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,11 @@ | ||
require 'digest' | ||
|
||
module Readme | ||
class Mask | ||
def self.mask(data) | ||
digest = Digest::SHA2.new(512).base64digest(data) | ||
opts = data.length >= 4 ? data[-4,4] : data | ||
"sha512-#{digest}?#{opts}" | ||
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require 'readme/payload' | ||
require 'readme/mask' | ||
require 'socket' | ||
require 'json' | ||
require 'securerandom' | ||
|
||
har_json = File.read(File.expand_path('../../fixtures/har.json', __FILE__)) | ||
|
@@ -9,24 +11,28 @@ | |
let(:ip_address) { Socket.ip_address_list.detect(&:ipv4_private?).ip_address } | ||
|
||
it 'returns JSON matching the payload schema' do | ||
id = '1' | ||
result = described_class.new( | ||
har, | ||
{ id: '1', label: 'Owlbert', email: '[email protected]' }, | ||
{ id: id, label: 'Owlbert', email: '[email protected]' }, | ||
ip_address, | ||
development: true | ||
) | ||
|
||
expect(JSON.parse(result.to_json)["group"]["id"]).to match(Readme::Mask.mask(id)) | ||
expect(result.to_json).to match_json_schema('payload') | ||
end | ||
|
||
it 'substitutes api_key for id' do | ||
api_key = '1' | ||
result = described_class.new( | ||
har, | ||
{ api_key: '1', label: 'Owlbert', email: '[email protected]' }, | ||
{ api_key: api_key, label: 'Owlbert', email: '[email protected]' }, | ||
ip_address, | ||
development: true | ||
) | ||
|
||
expect(JSON.parse(result.to_json)["group"]["id"]).to match(Readme::Mask.mask(api_key)) | ||
expect(result.to_json).to match_json_schema('payload') | ||
end | ||
|
||
|