jenkinsci / generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
https://plugins.jenkins.io/generic-webhook-trigger
404 stars 159 forks source link

HMAC verify 500 error with Teams #187

Closed izenk closed 3 years ago

izenk commented 3 years ago

I think, I found the problem: here

MS Teams generate HMAC token during webhook registration and this token always contains '=' at the end of string and this block of code (To handle X-Hub-Signature: sha256=87e3e7...) if (value.contains("=")) { return value.split("=")[1];} tries to split on '=' and take right part, what leads to ArrayIndexOutOfBoundsException because '=' is the last symbol in the string.

tomasbjerre commented 3 years ago

Problem seems to be that Teams is sending the HMAC value as Base64 encoded.

If the plugin tries to decode any value as Base64, and fall back on current implementation, it would succeed with decoding things that are not really Base64 encoded, like 87e3e7b7e4567f528342a75b6d88c619f272c68a4d0d565c68d596a830213164.

So I think the fix here needs to be an option in the plugin to decode the header, as it cannot be auto detected.

tomasbjerre commented 3 years ago

On second thought, I can just Base64 encode the calculated HMAC and also compare that. Fixed and released in 1.72.

izenk commented 3 years ago

@tomasbjerre thanks! Plugin was updated and error gone. Any ways to debug plugin issues? May be a logger? Error gone, but now jenkins just returns 403 on HMAC from ms teams.

tomasbjerre commented 3 years ago

There is also response content along with that 403 error.

Best way, in my opinion, to troubleshoot is with curl, as explained in readme.