-
Notifications
You must be signed in to change notification settings - Fork 16
Reject reqs missing x-hub-signature header if secret_token defined #18
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
Reject reqs missing x-hub-signature header if secret_token defined #18
Conversation
|
The PR looks like it works as-advertised, but I'd appreciate a little validation on my understanding of how it's supposed to work to determine whether this should be considered a breaking change or a fix to the current implementation. From what I understand, this input sets up an HTTP web server, listening for requests, and the Github hooks API includes a signature of each raw request body as a This PR, then, includes the absence of the header along-side a If this is the case, then I would consider the PR to be a fix for the current implementation, in which case a patch-level bump as proposed is appropriate. |
@yaauie Exactly. No header means we can't validate, so we consider it invalid, and let
Yep, that's what's intended here. Not a breaking change, just a patch to bring the behavior in-line with expectations. |
lib/logstash/inputs/github.rb
Outdated
| event.tag("_Invalid_Github_Message") | ||
| is_valid = false | ||
| end | ||
| elsif @secret_token && !sign_header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While your change is functionally correct and minimal, there are a couple of anti-patterns within the existing method definition (e.g., if not, unnecessary is_valid variable) and with this change the reasoning behind this code becomes a little less clear, a little harder to follow, and a little more repetitive.
I'd prefer a functionally-equivalent refactor to this whole method, which I think is an improvement:
def verify_signature(event,body)
# skip validation if we have no secret token
return true unless @secret_token
sign_header = event.get("[headers][x-hub-signature]")
if sign_header
hash = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), @secret_token, body)
event.set("hash", hash)
return true if Rack::Utils.secure_compare(hash, sign_header)
end
event.tag("_Invalid_Github_Message")
return false
endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me! 7d54a10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending @yaauie's approval, too.
|
@yaauie Does everything look good now? Are there additional changes you'd like to see? |
yaauie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've re-triggered the travis jobs that had failed due to an unrelated issue, and will merge this and push a release as soon as the build goes green.
LGTM 👍
|
Hi ! |
Should fix #16
Updates
verify_signatureto check for the absence of thex-hub-signatureheader whensecret_tokenis defined, and treats such requests as invalid.Also revises an existing test to match the new behavior, and adds three more tests to verify that we don't overcorrect by requiring (or checking) the header if
secret_tokenis not defined.