Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify: does not gracefully handle invalid signatures #80

Open
mfulton26 opened this issue Aug 30, 2022 · 10 comments
Open

verify: does not gracefully handle invalid signatures #80

mfulton26 opened this issue Aug 30, 2022 · 10 comments
Labels
Type: Bug Something isn't working as documented

Comments

@mfulton26
Copy link
Contributor

What happened?

An invalid signature was sent in a request and my server returned a 500, Internal Server Error, due to verify rejecting with a TypeError:

script.ts
import { verify } from "https://cdn.skypack.dev/@octokit/[email protected]?dts";

await verify("secret", "eventPayload", "signature");
run command
NO_COLOR=true deno run script.ts |& pbcopy
stderr
error: Uncaught TypeError: Cannot read properties of null (reading 'map')
  const integers = pairs.map(function(s) {
                         ^
    at hexToUInt8Array (https://cdn.skypack.dev/-/@octokit/[email protected]/dist=es2019,mode=imports/optimized/@octokit/webhooks-methods.js:11:26)
    at verify (https://cdn.skypack.dev/-/@octokit/[email protected]/dist=es2019,mode=imports/optimized/@octokit/webhooks-methods.js:7:70)
    at async file:///path/to/script.ts:3:1

What did you expect to happen?

For verify to resolve to false.

What the problem might be

verify does not validate the format of the signature before attempting to iterate over character pairs (e.g. /^[\dA-F]{64}$/i)

@mfulton26 mfulton26 added the Type: Bug Something isn't working as documented label Aug 30, 2022
@timrogers
Copy link

Thanks for reporting this!

Just to clarify, do the example values you provided in your issue trigger this error? (I haven't had a chance to test yet.)

Would you be open to making a PR to fix this? I'd be happy to review your contribution!

@mfulton26
Copy link
Contributor Author

Thanks for reporting this!

Just to clarify, do the example values you provided in your issue trigger this error? (I haven't had a chance to test yet.)

Would you be open to making a PR to fix this? I'd be happy to review your contribution!

yes

I think any signature that starts with something other 2 or more non-hex characters will reproduce

@mfulton26
Copy link
Contributor Author

I'll see if I have time to make a PR sometime today or tomorrow

@gr2m
Copy link
Contributor

gr2m commented Aug 30, 2022

Looks like a Deno error to me, I cannot reproduce it with Node. Tested with Node v18.8.0 and v16.17.0.

Unfortunately the libraries are not native ESM yet, Deno is using a built version of the code base served from skypack.dev, the build step might also be the culprit here.

@mfulton26
Copy link
Contributor Author

I see there are some browser tests. We can confirm if it is broken by adding additional test cases there first.

@mfulton26
Copy link
Contributor Author

The browser version is completely independent of the node implementation. In fact, I think the browser version has some other behavior differences too. e.g. I have to strip "sha256=" from the signature before passing it into verify for the browser/web version too work.

@mfulton26
Copy link
Contributor Author

It might be worthwhile to write the browser/web tests in Deno. Any concerns with me dropping puppeteer in favor of Deno here?

@gr2m
Copy link
Contributor

gr2m commented Aug 31, 2022

why not both? Maybe start a PR with Deno tests, without removing the existing tests, and we take it from there?

mfulton26 added a commit to mfulton26/webhooks-methods.js that referenced this issue Aug 31, 2022
- configure devcontainer:
  - image: default + Deno
  - extensions: +Deno +Prettier
  - Deno extension: only enabled for Deno test files
- configure Deno to ignore Jest tests
- configure Jest to ignore Deno tests
- add simple `sign` and `verify` Deno tests (more can be added later)

Refs octokit#80
@mfulton26
Copy link
Contributor Author

initial Deno tests PR: #81

@wolfy1339
Copy link
Member

I think the proper thing to do is to catch these errors and handle them in your own code.

We are switching to outputting ESM in the next major version, which should help out with these things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

4 participants