Skip to content
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

Crumb exclusion should be more forgiving if the user leaves off the trailing slash #152

Merged
merged 1 commit into from
Nov 16, 2016

Conversation

i386
Copy link
Contributor

@i386 i386 commented Nov 5, 2016

Discovered that if I left out the trailing slash on my webhook configuration in Github (e.g. /github-webook rather than /github-webhook/) then incoming requests would not be covered by the crumb exclusion.

This change also adds tests for GitHubWebHookCrumbExclusion.

PTAL @jenkinsci/code-reviewers @KostyaSha


This change is Reviewable

@i386 i386 force-pushed the more-forgiving-config branch 4 times, most recently from 3a1df8f to 098e1cb Compare November 7, 2016 21:31
@jglick
Copy link
Member

jglick commented Nov 7, 2016

What is the purpose of this? If Jenkins receives a request to /github-webhook it will simply redirect you to /github-webhook/ before servicing GitHubWebHook.doIndex:

$ curl -IL https://jenkins.ci.cloudbees.com/github-webhook
HTTP/1.1 302 Found
Date: Mon, 07 Nov 2016 22:32:45 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: https://jenkins.ci.cloudbees.com/github-webhook/
Server: Jetty(9.2.z-SNAPSHOT)
Set-Cookie: JSESSIONID.f61ecab1=1cu3g6hvkmjo21mdyuj1ixkhgu;Path=/;Secure;HttpOnly
X-Content-Type-Options: nosniff
Connection: keep-alive

HTTP/1.1 405 Method Not Allowed
Content-Type: text/plain;charset=UTF-8
Date: Mon, 07 Nov 2016 22:32:45 GMT
Server: Jetty(9.2.z-SNAPSHOT)
X-Content-Type-Options: nosniff
Connection: keep-alive

so you would better use the form ending with / to begin with.

@KostyaSha
Copy link
Member

I also don't understand profit of it. Url format should be also documented. A lot of APIs are sensitive and users should follow docs.

@lanwen
Copy link
Member

lanwen commented Nov 11, 2016

Agree with @KostyaSha. So many code to avoid user mistake...

@lanwen lanwen closed this Nov 11, 2016
@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

@jglick from my testing it seems Github wasn't following the redirect.

@michaelneale
Copy link
Member

michaelneale commented Nov 16, 2016

github does not follow the redirect. @lanwen its a net increase of 4 lines of code for something that bites users daily - is that a lot of code? (did you see that most of it is test cases) @jglick github does not follow the redirect: isaacs/github#574. You do realise this PR is about the "github plugin" so the redirect won't work (github won't change this, they haven't so far, they are not going to). Did you read the PR?

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

@KostyaSha @lanwen I strongly disagree - it's very easy to leave a slash off of the end of the URL and not pick up on why it's not working. This removes the problem all together at the cost of a few lines of code in the Git plugin (and I even wrote some tests!)

We can make more users satisfied with Jenkins if we are more forgiving with their mistakes. So closing this PR as WONTFIX is 🐛

@daniel-beck
Copy link
Member

I'll just leave this link here:
https://en.wikipedia.org/wiki/Robustness_principle

@KostyaSha
Copy link
Member

github does not follow the redirect.

Where did you found this?

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

@KostyaSha isaacs/github#574

I also ran into this problem myself which motivated me to take time out of my weekend to make this change.

@michaelneale
Copy link
Member

@KostyaSha years of using github with random webhook services that send 302's

@KostyaSha
Copy link
Member

Could you please stop editing your comments? I can't collect everything to follow.

}
return false;
pathInfo = !pathInfo.endsWith("/") ? pathInfo + '/' : pathInfo;
Copy link
Member

Choose a reason for hiding this comment

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

Please place comment here and with link to source of crazy GH API nuances.

if (pathInfo != null && pathInfo.equals(getExclusionPath())) {
chain.doFilter(req, resp);
return true;
if (pathInfo == null || pathInfo.equals("")) {
Copy link
Member

Choose a reason for hiding this comment

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

Use StringUtils.isEmpty() (AFAIR) with static import

@KostyaSha
Copy link
Member

@KostyaSha isaacs/github#574

Second time on this week i shocked how GH handle HTTP.

@KostyaSha
Copy link
Member

@michaelneale blocked me on GH so i have no notifications about his comments.

@KostyaSha KostyaSha reopened this Nov 16, 2016
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.

comments

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

@KostyaSha I've updated the PR with the requested changes.

return false;
}
// Github will not follow redirects https://github.com/isaacs/github/issues/574
pathInfo = !pathInfo.endsWith("/") ? pathInfo + '/' : pathInfo;
Copy link
Member

Choose a reason for hiding this comment

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

please swap arguments to exclude negative logic
pathInfo = pathInfo.endsWith("/") ? pathInfo : pathInfo + '/' ;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return false;
}
// Github will not follow redirects https://github.com/isaacs/github/issues/574
pathInfo = pathInfo.endsWith("/") ? pathInfo : pathInfo + '/';
Copy link
Member

Choose a reason for hiding this comment

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

extra space...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

Thanks @KostyaSha

@i386 i386 force-pushed the more-forgiving-config branch from d25704e to b522499 Compare November 16, 2016 01:24
@KostyaSha
Copy link
Member

Will keep for @lanwen review. 4am. 💤

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

Squashed these commits.

@KostyaSha
Copy link
Member

@i386 no need, github has squash button.

@KostyaSha
Copy link
Member

screenshot 2016-11-16 04 25 40

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.

lgtm

@lanwen
Copy link
Member

lanwen commented Nov 16, 2016

ok guys, you've convinced me

@lanwen lanwen merged commit f784e19 into jenkinsci:master Nov 16, 2016
@lanwen
Copy link
Member

lanwen commented Nov 16, 2016

released as 1.23.1

@michaelneale
Copy link
Member

thanks! @lanwen hahaha yes. I have no idea why github don't follow, but I suspect that it doesn't as it adds latency that is "hidden" (my theory). Anyway, they do what they do, and they are the 400 pound gorrilla so we have to follow their rules ;)

@i386
Copy link
Contributor Author

i386 commented Nov 16, 2016

Thank you!

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.

6 participants