Skip to content
Draft
Changes from all 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
11 changes: 8 additions & 3 deletions packages/cli-kit/src/private/node/api/headers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CLI_KIT_VERSION} from '../../../public/common/version.js'
import {firstPartyDev} from '../../../public/node/context/local.js'
import {firstPartyDev, isUnitTest, isVerbose} from '../../../public/node/context/local.js'
import {AbortError} from '../../../public/node/error.js'
import https from 'https'

Expand All @@ -26,16 +26,21 @@ export class GraphQLClientError extends RequestClientError {
}
}

const SENSITIVE_HEADERS = ['token', 'authorization', 'subject_token', 'cookie']

/**
* Removes the sensitive data from the headers and outputs them as a string.
* @param headers - HTTP headers.
* @returns A sanitized version of the headers as a string.
*/
export function sanitizedHeadersOutput(headers: Record<string, string>): string {
if (!isVerbose() && !isUnitTest()) {
return ''
}

const sanitized: Record<string, string> = {}
const keywords = ['token', 'authorization', 'subject_token', 'cookie']
Object.keys(headers).forEach((header) => {
if (keywords.find((keyword) => header.toLowerCase().includes(keyword)) === undefined) {
if (SENSITIVE_HEADERS.find((keyword) => header.toLowerCase().includes(keyword)) === undefined) {
sanitized[header] = headers[header]!
}
})
Expand Down
Loading