@checkstack/notification-discord-backend 0.2.12 → 0.2.14
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/CHANGELOG.md +32 -0
- package/package.json +4 -4
- package/src/index.test.ts +63 -27
- package/src/index.ts +22 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @checkstack/notification-discord-backend
|
|
2
2
|
|
|
3
|
+
## 0.2.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b946952: Close the DNS-rebind window on notification delivery to user-supplied URLs.
|
|
8
|
+
|
|
9
|
+
The Webhook, Discord, Slack, Gotify, and Backstage channels now deliver through the new `createWebhookFetch` helper (exported from `@checkstack/notification-backend`), built on the platform guarded fetch: the host is resolved once, validated against the same webhook egress denylist as `validateWebhookUrl`, and the connection is pinned to exactly the validated IP. A short-TTL name can no longer pass the pre-flight with a public address and then connect to loopback or the cloud-metadata endpoint. Any 3xx response still fails the delivery closed instead of being followed.
|
|
10
|
+
|
|
11
|
+
`postJson` accepts a new optional `fetchImpl`, and each of these strategies is now built by a factory that takes an optional `egress` seam (`lookupFn` / `fetchImpl`) so tests no longer need real DNS. No configuration change is required; deliveries through an `HTTP(S)_PROXY` keep using the proxy as before.
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [b946952]
|
|
14
|
+
- Updated dependencies [adeafe0]
|
|
15
|
+
- Updated dependencies [b946952]
|
|
16
|
+
- Updated dependencies [b946952]
|
|
17
|
+
- Updated dependencies [adeafe0]
|
|
18
|
+
- Updated dependencies [b946952]
|
|
19
|
+
- Updated dependencies [b946952]
|
|
20
|
+
- Updated dependencies [b946952]
|
|
21
|
+
- Updated dependencies [b946952]
|
|
22
|
+
- Updated dependencies [b946952]
|
|
23
|
+
- @checkstack/backend-api@0.36.0
|
|
24
|
+
- @checkstack/notification-backend@1.8.13
|
|
25
|
+
- @checkstack/common@0.24.1
|
|
26
|
+
|
|
27
|
+
## 0.2.13
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [34f82c1]
|
|
32
|
+
- @checkstack/backend-api@0.35.4
|
|
33
|
+
- @checkstack/notification-backend@1.8.12
|
|
34
|
+
|
|
3
35
|
## 0.2.12
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/notification-discord-backend",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"checkstack": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"pack": "bunx @checkstack/scripts plugin-pack"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@checkstack/backend-api": "0.
|
|
22
|
-
"@checkstack/common": "0.24.
|
|
23
|
-
"@checkstack/notification-backend": "1.8.
|
|
21
|
+
"@checkstack/backend-api": "0.36.0",
|
|
22
|
+
"@checkstack/common": "0.24.1",
|
|
23
|
+
"@checkstack/notification-backend": "1.8.13",
|
|
24
24
|
"zod": "^4.2.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/src/index.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
discordUserConfigSchema,
|
|
7
7
|
buildDiscordEmbed,
|
|
8
8
|
discordStrategy,
|
|
9
|
+
createDiscordStrategy,
|
|
9
10
|
} from "./index";
|
|
10
11
|
|
|
11
12
|
function makeLogger(): Logger {
|
|
@@ -239,33 +240,68 @@ describe("Discord Notification Strategy", () => {
|
|
|
239
240
|
});
|
|
240
241
|
|
|
241
242
|
it("refuses redirects so a 302 to a blocked host is not followed", async () => {
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
243
|
+
const requested: string[] = [];
|
|
244
|
+
const strategy = createDiscordStrategy({
|
|
245
|
+
egress: {
|
|
246
|
+
fetchImpl: (async (url: RequestInfo | URL) => {
|
|
247
|
+
requested.push(String(url));
|
|
248
|
+
return new Response(null, {
|
|
249
|
+
status: 302,
|
|
250
|
+
headers: { Location: "http://169.254.169.254/latest/meta-data" },
|
|
251
|
+
});
|
|
252
|
+
}) as unknown as typeof fetch,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
// A public IP literal passes the pre-flight (no DNS, not in a denied range).
|
|
256
|
+
const result = await strategy.send(makeContext("https://93.184.216.34/hook"));
|
|
257
|
+
expect(result.success).toBe(false);
|
|
258
|
+
expect(result.error).toContain("redirect");
|
|
259
|
+
// Only the original target was requested; the Location was never followed.
|
|
260
|
+
expect(requested).toHaveLength(1);
|
|
261
|
+
expect(requested[0]).toContain("93.184.216.34");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("never delivers when the host rebinds to an internal address after the pre-flight", async () => {
|
|
265
|
+
let delivered = false;
|
|
266
|
+
let lookups = 0;
|
|
267
|
+
const strategy = createDiscordStrategy({
|
|
268
|
+
egress: {
|
|
269
|
+
// Public to the pre-flight, cloud metadata to the delivery resolve.
|
|
270
|
+
lookupFn: async () => {
|
|
271
|
+
lookups++;
|
|
272
|
+
const address = lookups === 1 ? "93.184.216.34" : "169.254.169.254";
|
|
273
|
+
return [{ address, family: 4 }];
|
|
274
|
+
},
|
|
275
|
+
fetchImpl: (async () => {
|
|
276
|
+
delivered = true;
|
|
277
|
+
return new Response(null, { status: 204 });
|
|
278
|
+
}) as unknown as typeof fetch,
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
const result = await strategy.send(
|
|
282
|
+
makeContext("https://rebind.example/hook"),
|
|
283
|
+
);
|
|
284
|
+
expect(result.success).toBe(false);
|
|
285
|
+
expect(delivered).toBe(false);
|
|
286
|
+
expect(lookups).toBe(2);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("delivers a POST through the guarded egress", async () => {
|
|
290
|
+
let method: string | undefined;
|
|
291
|
+
const strategy = createDiscordStrategy({
|
|
292
|
+
egress: {
|
|
293
|
+
lookupFn: async () => [{ address: "93.184.216.34", family: 4 }],
|
|
294
|
+
fetchImpl: (async (_url: RequestInfo | URL, init?: RequestInit) => {
|
|
295
|
+
method = init?.method;
|
|
296
|
+
return new Response(null, { status: 200 });
|
|
297
|
+
}) as unknown as typeof fetch,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
const result = await strategy.send(
|
|
301
|
+
makeContext("https://hooks.example.com/hook"),
|
|
302
|
+
);
|
|
303
|
+
expect(result.success).toBe(true);
|
|
304
|
+
expect(method).toBe("POST");
|
|
269
305
|
});
|
|
270
306
|
});
|
|
271
307
|
});
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
notificationStrategyExtensionPoint,
|
|
14
14
|
postJson,
|
|
15
|
+
createWebhookFetch,
|
|
15
16
|
validateWebhookUrl,
|
|
17
|
+
type WebhookEgressOptions,
|
|
16
18
|
IMPORTANCE_EMOJI,
|
|
17
19
|
renderSubjectsAsMarkdown,
|
|
18
20
|
} from "@checkstack/notification-backend";
|
|
@@ -139,9 +141,16 @@ function buildDiscordEmbed(options: DiscordEmbedOptions): DiscordEmbed {
|
|
|
139
141
|
|
|
140
142
|
/**
|
|
141
143
|
* Discord notification strategy using webhooks.
|
|
144
|
+
*
|
|
145
|
+
* `egress` is a test seam: production passes nothing (real DNS + the pinned
|
|
146
|
+
* transport); tests inject a DNS / `fetch` stub so they never touch the network.
|
|
142
147
|
*/
|
|
143
|
-
|
|
144
|
-
{
|
|
148
|
+
function createDiscordStrategy({
|
|
149
|
+
egress = {},
|
|
150
|
+
}: {
|
|
151
|
+
egress?: WebhookEgressOptions;
|
|
152
|
+
} = {}): NotificationStrategy<DiscordConfig, DiscordUserConfig> {
|
|
153
|
+
return {
|
|
145
154
|
id: "discord",
|
|
146
155
|
displayName: "Discord",
|
|
147
156
|
description: "Send notifications via Discord webhooks",
|
|
@@ -178,7 +187,10 @@ const discordStrategy: NotificationStrategy<DiscordConfig, DiscordUserConfig> =
|
|
|
178
187
|
// SSRF guard: the webhook URL is user-supplied. Reject it up front if it
|
|
179
188
|
// resolves to an internal/reserved address, and refuse redirects below so
|
|
180
189
|
// a receiver cannot 3xx us at an internal host past this pre-flight.
|
|
181
|
-
const validation = await validateWebhookUrl({
|
|
190
|
+
const validation = await validateWebhookUrl({
|
|
191
|
+
url: userConfig.webhookUrl,
|
|
192
|
+
lookupFn: egress.lookupFn,
|
|
193
|
+
});
|
|
182
194
|
if (!validation.ok) {
|
|
183
195
|
logger.warn(
|
|
184
196
|
`Blocked Discord delivery to ${userConfig.webhookUrl}: ${validation.error}`,
|
|
@@ -199,7 +211,9 @@ const discordStrategy: NotificationStrategy<DiscordConfig, DiscordUserConfig> =
|
|
|
199
211
|
const result = await postJson({
|
|
200
212
|
url: userConfig.webhookUrl,
|
|
201
213
|
body: { embeds: [embed] },
|
|
202
|
-
|
|
214
|
+
// Pinned to the validated IP (no DNS-rebind window) and fails closed on
|
|
215
|
+
// any 3xx, so a receiver cannot redirect us at an internal host.
|
|
216
|
+
fetchImpl: createWebhookFetch({ logger, ...egress }),
|
|
203
217
|
serviceName: "Discord",
|
|
204
218
|
logger,
|
|
205
219
|
});
|
|
@@ -208,6 +222,9 @@ const discordStrategy: NotificationStrategy<DiscordConfig, DiscordUserConfig> =
|
|
|
208
222
|
: { success: false, error: result.error };
|
|
209
223
|
},
|
|
210
224
|
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const discordStrategy = createDiscordStrategy();
|
|
211
228
|
|
|
212
229
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
213
230
|
// Plugin Definition
|
|
@@ -237,6 +254,7 @@ export {
|
|
|
237
254
|
discordUserConfigSchema,
|
|
238
255
|
buildDiscordEmbed,
|
|
239
256
|
discordStrategy,
|
|
257
|
+
createDiscordStrategy,
|
|
240
258
|
};
|
|
241
259
|
/** @internal */
|
|
242
260
|
export type { DiscordConfig, DiscordUserConfig, DiscordEmbedOptions };
|