Skip to content

Commit 45c44bd

Browse files
[Security] Redact cookies from debug logs
Add 'cookie' to the list of redacted keywords in `sanitizedHeadersOutput` to prevent session data leakage in debug logs. Update tests to verify redaction.
1 parent ab07b6a commit 45c44bd

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

packages/cli-kit/src/private/node/api/headers.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('common API methods', () => {
7676
},
7777
)
7878

79-
test('sanitizedHeadersOutput removes the headers that include the token', () => {
79+
test('sanitizedHeadersOutput removes sensitive headers', () => {
8080
// Given
8181
const headers = {
8282
'User-Agent': 'useragent',
@@ -85,6 +85,8 @@ describe('common API methods', () => {
8585
authorization: 'token',
8686
'Content-Type': 'application/json',
8787
'X-Shopify-Access-Token': 'token',
88+
Cookie: 'session=123',
89+
'Set-Cookie': 'session=456',
8890
}
8991

9092
// When

packages/cli-kit/src/private/node/api/headers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class GraphQLClientError extends RequestClientError {
3333
*/
3434
export function sanitizedHeadersOutput(headers: Record<string, string>): string {
3535
const sanitized: Record<string, string> = {}
36-
const keywords = ['token', 'authorization', 'subject_token']
36+
const keywords = ['token', 'authorization', 'subject_token', 'cookie']
3737
Object.keys(headers).forEach((header) => {
3838
if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {
3939
sanitized[header] = headers[header]!

0 commit comments

Comments
 (0)