+
Skip to content

No webhook secret #1127

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

Merged
merged 4 commits into from
Feb 28, 2019
Merged

No webhook secret #1127

merged 4 commits into from
Feb 28, 2019

Conversation

jbrockopp
Copy link
Contributor

@jbrockopp jbrockopp commented Feb 25, 2019

Fixes #1126

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@jbrockopp
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Feb 25, 2019
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @jbrockopp!

Just a couple minor tweaks, please, and then we will await a second LGTM before merging.

return nil, err
// Only validate the signature if a secret message exists. This is intended for
// local development only and all webhooks should contain a secret message.
if secretKey != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In Go, it is more idiomatic with slices to check against a length of zero which will work for both nil and a zero-length slice. Checking against nil is discouraged because it doesn't work for a zero-length slice.

So please change this to if len(secretKey) > 0 {.

@@ -110,7 +110,7 @@ func TestValidatePayload_FormGet(t *testing.T) {

// check that if payload is invalid we get error
req.Header.Set(signatureHeader, "invalid signature")
if _, err = ValidatePayload(req, nil); err == nil {
if _, err = ValidatePayload(req, []byte{}); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This and line 143 will now need to be changed... since it is checking for an invalid signature, please just go ahead and use something like []byte{0} here and below.

@@ -130,6 +130,8 @@ func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
// The Content-Type header of the payload can be "application/json" or "application/x-www-form-urlencoded".
// If the Content-Type is neither then an error is returned.
// secretKey is the GitHub Webhook secret message.
// If your webhook does not contain a secret message, you can pass nil. This
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about ...pass nil or an empty slice. ?

@gmlewis gmlewis requested a review from gauntface February 26, 2019 02:45
@jbrockopp
Copy link
Contributor Author

@gmlewis I have made changes per your feedback. Please let me know if anything else is required 👍

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @jbrockopp!

Awaiting second LGTM before merging.

@@ -130,6 +130,8 @@ func messageMAC(signature string) ([]byte, func() hash.Hash, error) {
// The Content-Type header of the payload can be "application/json" or "application/x-www-form-urlencoded".
// If the Content-Type is neither then an error is returned.
// secretKey is the GitHub Webhook secret message.
// If your webhook does not contain a secret message, you can pass nil or an empty slice.
// This is intended for local development purposes only and all webhooks should contain a secret message.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: I believe we should maintain semantic consistency between GitHub documentation and the library's documentation so that the user can easily navigate between both of them with ease. Thus, I request that we update this to read "... all webhooks should ideally set up a secret token."

Thoughts @gmlewis @jbrockopp

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds great! Let's please go ahead and address this change in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kshitij10496 @gmlewis sure I can do that. I was just following the previously used verbiage in the existing code.

// secretKey is the GitHub Webhook secret message.

Copy link
Contributor

@kshitij10496 kshitij10496 left a comment

Choose a reason for hiding this comment

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

I have a minor, non-blocking suggestion about the general documentation which can be addressed in a separate change. So, LGTM on this PR! 👍

Thanks, @jbrockopp! 🎉

@jbrockopp
Copy link
Contributor Author

@kshitij10496 @gmlewis I have made changes per your feedback. Please let me know if anything else is required 👍

Copy link
Contributor

@gauntface gauntface left a comment

Choose a reason for hiding this comment

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

Thank you for the fix 👍

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 28, 2019

Thank you, @gauntface!
Merging.

@gmlewis gmlewis merged commit 361aadb into google:master Feb 28, 2019
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
willnorris added a commit that referenced this pull request Mar 31, 2023
Verify the payload signature if the request has a signature present in
HTTP headers, or if a non-empty secretToken is passed to the
ValidatePayload method, indicating that a signature is expected.

This modifies the behavior added in #1127, but not the spirit of what
was requested in #1126, which is to support webhooks that don't have
configured secrets.

Specifically, this no longer allows signature checking to be skipped
entirely, even for webhooks with a configured secret, simply by passing
an empty secretToken to ValidatePayload.

Fixes #2731
willnorris added a commit that referenced this pull request Mar 31, 2023
Verify the payload signature if the request has a signature present in
HTTP headers, or if a non-empty secretToken is passed to the
ValidatePayload method, indicating that a signature is expected.

This modifies the behavior added in #1127, but not the spirit of what
was requested in #1126, which is to support webhooks that don't have
configured secrets.

Specifically, this no longer allows signature checking to be skipped
entirely, even for webhooks with a configured secret, simply by passing
an empty secretToken to ValidatePayload.

Fixes #2731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载