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

Accept array of secrets, not just one #777

Closed
wants to merge 7 commits into from

Conversation

nwf-msr
Copy link

@nwf-msr nwf-msr commented Dec 6, 2022

Resolves #770.


Behavior

Before the change?

  • Only one secret could be specified for a WebHook object.

After the change?

  • A bare secret or an array of secrets are each accepted. In the latter case, any match will be accepted.

Additional info

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Added the appropriate label for the given change

Does this introduce a breaking change?

  • No

Pull request type

I do not seem to be able to add labels, but please add Type: Feature for me?


We don't really have to do anything special here for constant-timedness.
Since each comparison is constant time, the only timing differential is
between all checks (completely) failing and some check (completely)
succeeding, and so the only thing learned is whether a guess was
completely right or wrong.
And plumb through the option of taking an array of secrets
Add typechecking and integration tests
Mention this ability in the README

FIXES #770
@gr2m gr2m added the Type: Feature New feature or request label Dec 6, 2022
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

PR looks great so far! Can you please also update the ### Constructor options table?

Also can you run npm run lint:fix to make the prettier linter happy?

@nwf-msr nwf-msr force-pushed the 202212-770-secrets branch from b6e31fe to 2dc6152 Compare December 6, 2022 04:37
@nwf-msr nwf-msr requested a review from gr2m December 6, 2022 04:39
@gr2m
Copy link
Contributor

gr2m commented Dec 6, 2022

can you look into the failing tests?

Please don't force-push changes, we don't mind a messy commit history in pull requests, we squash & merge them in the end anyway

@nwf-msr
Copy link
Author

nwf-msr commented Dec 8, 2022

What'd I do to make CodeQL unhappy? :(

@wolfy1339
Copy link
Member

It's not you, it's CodeQL being uncooperative.

Just ignore it

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

I think the pull request looks good as is.

Good point about the .sign() method. Given that the first secret in a given array of secrets has special meaning, I wonder if it would make more sense to keep the secret as is, but add an additional option such as alternativeSecrets or maybe some other name that better conveys that these secrets are used for incoming request verification only?

My understanding is that in your case, there will always only be one other secret. Do you see a use case where more than two secrets would be needed to be provided?

Comment on lines +62 to +63
then update your Webhook receiver to accept only the new secret. Signatures will
always be made with the first secret.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
then update your Webhook receiver to accept only the new secret. Signatures will
always be made with the first secret.
then update your Webhook receiver to accept only the new secret. New signatures will
be calculated using the first secret.

@@ -111,11 +123,14 @@ new Webhooks({ secret /*, transform */ });
<code>
secret
</code>
<em>(String)</em>
<em>(String or String Array)</em>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<em>(String or String Array)</em>
<em>(String or Array of Strings)</em>

Comment on lines +130 to +133
Secret as configured in GitHub Settings. If an array of strings, an
incoming webhook event will be accepted if its signature verifies
with any of the secrets given and signatures will always be generated
with the first secret.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Secret as configured in GitHub Settings. If an array of strings, an
incoming webhook event will be accepted if its signature verifies
with any of the secrets given and signatures will always be generated
with the first secret.
Secret as configured in GitHub Settings. If set to an array of strings, a
webhook request will be accepted if its signature verifies
with any of the given secrets. New signatures will always be
calculated using the first secret.

@nwf-msr
Copy link
Author

nwf-msr commented Dec 16, 2022

I think the pull request looks good as is.

Good point about the .sign() method. Given that the first secret in a given array of secrets has special meaning, I wonder if it would make more sense to keep the secret as is, but add an additional option such as alternativeSecrets or maybe some other name that better conveys that these secrets are used for incoming request verification only?

That makes sense. I'll take a stab at that approach.

My understanding is that in your case, there will always only be one other secret. Do you see a use case where more than two secrets would be needed to be provided?

That's true and no, I don't see reason to need more than one active and one retiring secret, at least, at the moment. I'm tempted to leave alternativeSecrets as an array of strings, tho', just in case. It's not like it's hard or on the hot path most of the time.

@gr2m
Copy link
Contributor

gr2m commented Jan 10, 2023

maybe call them alternativeSecretsForVerification to make clear they won't be used for the .sign() method?

@nwf-msr
Copy link
Author

nwf-msr commented Feb 6, 2023

Belatedly, I've raised #811 .

@wolfy1339
Copy link
Member

Instead of opening a separate PR, you could have simply reused this one.

Closing in favour of #811

@wolfy1339 wolfy1339 closed this Feb 10, 2023
@nwf-msr
Copy link
Author

nwf-msr commented Feb 10, 2023

I didn't reuse this one because I was advised not to force-push changes and enough time had elapsed that doing the work on a new checkout seemed wise.

@wolfy1339
Copy link
Member

When you need to update using a rebase, a force-push can be warranted.
When you simply always squash your changes, it can become harder to review changes since the last time it was reviewed, and we don't mind having many commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT]: Facilitate webhook secret rotation
4 participants