Skip to content

Commit

Permalink
Remove the URL query parameters from the HTU field
Browse files Browse the repository at this point in the history
This fixes issue #1842. The HTU field is now build by addition rather than by substraction: the origin and path from the target URL are concatenated to build the DPoP header `htu` claim, rather than stripping elements from the target URL.

Co-authored-by: Diego Albuquerque <[email protected]>
  • Loading branch information
NSeydoux and diegoaraujo authored Jan 26, 2022
1 parent 4e705c5 commit 2dbc30b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

The following changes have been implemented but not released yet:

-
### Bugfixes

- The HTU field of the DPoP header is now normalized to remove the query parameters.
Thanks to @diegoaraujo for his first contribution to the project!

## 1.11.3 - 2021-08-24

Expand Down
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
11 changes: 4 additions & 7 deletions packages/core/src/authenticatedFetch/dpopUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import { PREFERRED_SIGNING_ALG } from "../constant";
* @returns The normalized URL as a string.
* @hidden
*/
function removeHashUsernameAndPassword(audience: string): string {
const cleanedAudience = new URL(audience);
cleanedAudience.hash = "";
cleanedAudience.username = "";
cleanedAudience.password = "";
return cleanedAudience.toString();
function normalizeHTU(audience: string): string {
const audienceUrl = new URL(audience);
return new URL(audienceUrl.pathname, audienceUrl.origin).toString();
}

export type KeyPair = {
Expand All @@ -58,7 +55,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 2dbc30b

Please sign in to comment.