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

Adding secure tag to cookie #12522

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/java/teammates/ui/webapi/GetAuthInfoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
/**
* Action: gets user authentication information.
*
* <p>This does not log in or log out the user.
* <p>
* This does not log in or log out the user.
*/
class GetAuthInfoAction extends Action {

Expand Down Expand Up @@ -42,26 +43,26 @@ public JsonResult execute() {
createLoginUrl(frontendUrl, Const.WebPageURIs.STUDENT_HOME_PAGE),
createLoginUrl(frontendUrl, Const.WebPageURIs.INSTRUCTOR_HOME_PAGE),
createLoginUrl(frontendUrl, Const.WebPageURIs.ADMIN_HOME_PAGE),
createLoginUrl(frontendUrl, Const.WebPageURIs.MAINTAINER_HOME_PAGE)
);
createLoginUrl(frontendUrl, Const.WebPageURIs.MAINTAINER_HOME_PAGE));
} else {
output = new AuthInfo(
createLoginUrl(frontendUrl, nextUrl),
createLoginUrl(frontendUrl, nextUrl),
createLoginUrl(frontendUrl, nextUrl),
createLoginUrl(frontendUrl, nextUrl)
);
createLoginUrl(frontendUrl, nextUrl));
}
} else {
output = new AuthInfo(userInfo, authType == AuthType.MASQUERADE);
}

String csrfToken = StringHelper.encrypt(req.getSession().getId());
String existingCsrfToken = HttpRequestHelper.getCookieValueFromRequest(req, Const.SecurityConfig.CSRF_COOKIE_NAME);
String existingCsrfToken = HttpRequestHelper.getCookieValueFromRequest(req,
Const.SecurityConfig.CSRF_COOKIE_NAME);
if (csrfToken.equals(existingCsrfToken)) {
return new JsonResult(output);
}
Cookie csrfTokenCookie = new Cookie(Const.SecurityConfig.CSRF_COOKIE_NAME, csrfToken);
csrfTokenCookie.setSecure(true);
csrfTokenCookie.setPath("/");
List<Cookie> cookieList = Collections.singletonList(csrfTokenCookie);
return new JsonResult(output, cookieList);
Expand Down
Loading