Share redacted DPoP request targets
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
cebbe6ff19
commit
c60d2b1de2
2 files changed
+22
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
computeDpopAccessTokenHash,
|
||||
computeDpopJwkThumbprint,
|
||||
normalizeDpopHtu,
|
||||
redactDpopRequestTarget,
|
||||
type DpopPublicJwk,
|
||||
verifyDpopProof,
|
||||
} from "./dpop.ts";
|
||||
@@ -41,6 +42,18 @@ function signDpopProof(input: {
|
||||
return `${header}.${payload}.${signature}`;
|
||||
}
|
||||
|
||||
describe("redactDpopRequestTarget", () => {
|
||||
it("retains the scheme, host, port, and path while removing sensitive URL components", () => {
|
||||
const url = "https://user:[email protected]:8443/oauth/token?code=secret#fragment";
|
||||
|
||||
assert.equal(redactDpopRequestTarget(url), "https://example.com:8443/oauth/token");
|
||||
});
|
||||
|
||||
it("returns a safe sentinel for invalid input", () => {
|
||||
assert.equal(redactDpopRequestTarget("not a URL?token=secret"), "<invalid-url>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("verifyDpopProof", () => {
|
||||
const { privateKey, publicKey } = NodeCrypto.generateKeyPairSync("ec", {
|
||||
namedCurve: "P-256",
|
||||
|
||||
@@ -88,6 +88,15 @@ export function normalizeDpopHtu(url: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function redactDpopRequestTarget(url: string): string {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
return `${parsed.protocol}//${parsed.host}${parsed.pathname}`;
|
||||
} catch {
|
||||
return "<invalid-url>";
|
||||
}
|
||||
}
|
||||
|
||||
export function computeDpopJwkThumbprint(jwk: DpopPublicJwk): string {
|
||||
return Encoding.encodeBase64Url(sha256(new TextEncoder().encode(dpopThumbprintInput(jwk))));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user