Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(security): block the shared address space in webhook destinations (#1523)

Luan Taraschi028c905fd505
diff --git a/apps/api/src/utils/assert-public-destination.ts b/apps/api/src/utils/assert-public-destination.ts
index 351eacc86..51c67ac17 100644
--- a/apps/api/src/utils/assert-public-destination.ts
+++ b/apps/api/src/utils/assert-public-destination.ts
@@ -13,6 +13,10 @@ function isDisallowedIpv4(ip: string): boolean {
a === 0 ||
a === 10 ||
a === 127 ||
+ // 100.64.0.0/10, RFC 6598. Several hosted Kubernetes offerings put pod
+ // and service networks in here, where it reaches the same neighbours
+ // 10/8 does on a plain VPC.
+ (a === 100 && b >= 64 && b <= 127) ||
(a === 169 && b === 254) ||
(a === 172 && b >= 16 && b <= 31) ||
(a === 192 && b === 168)
diff --git a/tests/api/utils/assert-public-destination.test.ts b/tests/api/utils/assert-public-destination.test.ts
new file mode 100644
index 000000000..d104d6e06
--- /dev/null
+++ b/tests/api/utils/assert-public-destination.test.ts
@@ -0,0 +1,37 @@
+import { describe, expect, it } from "vitest";
+import { isDisallowedAddress } from "../../../apps/api/src/utils/assert-public-destination";
+
+describe("isDisallowedAddress", () => {
+ it("blocks the ranges a webhook must never reach", () => {
+ expect(isDisallowedAddress("localhost")).toBe(true);
+ expect(isDisallowedAddress("127.0.0.1")).toBe(true);
+ expect(isDisallowedAddress("10.0.0.1")).toBe(true);
+ expect(isDisallowedAddress("172.16.0.1")).toBe(true);
+ expect(isDisallowedAddress("192.168.1.1")).toBe(true);
+ expect(isDisallowedAddress("169.254.169.254")).toBe(true);
+ expect(isDisallowedAddress("[::1]")).toBe(true);
+ expect(isDisallowedAddress("[::ffff:7f00:1]")).toBe(true);
+ });
+
+ // RFC 6598. Several hosted Kubernetes offerings put pod and service
+ // networks in here, so on those clusters it reaches the same neighbours
+ // 10/8 does on a plain VPC.
+ it("blocks the shared address space", () => {
+ expect(isDisallowedAddress("100.64.0.0")).toBe(true);
+ expect(isDisallowedAddress("100.64.0.1")).toBe(true);
+ expect(isDisallowedAddress("100.100.100.100")).toBe(true);
+ expect(isDisallowedAddress("100.127.255.255")).toBe(true);
+ });
+
+ it("leaves the rest of 100.0.0.0/8 alone", () => {
+ expect(isDisallowedAddress("100.63.255.255")).toBe(false);
+ expect(isDisallowedAddress("100.128.0.0")).toBe(false);
+ expect(isDisallowedAddress("100.0.0.1")).toBe(false);
+ });
+
+ it("allows a routable address", () => {
+ expect(isDisallowedAddress("8.8.8.8")).toBe(false);
+ expect(isDisallowedAddress("93.184.216.34")).toBe(false);
+ expect(isDisallowedAddress("example.com")).toBe(false);
+ });
+});