aegis-bridge 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/channels/webhook.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { webhookEndpointSchema, getErrorMessage } from '../validation.js';
|
|
8
8
|
import { validateWebhookUrl } from '../ssrf.js';
|
|
9
|
+
import { redactSecretsFromText } from '../utils/redact-headers.js';
|
|
9
10
|
export class WebhookChannel {
|
|
10
11
|
name = 'webhook';
|
|
11
12
|
endpoints;
|
|
@@ -124,7 +125,7 @@ export class WebhookChannel {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
catch (e) {
|
|
127
|
-
lastError = getErrorMessage(e);
|
|
128
|
+
lastError = redactSecretsFromText(getErrorMessage(e), ep.headers);
|
|
128
129
|
if (attempt < maxRetries) {
|
|
129
130
|
const delay = WebhookChannel.backoff(attempt);
|
|
130
131
|
console.warn(`Webhook ${ep.url} error for ${event} (attempt ${attempt}/${maxRetries}): ${lastError}, retrying in ${Math.round(delay)}ms`);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact-headers.ts — Redact sensitive header values for safe logging.
|
|
3
|
+
*
|
|
4
|
+
* Issue #582: Prevent webhook custom headers (Authorization, Cookie, etc.)
|
|
5
|
+
* from leaking into error logs on delivery failures.
|
|
6
|
+
*/
|
|
7
|
+
/** Return a copy of `headers` with sensitive values replaced. */
|
|
8
|
+
export declare function redactHeaders(headers: Record<string, string>): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Scrub any sensitive header *values* from arbitrary text.
|
|
11
|
+
* If a fetch error message happens to include a header value, this removes it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function redactSecretsFromText(text: string, headers: Record<string, string> | undefined): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact-headers.ts — Redact sensitive header values for safe logging.
|
|
3
|
+
*
|
|
4
|
+
* Issue #582: Prevent webhook custom headers (Authorization, Cookie, etc.)
|
|
5
|
+
* from leaking into error logs on delivery failures.
|
|
6
|
+
*/
|
|
7
|
+
/** Header names whose values should be treated as secrets. Case-insensitive. */
|
|
8
|
+
const SENSITIVE_HEADER_NAMES = new Set([
|
|
9
|
+
'authorization',
|
|
10
|
+
'cookie',
|
|
11
|
+
'set-cookie',
|
|
12
|
+
'x-api-key',
|
|
13
|
+
'x-auth-token',
|
|
14
|
+
'api-key',
|
|
15
|
+
'apikey',
|
|
16
|
+
'proxy-authorization',
|
|
17
|
+
'x-csrf-token',
|
|
18
|
+
'www-authenticate',
|
|
19
|
+
'proxy-authenticate',
|
|
20
|
+
]);
|
|
21
|
+
function isSensitive(headerName) {
|
|
22
|
+
return SENSITIVE_HEADER_NAMES.has(headerName.toLowerCase());
|
|
23
|
+
}
|
|
24
|
+
function redactValue(value) {
|
|
25
|
+
if (value.length <= 8)
|
|
26
|
+
return '[REDACTED]';
|
|
27
|
+
return `${value.slice(0, 4)}...[REDACTED]`;
|
|
28
|
+
}
|
|
29
|
+
/** Return a copy of `headers` with sensitive values replaced. */
|
|
30
|
+
export function redactHeaders(headers) {
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
33
|
+
result[name] = isSensitive(name) ? redactValue(value) : value;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Scrub any sensitive header *values* from arbitrary text.
|
|
39
|
+
* If a fetch error message happens to include a header value, this removes it.
|
|
40
|
+
*/
|
|
41
|
+
export function redactSecretsFromText(text, headers) {
|
|
42
|
+
if (!headers)
|
|
43
|
+
return text;
|
|
44
|
+
let result = text;
|
|
45
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
46
|
+
if (!isSensitive(name) || !value)
|
|
47
|
+
continue;
|
|
48
|
+
// Skip very short values — too many false positives
|
|
49
|
+
if (value.length < 4)
|
|
50
|
+
continue;
|
|
51
|
+
result = result.replaceAll(value, '[REDACTED]');
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=redact-headers.js.map
|