Repository navigation
Commit 5b04bef
committed
Improve logger data sanitization to support recursive handling and circular references
- Please refactor the `sanitize_data` function in `packages/shared/src/utils/logger.ts` to fix multiple API key leak vulnerabilities. Currently, it only checks top-level Axios errors, misses the raw `request._header` string, fails on nested errors (like `{ data: error }`), and doesn't redact Anthropic's `x-api-key`. Implement a robust recursive sanitization function with the following requirements: 1. **Recursive Deep Clone:** Traverse objects recursively so nested errors (e.g., `{ parse_error: error }`) are caught. 2. **Circular Reference Protection:** Use a `WeakSet` to prevent `Maximum call stack size exceeded` errors, as Axios error objects contain highly nested circular references (e.g., `request.res.req`). 3. **Key-based Redaction:** If an object key is `authorization` or `x-api-key` (case-insensitive), replace its value with `'[REDACTED]'`. 4. **String Regex Redaction:** If a value is a string (specifically to catch the raw HTTP string in `request._header`), run a regex replace...
├── apps
│ └── editor
│ └── src
│ ├── services
│ │ ├── model-fetcher.ts
│ │ └── prompt-view-api-calls-manager.ts
│ └── utils
│ ├── build-request-headers.ts
│ └── send-llm-message.ts
└── packages
└── shared
├── package.json
└── src
└── utils
└── logger.ts1 parent 1b5d8e7 commit 5b04bef
1 file changed
Lines changed: 30 additions & 36 deletions
File tree
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 13 | + | |
26 | 14 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
41 | 23 | | |
42 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
43 | 37 | | |
44 | 38 | | |
45 | | - | |
| 39 | + | |
46 | 40 | | |
47 | 41 | | |
48 | 42 | | |
| |||
0 commit comments