mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
fix: sanitize base64 of all secrets (#14423)
This commit is contained in:
parent
1151f08d9a
commit
69c9c98cd6
2 changed files with 21 additions and 1 deletions
|
@ -11,6 +11,7 @@ describe('util/sanitize', () => {
|
|||
});
|
||||
|
||||
it('sanitizes empty string', () => {
|
||||
addSecretForSanitizing('');
|
||||
expect(sanitize(null as never)).toBeNull();
|
||||
expect(sanitize('')).toBe('');
|
||||
});
|
||||
|
@ -32,4 +33,10 @@ describe('util/sanitize', () => {
|
|||
const outputX2 = [output, output].join('\n');
|
||||
expect(sanitize(inputX2)).toBe(outputX2);
|
||||
});
|
||||
it('sanitizes github app tokens', () => {
|
||||
addSecretForSanitizing('x-access-token:abc123');
|
||||
expect(sanitize(`hello ${toBase64('abc123')} world`)).toBe(
|
||||
'hello **redacted** world'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import is from '@sindresorhus/is';
|
||||
import { toBase64 } from './string';
|
||||
|
||||
const secrets = new Set<string>();
|
||||
|
||||
export const redactedFields = [
|
||||
|
@ -26,9 +29,19 @@ export function sanitize(input: string): string {
|
|||
return output;
|
||||
}
|
||||
|
||||
const GITHUB_APP_TOKEN_PREFIX = 'x-access-token:';
|
||||
|
||||
export function addSecretForSanitizing(secret: string): void {
|
||||
if (!is.nonEmptyString(secret)) {
|
||||
return;
|
||||
}
|
||||
secrets.add(secret);
|
||||
secrets.add(secret?.replace('x-access-token:', '')); // GitHub App tokens
|
||||
secrets.add(toBase64(secret));
|
||||
if (secret.startsWith(GITHUB_APP_TOKEN_PREFIX)) {
|
||||
const trimmedSecret = secret.replace(GITHUB_APP_TOKEN_PREFIX, '');
|
||||
secrets.add(trimmedSecret);
|
||||
secrets.add(toBase64(trimmedSecret));
|
||||
}
|
||||
}
|
||||
|
||||
export function clearSanitizedSecretsList(): void {
|
||||
|
|
Loading…
Reference in a new issue