Skip to content
Closed
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
22 changes: 22 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 @@ -79,4 +79,26 @@ describe('sanitizeURL', () => {
'https://example.com/?access_token=****&refresh_token=****&device_code=****&subject_token=****&other=keep',
)
})

test('sanitizes URL credentials', () => {
// Given
const url = 'https://user:pass@example.com'

// When
const sanitizedUrl = sanitizeURL(url)

// Then
expect(sanitizedUrl).toBe('https://****:****@example.com/')
})

test('sanitizes case-insensitive query parameters', () => {
// Given
const url = 'https://example.com?TOKEN=secret&Access_Token=hidden'

// When
const sanitizedUrl = sanitizeURL(url)

// Then
expect(sanitizedUrl).toBe('https://example.com/?TOKEN=****&Access_Token=****')
})
})
15 changes: 12 additions & 3 deletions packages/cli-kit/src/private/node/api/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ const SENSITIVE_QUERY_PARAMS = [
*/
export function sanitizeURL(url: string): string {
const parsedUrl = new URL(url)
for (const param of SENSITIVE_QUERY_PARAMS) {
if (parsedUrl.searchParams.has(param)) {
parsedUrl.searchParams.set(param, '****')

if (parsedUrl.username) {
parsedUrl.username = '****'
}
if (parsedUrl.password) {
parsedUrl.password = '****'
}

for (const [key] of parsedUrl.searchParams) {
if (SENSITIVE_QUERY_PARAMS.includes(key.toLowerCase())) {
parsedUrl.searchParams.set(key, '****')
}
}

return parsedUrl.toString()
}
Loading