Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding support for data uri sanitisation #31721

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:**redacted**'}
${'user@domain.com'} | ${'user@domain.com'}
`('sanitizeValue("$input") == "$output"', ({ input, output }) => {
expect(sanitizeValue(input)).toBe(output);
Expand Down
11 changes: 10 additions & 1 deletion lib/logger/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,18 @@ 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;
sahil-seth marked this conversation as resolved.
Show resolved Hide resolved

export function sanitizeUrls(text: string): string {
return text.replace(urlRe, (url) => {
let sanitizedText = text.replace(urlRe, (url) => {
sahil-seth marked this conversation as resolved.
Show resolved Hide resolved
return url.replace(urlCredRe, '//**redacted**@');
});

// Check for data URIs
if (sanitizedText.startsWith('data:')) {
sanitizedText = sanitizedText.replace(dataUriCredRe, (dataUri) => {
return 'data:**redacted**';
});
}
return sanitizedText;
sahil-seth marked this conversation as resolved.
Show resolved Hide resolved
}