The shared credential admission (V2 and V3) only rejected CR/LF. A token with NUL, a non-Latin-1 character or another control character passed, then Fetch rejected it after V3 had marked the attempt dispatched: a query burned its retry budget and a command ended MAYBE_APPLIED with NETWORK_FAILURE. The external session adapter also merged header names that differ only in case, silently keeping the last value. - admitCredentialHeaders: the value must match [\x20-\x7E\xA0-\xFF]+ (a ByteString without C0/C1 controls); the size limit is now the string length, which is the wire byte count for a ByteString. Failure stays CREDENTIAL_HEADER_VALUE_INVALID, i.e. AUTH_INTEGRATION_FAILURE before dispatch. - checkFinalInvariants: builds `new Headers(headers)` first; any value Fetch would reject fails as HEADER_VALUE_INVALID (new additive member of FinalInvariantFailure) with zero fetch calls. - validateCredentialPatch: rejects case-only duplicate header names. RED before fix: http-execution-v3-live-authority.test.ts "rejects a NUL / non-Latin-1 credential value before dispatch" (got TRANSPORT_FAILURE, fetch called), http-contract-bridge.test.ts "rejects a NUL/non-Latin-1/tab/DEL/C1 control value ..." and "fails before dispatch when Fetch would reject a header value", auth-session-adapter.test.ts "rejects credential headers that differ only in case instead of merging them". Pinned: "admits an ordinary bearer token", CR/LF rejection, existing "Bearer ok"/"Bearer token" integration paths. Gates: check:architecture, check:types:app, check:types:test, lint, test:component, test:integration, test:contract, test:platform, test:reference-feature pass. test:unit passes except removal-fixture.test.ts (needs generated artifacts/ release evidence absent in a fresh worktree; unrelated). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
admitCredentialHeaders,
|
|
checkFinalInvariants,
|
|
projectRequest,
|
|
} from "../../src/adapters/http/http-contract-bridge.ts";
|
|
import { TEST_DETAIL_HTTP_CONTRACT } from "../helpers/external-contract-fixture.ts";
|
|
|
|
const BEARER_PROFILE = Object.freeze({
|
|
authProfileId: "TEST_BEARER",
|
|
transport: "BEARER_HEADER" as const,
|
|
credentials: "omit" as const,
|
|
allowedCredentialHeaders: Object.freeze(["authorization" as const]),
|
|
requiredCredentialHeaders: Object.freeze(["authorization" as const]),
|
|
});
|
|
|
|
describe("credential header admission", () => {
|
|
it.each([
|
|
["NUL", "Bearer abc\u0000def"],
|
|
["non-Latin-1", "Bearer 한"],
|
|
["tab", "Bearer abc\tdef"],
|
|
["DEL", "Bearer abc\u007fdef"],
|
|
["C1 control", "Bearer abc\u0085def"],
|
|
["CR/LF", "Bearer abc\r\nX-Evil: 1"],
|
|
])("rejects a %s value before any header object is built", (_label, value) => {
|
|
expect(
|
|
admitCredentialHeaders({ authorization: value }, BEARER_PROFILE),
|
|
).toEqual({ ok: false, failure: "CREDENTIAL_HEADER_VALUE_INVALID" });
|
|
});
|
|
|
|
it("admits an ordinary bearer token", () => {
|
|
const token = "Bearer eyJhbGciOi.J9-abc_DEF~+/=";
|
|
expect(
|
|
admitCredentialHeaders({ Authorization: token }, BEARER_PROFILE),
|
|
).toEqual({ ok: true, headers: { authorization: token } });
|
|
});
|
|
|
|
it("rejects names that differ only in case", () => {
|
|
expect(
|
|
admitCredentialHeaders(
|
|
{ Authorization: "Bearer a", authorization: "Bearer b" },
|
|
BEARER_PROFILE,
|
|
).ok,
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("final request invariants", () => {
|
|
it("fails before dispatch when Fetch would reject a header value", () => {
|
|
const request = Object.freeze({
|
|
url: "https://api.test/base/x",
|
|
method: "POST",
|
|
bodyBytes: null,
|
|
});
|
|
const init: RequestInit = {
|
|
method: "POST",
|
|
redirect: "error",
|
|
credentials: "omit",
|
|
};
|
|
expect(
|
|
checkFinalInvariants({
|
|
request,
|
|
expectedMethod: "POST",
|
|
baseUrl: "https://api.test/base/",
|
|
init,
|
|
headers: {
|
|
authorization: "Bearer ok",
|
|
"Idempotency-Key": "키",
|
|
},
|
|
requestByteLimit: 0,
|
|
deadlineRemainingMs: 1_000,
|
|
scopeIsCurrent: true,
|
|
authProfile: BEARER_PROFILE,
|
|
}),
|
|
).toBe("HEADER_VALUE_INVALID");
|
|
});
|
|
});
|
|
|
|
describe("descriptor-driven path projection", () => {
|
|
it.each([".", ".."])(
|
|
"rejects the dot segment %j instead of letting URL resolution move the target",
|
|
(entityId) => {
|
|
expect(
|
|
projectRequest(
|
|
TEST_DETAIL_HTTP_CONTRACT,
|
|
{ entityId },
|
|
"https://api.test/base/",
|
|
),
|
|
).toEqual({ ok: false, failure: "PATH_VALUE_INVALID" });
|
|
},
|
|
);
|
|
|
|
it("still encodes an ordinary value containing dots", () => {
|
|
const outcome = projectRequest(
|
|
TEST_DETAIL_HTTP_CONTRACT,
|
|
{ entityId: "..a." },
|
|
"https://api.test/base/",
|
|
);
|
|
expect(outcome.ok && outcome.request.url).toBe(
|
|
"https://api.test/base/api/test-entities/..a.",
|
|
);
|
|
});
|
|
});
|