Skip to content

Conversation

@thibmeu
Copy link
Collaborator

@thibmeu thibmeu commented Sep 25, 2025

It allows to get a shorthand to validate a signature, instead of parsing the HTML page that is targetted at browsers.

Available at https://http-message-signatures-example.research.cloudflare.com/

In addition, this commit adds support to read signature-agent (only https: scheme)

Note: that commit does not add the endpoint in the documentation yet

fyi @sandormajor

It allows to get a shorthand to validate a signature, instead of parsing
the HTML page that is targetted at browsers.

In addition, this commit adds support to read signature-agent
@thibmeu thibmeu requested a review from AkshatM September 25, 2025 13:27
@thibmeu thibmeu self-assigned this Sep 25, 2025
@thibmeu thibmeu added the enhancement New feature or request label Sep 25, 2025
`${parsed}${HTTP_MESSAGE_SIGNATURES_DIRECTORY}`
).then((r) => r.json());
} else {
directory = await getDirectory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would rename getDirectory() to getExampleDirectory() or similar and the import jwk from ... on the top to import exampleJwk from

console.error(
`Failed to validate Signature-Agent header: ${signatureAgent}`
);
return SignatureValidationStatus.INVALID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how much you want to get into such error reporting but it would be very helpful for debugging to return the reason of the failure back in the response body. Essentially printing out the message of the exception if something fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've updated the code so that it returns invalid: <error.message>, when a message is present. validation is very much "does it succeed". it could be refined to provide clearer error message

note that you should be able to run the code locally with npm run dev

@sandormajor
Copy link
Contributor

Thank you @thibmeu for the quick update to help users debug webbotauth, I really appreciate it!

Rename getDirectory to getExampleDirectory
Return the error when signature validation fails
Simplify fetching signature agent branch
@thibmeu
Copy link
Collaborator Author

thibmeu commented Sep 26, 2025

@sandormajor thanks for the fast turnaround on the review. i've updated the code accordingly.

Copy link
Contributor

@sandormajor sandormajor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thibmeu looks great!

// make "some" validatation of the Signature-Agent header before making a request
let parsed: string;
try {
parsed = JSON.parse(signatureAgent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will try parsing "https://..." from the Signature-Agent header as JSON, and going to fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature-Agent is a structured string (Section 3.3.3 of RFC8941), meaning the header will be Signature-Agent: "https://example.com"
So what's being passed to fetchDirectory method is "https://example.com" (literal, with the quotes)

This would result in the following execution

signatureAgent = `"https://example.com"`
parsed = JSON.parse(signatureAgent)

// parsed === "https://example.com"

This would have to be updated following thibmeu/http-message-signatures-directory#71, but is OK for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Thibault, I totally missed the quotes around it :)

@thibmeu thibmeu merged commit 36b5495 into cloudflare:main Oct 14, 2025
3 checks passed
@thibmeu thibmeu deleted the add-verify-short branch October 14, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants