Skip to content

Commit

Permalink
Fix to show request headers in Action's Tester UI (segmentio#2067)
Browse files Browse the repository at this point in the history
* add test destination

* add request body

* convert req headers to js object

* remove test dest

* add filtering for sensitive headers
  • Loading branch information
tcgilbert authored Jun 4, 2024
1 parent 5887a12 commit dbec70c
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/cli/src/lib/summarize-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Exchange {

export interface RequestToDestination {
url: string
headers: Headers
headers: { [key: string]: string } // JSON.strigify() does not work for request headers
method: string
body: unknown
}
Expand Down Expand Up @@ -36,10 +36,42 @@ async function summarizeRequest(response: Response): Promise<RequestToDestinatio
const request = response.request.clone()
const data = await request.text()

// List of headers that may contain sensitive information
const sensitiveHeaders = [
'authorization',
'proxy-authorization',
'cookie',
'set-cookie',
'www-authenticate',
'proxy-authenticate',
'x-csrf-token',
'x-xsrf-token',
'x-api-key',
'x-client-id',
'x-uid',
'x-requested-with',
'x-forwarded-for',
'x-real-ip',
'x-amz-security-token',
'x-amz-content-sha256',
'x-amz-date',
'x-amz-user-agent'
]

// Convert headers to plain JavaScript object and redact sensitive headers
const headersObject: { [key: string]: string } = {}
request.headers.forEach((value, key) => {
if (sensitiveHeaders.includes(key.toLowerCase())) {
headersObject[key] = '<redacted>'
} else {
headersObject[key] = value
}
})

return {
url: request.url,
method: request.method,
headers: request.headers,
headers: headersObject,
body: data ?? ''
}
}
Expand Down

0 comments on commit dbec70c

Please sign in to comment.