-
Bug
-
Resolution: Unresolved
-
Major
-
Jenkins Version: 2.4462.3
Bitbucket Branch Source Plugin Version: 895.v15dc41668f03
JDK Version: JDK11
We have a Jenkins master in our production environment.
I've observed that the Bitbucket Branch Source Plugin creates webhooks in Bitbucket repositories and uses specific endpoints in Jenkins for webhook notifications, such as:
- /bitbucket-scmsource-hook/notify
- /bitbucket-server-webhook/trigger
These endpoints successfully process webhook requests from Bitbucket without requiring any authentication (e.g., credentials, tokens). While this facilitates seamless integration, it raises the following concerns:
Observed Behavior:
- The plugin creates webhooks in Bitbucket repositories automatically when a multibranch pipeline or Bitbucket project is configured in Jenkins.
- Webhook requests to the above endpoints are authenticated implicitly, even when no credentials are configured.
Expected Behavior:
- Jenkins should authenticate incoming webhook requests using a api token or user credentials.
- The plugin should enforce secure communication to avoid unauthorized triggering of builds.
Why does the plugin allow unauthenticated access to these endpoints?
[JENKINS-74983] Security Concern: Bitbucket Branch Source Plugin Creating Webhooks Without Authentication
Priority | Original: Critical [ 2 ] | New: Major [ 3 ] |
Bitbucket webhook HTTP requests can have an X-Hub-Signature header field that contains the HMAC of the request body. The key of the HMAC is a secret that must be configured beforehand. The Bitbucket Branch Source plugin for Jenkins could be enhanced to let the administrator input this secret and to validate the incoming HTTP requests.
The X-Hub-Signature header field is documented in:
It looks like these are compatible with each other, so the HMAC validation would only need to be implemented once.
I suppose the HMAC must be computed from the byte stream, preferably before decoding to a Java string, and definitely before parsing JSON. In the Bitbucket Branch Source plugin, the BitbucketSCMSourcePushHookReceiver.doNotify(StaplerRequest2) method decodes from UTF-8 to a string:
String body = IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8);
and passes this string to an implementation of HookProcessor.process(HookEventType, String, BitbucketType, String), which then parses JSON. The plugin does not know the project and repository before it parses this JSON; and it cannot compute the HMAC before it has located the HMAC key. Ways to solve this:
The first of these options looks best.