Skip to content
Snippets Groups Projects
Unverified Commit 50f1e291 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

feat: do not mask secrets templates (#31240)

parent ff875962
No related branches found
Tags 38.69.0
No related merge requests found
...@@ -53,6 +53,34 @@ describe('logger/utils', () => { ...@@ -53,6 +53,34 @@ describe('logger/utils', () => {
expect(sanitizeValue(input)).toBe(output); expect(sanitizeValue(input)).toBe(output);
}); });
it('preserves secret template strings in redacted fields', () => {
const input = {
normal: 'value',
token: '{{ secrets.MY_SECRET }}',
password: '{{secrets.ANOTHER_SECRET}}',
content: '{{ secrets.CONTENT_SECRET }}',
npmToken: '{{ secrets.NPM_TOKEN }}',
forkToken: 'some-token',
nested: {
authorization: '{{ secrets.NESTED_SECRET }}',
password: 'some-password',
},
};
const expected = {
normal: 'value',
token: '{{ secrets.MY_SECRET }}',
password: '{{secrets.ANOTHER_SECRET}}',
content: '[content]',
npmToken: '{{ secrets.NPM_TOKEN }}',
forkToken: '***********',
nested: {
authorization: '{{ secrets.NESTED_SECRET }}',
password: '***********',
},
};
expect(sanitizeValue(input)).toEqual(expected);
});
describe('prepareError', () => { describe('prepareError', () => {
function getError<T extends z.ZodType>( function getError<T extends z.ZodType>(
schema: T, schema: T,
......
...@@ -4,6 +4,7 @@ import bunyan from 'bunyan'; ...@@ -4,6 +4,7 @@ import bunyan from 'bunyan';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { RequestError as HttpError } from 'got'; import { RequestError as HttpError } from 'got';
import { ZodError } from 'zod'; import { ZodError } from 'zod';
import { regEx } from '../util/regex';
import { redactedFields, sanitize } from '../util/sanitize'; import { redactedFields, sanitize } from '../util/sanitize';
import type { BunyanRecord, BunyanStream } from './types'; import type { BunyanRecord, BunyanStream } from './types';
...@@ -214,7 +215,12 @@ export function sanitizeValue( ...@@ -214,7 +215,12 @@ export function sanitizeValue(
if (!val) { if (!val) {
curValue = val; curValue = val;
} else if (redactedFields.includes(key)) { } else if (redactedFields.includes(key)) {
curValue = '***********'; // Do not mask/sanitize secrets templates
if (is.string(val) && regEx(/^{{\s*secrets\..*}}$/).test(val)) {
curValue = val;
} else {
curValue = '***********';
}
} else if (contentFields.includes(key)) { } else if (contentFields.includes(key)) {
curValue = '[content]'; curValue = '[content]';
} else if (key === 'secrets') { } else if (key === 'secrets') {
......
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