Skip to content

Commit

Permalink
fixing issue "URL query parameters do not get removed in htu field in…
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoaraujo committed Jan 25, 2022
1 parent 93ac2d4 commit b26d0cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/authenticatedFetch/dpopUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ describe("createDpopHeader", () => {
expect(payload.htu).toBe("https://some.resource/");
});

it("creates a JWT with 'htu' that needs to be normalized", async () => {
const header = await createDpopHeader(
"https://user:[email protected]/?query#hash",
"GET",
await mockKeyPair()
);
const { payload } = await jwtVerify(header, (await mockJwk()).publicKey);
expect(payload.htm).toBe("GET");
expect(payload.jti).toBeDefined();
// The IRI is normalized, hence the trailing '/'
expect(payload.htu).toBe("https://some.resource/");
});

it("creates a JWT with the appropriate protected header", async () => {
const header = await createDpopHeader(
"https://some.resource",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/authenticatedFetch/dpopUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import { PREFERRED_SIGNING_ALG } from "../constant";
* @returns The normalized URL as a string.
* @hidden
*/
function removeHashUsernameAndPassword(audience: string): string {
function normalizeHTU(audience: string): string {
const cleanedAudience = new URL(audience);
cleanedAudience.hash = "";
cleanedAudience.username = "";
cleanedAudience.password = "";
cleanedAudience.search = "";
return cleanedAudience.toString();
}

Expand All @@ -58,7 +59,7 @@ export async function createDpopHeader(
dpopKey: KeyPair
): Promise<string> {
return new SignJWT({
htu: removeHashUsernameAndPassword(audience),
htu: normalizeHTU(audience),
htm: method.toUpperCase(),
jti: v4(),
})
Expand Down

0 comments on commit b26d0cf

Please sign in to comment.