Skip to content

[JENKINS-48012] Require a X-Hub-Signature header when receiving a hook payload and if…#188

Merged
lanwen merged 2 commits intojenkinsci:masterfrom
silbernm:JENKINS-48012-require-signature-if-secret-configured
Jan 16, 2018
Merged

[JENKINS-48012] Require a X-Hub-Signature header when receiving a hook payload and if…#188
lanwen merged 2 commits intojenkinsci:masterfrom
silbernm:JENKINS-48012-require-signature-if-secret-configured

Conversation

@silbernm
Copy link
Contributor

@silbernm silbernm commented Jan 12, 2018

… a secret is configured

As reported in JENKINS-48012, an attacker can currently circumvent the signature check of the GitHub plugin simply by omitting the X-Hub-Signature header.


This change is Reviewable

@oleg-nenashev oleg-nenashev requested review from KostyaSha, kostmo and lanwen and removed request for kostmo January 12, 2018 12:18
*
* @param config where to remove
*/
public static void removeSecretIn(GitHubPluginConfig config) {
Copy link
Member

Choose a reason for hiding this comment

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

@Restricted perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

It's in the Test scope

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Javadoc needs to be adjusted then. Currently it says "Checks that an incoming request has a valid signature, if there is specified a signature in the config." which is exactly what the method does.

For discussion: Maybe it worth to add a configuration option which would allow opting-out from enforced checks. I'd guess it's important for on-premise instances like GitHub Enterprise

@daniel-beck
Copy link
Member

Seems to be introduced by #134:

also don't bother signature validation if no header from github with signature

Versions from v1.21.0 appear to be affected.

@daniel-beck
Copy link
Member

daniel-beck commented Jan 12, 2018

@oleg-nenashev

Currently it says "Checks that an incoming request has a valid signature, if there is specified a signature in the config." which is exactly what the method does.

It only checks the signature validity if it's present. For there to be a valid signature, it needs:

  • to have a signature
  • the signature needs to be valid

So the Javadoc LGTM.

…ret is specified in the GitHub plugin config
@silbernm
Copy link
Contributor Author

@daniel-beck
@oleg-nenashev
I think we are on the same page, but the documentation is misleading. There is never a "signature" in the config, but a "hook secret". I understood the Javadoc comment as "if there is specified a secret in the config" (because that is the only thing that makes sense IMHO) and coded my fix according to that interpretation. I have tried coming up with a better wording and I have moved the line that reads the signature header further down, such that it is clear that the header is validated if and only if a hook secret is specified in the GitHub plugin config.

Regarding GitHub Enterprise on-premise: That is exactly the setup that we are using at my workplace. When not configuring a shared secret in the GitHub plugin configuration, the fixed method will continue not to verify the signature, even if one was provided. So we should be fine on that use-case.

@daniel-beck
Copy link
Member

[ERROR] src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java[135] (sizes) LineLength: Line is longer than 120 characters (found 124).

Copy link
Member

@KostyaSha KostyaSha left a comment

Choose a reason for hiding this comment

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

seems fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants