Skip to content
Snippets Groups Projects
Unverified Commit dbd69e9a authored by sahil-seth's avatar sahil-seth Committed by GitHub
Browse files

feat: adding support for data uri sanitisation (#31721)

parent 05accc8f
No related branches found
Tags 38.111.0
No related merge requests found
......@@ -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);
......
......@@ -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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment