Skip to content

Commit 8c4afe8

Browse files
committed
Merge remote-tracking branch 'cert/0.29.x' into next-release
2 parents 715be7a + 9a62d4f commit 8c4afe8

File tree

4 files changed

+387
-5
lines changed

4 files changed

+387
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<groupId>org.jenkins-ci.plugins</groupId>
4141
<artifactId>github-oauth</artifactId>
42-
<version>0.30-SNAPSHOT</version>
42+
<version>0.31-SNAPSHOT</version>
4343
<name>GitHub Authentication plugin</name>
4444
<description>A Jenkins authentication plugin that delegates to GitHub. We also implement an Authorization Strategy that uses the acquired OAuth token to interact with the GitHub API to determine a user's level of access to Jenkins.</description>
4545
<packaging>hpi</packaging>

src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ of this software and associated documentation files (the "Software"), to deal
7979
import org.kohsuke.stapler.HttpRedirect;
8080
import org.kohsuke.stapler.HttpResponse;
8181
import org.kohsuke.stapler.HttpResponses;
82+
import org.kohsuke.stapler.QueryParameter;
8283
import org.kohsuke.stapler.StaplerRequest;
8384
import org.springframework.dao.DataAccessException;
8485
import org.springframework.dao.DataRetrievalFailureException;
@@ -93,6 +94,7 @@ of this software and associated documentation files (the "Software"), to deal
9394
import java.util.logging.Logger;
9495
import javax.annotation.Nonnull;
9596
import javax.annotation.Nullable;
97+
import javax.servlet.http.HttpSession;
9698

9799
/**
98100
*
@@ -333,9 +335,18 @@ public String getOauthScopes() {
333335
return oauthScopes;
334336
}
335337

336-
public HttpResponse doCommenceLogin(StaplerRequest request, @Header("Referer") final String referer)
338+
public HttpResponse doCommenceLogin(StaplerRequest request, @QueryParameter String from, @Header("Referer") final String referer)
337339
throws IOException {
338-
request.getSession().setAttribute(REFERER_ATTRIBUTE,referer);
340+
String redirectOnFinish;
341+
if (from != null && Util.isSafeToRedirectTo(from)) {
342+
redirectOnFinish = from;
343+
} else if (referer != null && (referer.startsWith(Jenkins.getInstance().getRootUrl()) || Util.isSafeToRedirectTo(referer))) {
344+
redirectOnFinish = referer;
345+
} else {
346+
redirectOnFinish = Jenkins.getInstance().getRootUrl();
347+
}
348+
349+
request.getSession().setAttribute(REFERER_ATTRIBUTE, redirectOnFinish);
339350

340351
Set<String> scopes = new HashSet<>();
341352
for (GitHubOAuthScope s : getJenkins().getExtensionList(GitHubOAuthScope.class)) {
@@ -361,6 +372,7 @@ public HttpResponse doCommenceLogin(StaplerRequest request, @Header("Referer") f
361372
public HttpResponse doFinishLogin(StaplerRequest request)
362373
throws IOException {
363374
String code = request.getParameter("code");
375+
String referer = (String)request.getSession().getAttribute(REFERER_ATTRIBUTE);
364376

365377
if (code == null || code.trim().length() == 0) {
366378
Log.info("doFinishLogin: missing code.");
@@ -372,6 +384,14 @@ public HttpResponse doFinishLogin(StaplerRequest request)
372384
if (accessToken != null && accessToken.trim().length() > 0) {
373385
// only set the access token if it exists.
374386
GithubAuthenticationToken auth = new GithubAuthenticationToken(accessToken, getGithubApiUri());
387+
388+
HttpSession session = request.getSession(false);
389+
if(session != null){
390+
// avoid session fixation
391+
session.invalidate();
392+
}
393+
request.getSession(true);
394+
375395
SecurityContextHolder.getContext().setAuthentication(auth);
376396

377397
GHMyself self = auth.getMyself();
@@ -409,7 +429,6 @@ public HttpResponse doFinishLogin(StaplerRequest request)
409429
Log.info("Github did not return an access token.");
410430
}
411431

412-
String referer = (String)request.getSession().getAttribute(REFERER_ATTRIBUTE);
413432
if (referer!=null) return HttpResponses.redirectTo(referer);
414433
return HttpResponses.redirectToContextRoot(); // referer should be always there, but be defensive
415434
}

src/main/resources/org/jenkinsci/plugins/GithubSecurityRealm/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</f:entry>
1818

1919
<f:entry title="Client Secret" field="clientSecret" help="/plugin/github-oauth/help/realm/client-secret-help.html">
20-
<f:textbox />
20+
<f:password />
2121
</f:entry>
2222

2323
<f:entry title="OAuth Scope(s)" field="oauthScopes" help="/plugin/github-oauth/help/realm/oauth-scopes-help.html">

0 commit comments

Comments
 (0)