mirror of
https://github.com/different-ai/openwork
synced 2026-04-27 09:57:38 +02:00
Align the legacy v1 bundle publish routes with the scoped Next API protections so older deployment paths stop accepting wildcard origins or host-derived share URLs. Co-authored-by: src-opn <src-opn@users.noreply.github.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { buildCanonicalRequest } from "./request-like.ts";
|
|
import { buildCorsHeaders, validateTrustedOrigin } from "./publish-security.ts";
|
|
|
|
test("buildCanonicalRequest pins legacy publish routes to the fixed share origin", () => {
|
|
const request = buildCanonicalRequest({
|
|
pathname: "/v1/bundles",
|
|
method: "POST",
|
|
headers: {
|
|
host: "evil.example",
|
|
"x-forwarded-host": "evil.example",
|
|
origin: "https://openworklabs.com",
|
|
},
|
|
});
|
|
|
|
assert.equal(new URL(request.url).origin, "https://share.openworklabs.com");
|
|
});
|
|
|
|
test("buildCorsHeaders reflects only trusted publisher origins", () => {
|
|
const trustedRequest = buildCanonicalRequest({
|
|
pathname: "/v1/bundles",
|
|
method: "POST",
|
|
headers: { origin: "https://openworklabs.com" },
|
|
});
|
|
const trustedHeaders = buildCorsHeaders(trustedRequest);
|
|
|
|
assert.equal(trustedHeaders["Access-Control-Allow-Origin"], "https://openworklabs.com");
|
|
assert.equal(trustedHeaders.Vary, "Origin");
|
|
|
|
const untrustedRequest = buildCanonicalRequest({
|
|
pathname: "/v1/bundles",
|
|
method: "POST",
|
|
headers: { origin: "https://evil.example" },
|
|
});
|
|
const untrustedHeaders = buildCorsHeaders(untrustedRequest);
|
|
|
|
assert.equal(untrustedHeaders["Access-Control-Allow-Origin"], undefined);
|
|
assert.equal(validateTrustedOrigin(untrustedRequest).ok, false);
|
|
});
|