8000 Merge security issues · jpigree/github-oauth-plugin@1171f87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1171f87

Browse files
committed
Merge security issues
Merge remote-tracking branches 'origin/PR-1', 'origin/PR-2' and 'origin/PR-3' into 0.29.x - SECURITY-602 - SECURITY-797 - SECURITY-798
4 parents fae1a85 + 7a75a47 + a77729d + 10d173f commit 1171f87

File tree

3 files changed

+386
-4
lines changed

3 files changed

+386
-4
lines changed

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)
0