Redact query parameter values in URLs where the param name matches sensitiveKeys.
(value: string, sensitiveKeysLower: Set<string>)
| 372 | |
| 373 | /** Redact query parameter values in URLs where the param name matches sensitiveKeys. */ |
| 374 | function redactUrlQueryParams(value: string, sensitiveKeysLower: Set<string>): string { |
| 375 | const qIndex = value.indexOf("?") |
| 376 | if (qIndex === -1) return value |
| 377 | |
| 378 | const base = value.slice(0, qIndex + 1) |
| 379 | const queryString = value.slice(qIndex + 1) |
| 380 | |
| 381 | // Handle fragment after query string |
| 382 | const hashIndex = queryString.indexOf("#") |
| 383 | const qs = hashIndex === -1 ? queryString : queryString.slice(0, hashIndex) |
| 384 | const fragment = hashIndex === -1 ? "" : queryString.slice(hashIndex) |
| 385 | |
| 386 | const redactedParams = qs.split("&").map((param) => { |
| 387 | const eqIndex = param.indexOf("=") |
| 388 | if (eqIndex === -1) return param |
| 389 | const name = param.slice(0, eqIndex) |
| 390 | if (sensitiveKeysLower.has(name.toLowerCase())) { |
| 391 | return `${name}=${REDACTED}` |
| 392 | } |
| 393 | return param |
| 394 | }).join("&") |
| 395 | |
| 396 | return base + redactedParams + fragment |
| 397 | } |
| 398 | |
| 399 | function matchesStatePath(currentPath: string, patterns: string[]): boolean { |
| 400 | for (const pattern of patterns) { |