File tree Expand file tree Collapse file tree 3 files changed +47
-78
lines changed Expand file tree Collapse file tree 3 files changed +47
-78
lines changed Original file line number Diff line number Diff line change @@ -16,45 +16,7 @@ import type { RequestOptions as HttpsRequestOptions } from 'node:https'
1616/**
1717 * Array of sensitive header names that should be redacted in logs
1818 */
19- const SENSITIVE_HEADERS = [
20- 'authorization' ,
21- 'cookie' ,
22- 'set-cookie' ,
23- 'proxy-authorization' ,
24- 'www-authenticate' ,
25- 'proxy-authenticate' ,
26- ]
27-
28- /**
29- * Sanitize headers for logging by redacting sensitive values.
30- */
31- function sanitizeHeaders (
32- headers : Record < string , unknown > | readonly string [ ] | undefined ,
33- ) : Record < string , string > | undefined {
34- if ( ! headers ) {
35- return undefined
36- }
37-
38- // Handle readonly string[] case - this shouldn't normally happen for headers
39- if ( Array . isArray ( headers ) ) {
40- return { headers : headers . join ( ', ' ) }
41- }
42-
43- const sanitized : Record < string , string > = { }
44-
45- // Plain object iteration works for both HeadersRecord and IncomingHttpHeaders
46- for ( const [ key , value ] of Object . entries ( headers ) ) {
47- const keyLower = key . toLowerCase ( )
48- if ( SENSITIVE_HEADERS . includes ( keyLower ) ) {
49- sanitized [ key ] = '[REDACTED]'
50- } else {
51- // Handle both string and string[] values
52- sanitized [ key ] = Array . isArray ( value ) ? value . join ( ', ' ) : String ( value )
53- }
54- }
55-
56- return sanitized
57- }
19+ import { sanitizeHeaders } from './utils/header-sanitization'
5820
5921/**
6022 * Create multipart form-data body parts for file uploads.
Original file line number Diff line number Diff line change @@ -24,45 +24,7 @@ import type { ClientRequest, IncomingMessage } from 'node:http'
2424/**
2525 * Array of sensitive header names that should be redacted in logs
2626 */
27- const SENSITIVE_HEADERS = [
28- 'authorization' ,
29- 'cookie' ,
30- 'set-cookie' ,
31- 'proxy-authorization' ,
32- 'www-authenticate' ,
33- 'proxy-authenticate' ,
34- ]
35-
36- /**
37- * Sanitize headers for logging by redacting sensitive values.
38- */
39- function sanitizeHeaders (
40- headers : Record < string , unknown > | readonly string [ ] | undefined ,
41- ) : Record < string , string > | undefined {
42- if ( ! headers ) {
43- return undefined
44- }
45-
46- // Handle readonly string[] case - this shouldn't normally happen for headers
47- if ( Array . isArray ( headers ) ) {
48- return { headers : headers . join ( ', ' ) }
49- }
50-
51- const sanitized : Record < string , string > = { }
52-
53- // Plain object iteration works for both HeadersRecord and IncomingHttpHeaders
54- for ( const [ key , value ] of Object . entries ( headers ) ) {
55- const keyLower = key . toLowerCase ( )
56- if ( SENSITIVE_HEADERS . includes ( keyLower ) ) {
57- sanitized [ key ] = '[REDACTED]'
58- } else {
59- // Handle both string and string[] values
60- sanitized [ key ] = Array . isArray ( value ) ? value . join ( ', ' ) : String ( value )
61- }
62- }
63-
64- return sanitized
65- }
27+ import { sanitizeHeaders } from './utils/header-sanitization'
6628
6729/**
6830 * HTTP response error for Socket API requests.
Original file line number Diff line number Diff line change 1+ /**
2+ * List of sensitive HTTP headers that should be redacted in logs.
3+ */
4+ export const SENSITIVE_HEADERS : readonly string [ ] = [
5+ 'authorization' ,
6+ 'cookie' ,
7+ 'set-cookie' ,
8+ 'proxy-authorization' ,
9+ 'www-authenticate' ,
10+ 'proxy-authenticate' ,
11+ ]
12+
13+ /**
14+ * Sanitize headers for logging by redacting sensitive values.
15+ *
16+ * @param headers - Headers to sanitize (object or array)
17+ * @returns Sanitized headers with sensitive values redacted
18+ */
19+ export function sanitizeHeaders (
20+ headers : Record < string , unknown > | readonly string [ ] | undefined ,
21+ ) : Record < string , string > | undefined {
22+ if ( ! headers ) {
23+ return undefined
24+ }
25+
26+ // Handle readonly string[] case - this shouldn't normally happen for headers.
27+ if ( Array . isArray ( headers ) ) {
28+ return { headers : headers . join ( ', ' ) }
29+ }
30+
31+ const sanitized : Record < string , string > = { }
32+
33+ // Plain object iteration works for both HeadersRecord and IncomingHttpHeaders.
34+ for ( const [ key , value ] of Object . entries ( headers ) ) {
35+ const keyLower = key . toLowerCase ( )
36+ if ( SENSITIVE_HEADERS . includes ( keyLower ) ) {
37+ sanitized [ key ] = '[REDACTED]'
38+ } else {
39+ // Handle both string and string[] values.
40+ sanitized [ key ] = Array . isArray ( value ) ? value . join ( ', ' ) : String ( value )
41+ }
42+ }
43+
44+ return sanitized
45+ }
You can’t perform that action at this time.
0 commit comments