Files
OmniRoute/tests/unit/webhook-metadata-guard-3269.test.ts
Diego Rodrigues de Sa e Souza 36932b62a7 fix(api): harden private webhook opt-in against cloud-metadata SSRF (#3269) (#3281)
Follow-up to the #3269 private-webhook opt-in. With the opt-in on, the private-host
check was bypassed entirely, leaving cloud-metadata endpoints (169.254.169.254,
metadata.google.internal, 100.100.100.200, link-local 169.254.0.0/16) reachable — the
classic SSRF -> IAM-credential pivot — and the webhook test endpoint returned the
upstream body, making it a content-exfiltration primitive against internal services.

- outboundUrlGuard: add isCloudMetadataHost(); parseAndValidateWebhookUrl blocks those
  hosts UNCONDITIONALLY, even when private targets are opted in.
- webhooks/[id]/test: redact responseBody for private targets (status + latency only).

Regression test: tests/unit/webhook-metadata-guard-3269.test.ts (RED before, GREEN after);
existing webhook SSRF/opt-in suites stay green (34/34).
2026-06-06 03:08:16 -03:00

78 lines
2.6 KiB
TypeScript

/**
* Security hardening for #3269: even when private webhook targets are opted in via
* OMNIROUTE_ALLOW_PRIVATE_PROVIDER_URLS, cloud-metadata / link-local endpoints
* (169.254.169.254, metadata.google.internal, 100.100.100.200, 169.254.0.0/16) must be
* blocked UNCONDITIONALLY — they are the classic SSRF→IAM-credential pivot and have no
* legitimate webhook use case.
*/
import { describe, it, after } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omni-wh-meta-3269-"));
const { parseAndValidateWebhookUrl, isCloudMetadataHost, OutboundUrlGuardError } = await import(
"../../src/shared/network/outboundUrlGuard.ts"
);
const { resetDbInstance } = await import("../../src/lib/db/core.ts");
const FLAG = "OMNIROUTE_ALLOW_PRIVATE_PROVIDER_URLS";
const METADATA_TARGETS = [
"http://169.254.169.254/latest/meta-data/iam/security-credentials/",
"http://metadata.google.internal/computeMetadata/v1/",
"http://100.100.100.200/latest/meta-data/",
"http://169.254.1.2/anything",
];
describe("webhook guard blocks cloud-metadata unconditionally (#3269 hardening)", () => {
it("isCloudMetadataHost flags the known metadata + link-local hosts", () => {
assert.equal(isCloudMetadataHost("169.254.169.254"), true);
assert.equal(isCloudMetadataHost("metadata.google.internal"), true);
assert.equal(isCloudMetadataHost("100.100.100.200"), true);
assert.equal(isCloudMetadataHost("169.254.55.66"), true);
assert.equal(isCloudMetadataHost("10.0.0.5"), false);
assert.equal(isCloudMetadataHost("hooks.example.com"), false);
});
it("blocks metadata targets even when the private opt-in is ON", () => {
process.env[FLAG] = "true";
try {
for (const target of METADATA_TARGETS) {
assert.throws(
() => parseAndValidateWebhookUrl(target),
OutboundUrlGuardError,
`expected ${target} to be blocked`
);
}
} finally {
delete process.env[FLAG];
}
});
it("still allows a normal private LAN host when opted in (not metadata)", () => {
process.env[FLAG] = "true";
try {
const url = parseAndValidateWebhookUrl("http://192.168.0.10/hook");
assert.equal(url.hostname, "192.168.0.10");
} finally {
delete process.env[FLAG];
}
});
});
after(() => {
try {
resetDbInstance();
} catch {
/* ignore */
}
try {
fs.rmSync(process.env.DATA_DIR as string, { recursive: true, force: true });
} catch {
/* ignore */
}
});