Skip to content
Draft
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions packages/cli-kit/src/private/node/api/urls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('sanitizeURL', () => {
'client_secret',
'code',
'token',
'password',
'code_verifier',
'client_assertion',
'assertion',
'auth_token',
])('sanitizes %s query parameter', (param) => {
// Given
const url = `https://example.com?${param}=secret-value`
Expand All @@ -79,4 +84,26 @@ describe('sanitizeURL', () => {
'https://example.com/?access_token=****&refresh_token=****&device_code=****&subject_token=****&other=keep',
)
})

test('redacts password from URL authority', () => {
// Given
const url = 'https://user:password123@example.com/path'

// When
const sanitizedUrl = sanitizeURL(url)

// Then
expect(sanitizedUrl).toBe('https://user:****@example.com/path')
})
Comment thread
gonzaloriestra marked this conversation as resolved.

test('redacts both password and sensitive query parameters', () => {
// Given
const url = 'https://user:secret@example.com/path?access_token=tok&other=keep'

// When
const sanitizedUrl = sanitizeURL(url)

// Then
expect(sanitizedUrl).toBe('https://user:****@example.com/path?access_token=****&other=keep')
})
})
10 changes: 9 additions & 1 deletion packages/cli-kit/src/private/node/api/urls.ts
Comment thread
gonzaloriestra marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ const SENSITIVE_QUERY_PARAMS = [
'client_secret',
'code',
'token',
'password',
'code_verifier',
'client_assertion',
'assertion',
'auth_token',
]

/**
* Removes the sensitive data from the url and outputs them as a string.
* @param url - HTTP headers.
* @param url - The URL to sanitize.
* @returns A sanitized version of the url as a string.
*/
export function sanitizeURL(url: string): string {
Expand All @@ -26,5 +31,8 @@ export function sanitizeURL(url: string): string {
parsedUrl.searchParams.set(param, '****')
}
}
if (parsedUrl.password) {
parsedUrl.password = '****'
}
return parsedUrl.toString()
}
Loading