|
1 | 1 | import fastRedact from 'fast-redact'; |
2 | 2 |
|
3 | | -export const redactionFields = { |
4 | | - 'cookie': 'cookie', |
5 | | - 'x-auth-token': '["x-auth-token"]', |
6 | | - 'authorization': 'authorization', |
7 | | - 'access_token': 'access_token', |
8 | | - 'customFields': 'customFields.*', |
9 | | - 'emails': 'emails[*].address', |
10 | | - 'email': 'email', |
11 | | - 'password': 'password', |
12 | | - 'pass': 'pass', |
13 | | -}; |
| 3 | +const requestFields = [ |
| 4 | + 'Cookie', |
| 5 | + 'cookie', |
| 6 | + '["x-auth-token"]', |
| 7 | + '["X-Auth-Token"]', |
| 8 | + 'auth', |
| 9 | + 'Auth', |
| 10 | + 'authorization', |
| 11 | + 'Authorization', |
| 12 | + 'access_token', |
| 13 | +]; |
14 | 14 |
|
15 | | -const redactor = fastRedact({ |
16 | | - paths: Object.values(redactionFields), |
17 | | - serialize: false, |
18 | | - strict: false, |
19 | | -}); |
20 | | - |
21 | | -export function redact(value: unknown): void { |
22 | | - if (!value || typeof value !== 'object') return; |
| 15 | +const entityFields = ['password', 'pass', 'customFields.*', '_unmappedProperties_']; |
23 | 16 |
|
24 | | - if (Array.isArray(value)) { |
25 | | - return value.forEach(redact); |
26 | | - } |
| 17 | +const roomFields = ['customFields.*', '_unmappedProperties_', ...entityFields.map((field) => `creator.${field}`)]; |
27 | 18 |
|
28 | | - redactor(value); |
| 19 | +export const redactionFieldPaths = [ |
| 20 | + ...requestFields, |
| 21 | + ...entityFields, |
| 22 | + // Fields in debug logging |
| 23 | + 'info.query.query', // The deprecated `query` search param |
| 24 | + ...requestFields.map((field) => `info.query${field.startsWith('[') ? field : `.${field}`}`), |
| 25 | + ...requestFields.map((field) => `info.headers${field.startsWith('[') ? field : `.${field}`}`), |
| 26 | + ...requestFields.map((field) => `info.content${field.startsWith('[') ? field : `.${field}`}`), |
| 27 | + ...requestFields.map((field) => `info.data${field.startsWith('[') ? field : `.${field}`}`), |
| 28 | + // Incoming requests to the Apps API endpoints |
| 29 | + 'query.query', // The deprecated `query` search param |
| 30 | + ...requestFields.map((field) => `query${field.startsWith('[') ? field : `.${field}`}`), |
| 31 | + ...requestFields.map((field) => `headers${field.startsWith('[') ? field : `.${field}`}`), |
| 32 | + ...requestFields.map((field) => `content${field.startsWith('[') ? field : `.${field}`}`), |
| 33 | + ...entityFields.map((field) => `user.${field}`), |
| 34 | + // Slashcommands |
| 35 | + ...roomFields.map((field) => `params[0].room.${field}`), |
| 36 | + ...entityFields.map((field) => `params[0].sender.${field}`), |
| 37 | +]; |
29 | 38 |
|
30 | | - Object.entries(value).forEach(([key, val]) => { |
31 | | - // Don't recurse into properties that have already been redacted |
32 | | - if (!(key in redactionFields)) { |
33 | | - redact(val); |
34 | | - } |
35 | | - }); |
36 | | -} |
| 39 | +export const redact = fastRedact({ |
| 40 | + paths: redactionFieldPaths, |
| 41 | + censor: '[Redacted]', |
| 42 | + serialize: false, |
| 43 | + strict: false, |
| 44 | +}); |
0 commit comments