Skip to content

Commit

Permalink
feat: adding support for data uri sanitisation (#31721)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
sahil-seth and viceice authored Oct 8, 2024
1 parent 05accc8 commit dbd69e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/logger/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('logger/utils', () => {
${'redis://:somepw@172.32.11.71:6379/0'} | ${'redis://**redacted**@172.32.11.71:6379/0'}
${'some text with\r\n url: https://somepw@domain.com\nand some more'} | ${'some text with\r\n url: https://**redacted**@domain.com\nand some more'}
${'[git://domain.com](git://pw@domain.com)'} | ${'[git://domain.com](git://**redacted**@domain.com)'}
${'data:text/vnd-example;foo=bar;base64,R0lGODdh'} | ${'data:text/vnd-example;**redacted**'}
${'user@domain.com'} | ${'user@domain.com'}
`('sanitizeValue("$input") == "$output"', ({ input, output }) => {
expect(sanitizeValue(input)).toBe(output);
Expand Down
9 changes: 6 additions & 3 deletions lib/logger/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,12 @@ export function validateLogLevel(
// Can't use `util/regex` because of circular reference to logger
const urlRe = /[a-z]{3,9}:\/\/[^@/]+@[a-z0-9.-]+/gi;
const urlCredRe = /\/\/[^@]+@/g;
const dataUriCredRe = /^(data:[0-9a-z-]+\/[0-9a-z-]+;).+/i;

export function sanitizeUrls(text: string): string {
return text.replace(urlRe, (url) => {
return url.replace(urlCredRe, '//**redacted**@');
});
return text
.replace(urlRe, (url) => {
return url.replace(urlCredRe, '//**redacted**@');
})
.replace(dataUriCredRe, '$1**redacted**');
}

0 comments on commit dbd69e9

Please sign in to comment.