Skip to content

Commit

Permalink
fix(redact): redact emails inside strings MONGOSH-1392 (#404)
Browse files Browse the repository at this point in the history
* fix(redact): redact emails inside strings MONGOSH-1392

* refactor: combine rules
  • Loading branch information
alenakhineika authored Jul 11, 2024
1 parent 6f9e6b5 commit be8a9b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/mongodb-redact/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ describe('mongodb-redact', function () {
expect(redact('[email protected]')).to.equal('<email>');
});

it('should redact emails inside strings', function () {
expect(
redact(
'"db.test.insert({ email: "[email protected]" })"'
)
).to.equal('"db.test.insert({ email: "<email>" })"');
});

it('should redact ip addresses', function () {
expect(redact('10.0.0.1')).to.equal('<ip address>');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/mongodb-redact/src/regexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const regexes = [

// Email addresses
[
/(^|[ \t\r\n\v\f])([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,500})/gim,
'$1<email>',
/(^|[ \t\r\n\v\f"'`])([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(["'`]?)){1,500})/gim,
'$1<email>$6',
],

// IP addresses
Expand Down

0 comments on commit be8a9b7

Please sign in to comment.