8000 [SECURITY-798] Prevent open redirect · jpigree/github-oauth-plugin@a77729d · GitHub
[go: up one dir, main page]

Skip to content

Commit a77729d

Browse files
committed
[SECURITY-798] Prevent open redirect
- use the from in priority as it is managed directly inside the main layout - otherwise fallback to the referer header value - in all case, check the URL is either relative or inside Jenkins
1 parent fae1a85 commit a77729d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 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;
@@ -333,9 +334,18 @@ public String getOauthScopes() {
333334
return oauthScopes;
334335
}
335336

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

340350
Set<String> scopes = new HashSet<>();
341351
for (GitHubOAuthScope s : getJenkins().getExtensionList(GitHubOAuthScope.class)) {

0 commit comments

Comments
 (0)
0