Skip to content

Commit da2cc3d

Browse files
yadvrPearl Dsilva
authored andcommitted
server: Purge all cookies on logout, set /client path on login (apache#4176)
This will purge all the cookies on logout including multiple sessionkey cookies if passed. On login, this will restrict sessionkey cookie (httponly) to the / path. Fixes apache#4136 Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
1 parent fd21320 commit da2cc3d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static void setupSamlUserCookies(final LoginCmdResponse loginResponse, fi
280280
resp.addCookie(new Cookie("timezone", URLEncoder.encode(timezone, HttpUtils.UTF_8)));
281281
}
282282
resp.addCookie(new Cookie("userfullname", URLEncoder.encode(loginResponse.getFirstName() + " " + loginResponse.getLastName(), HttpUtils.UTF_8).replace("+", "%20")));
283-
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));
283+
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly;Path=/", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));
284284
}
285285

286286
/**

server/src/main/java/com/cloud/api/ApiServlet.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
213213
try {
214214
responseString = apiAuthenticator.authenticate(command, params, session, remoteAddress, responseType, auditTrailSb, req, resp);
215215
if (session != null && session.getAttribute(ApiConstants.SESSIONKEY) != null) {
216-
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, session.getAttribute(ApiConstants.SESSIONKEY)));
216+
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly;Path=/", ApiConstants.SESSIONKEY, session.getAttribute(ApiConstants.SESSIONKEY)));
217217
}
218218
} catch (ServerApiException e) {
219219
httpResponseCode = e.getErrorCode().getHttpCode();
@@ -238,9 +238,14 @@ void processRequestInContext(final HttpServletRequest req, final HttpServletResp
238238
} catch (final IllegalStateException ignored) {
239239
}
240240
}
241-
Cookie sessionKeyCookie = new Cookie(ApiConstants.SESSIONKEY, "");
242-
sessionKeyCookie.setMaxAge(0);
243-
resp.addCookie(sessionKeyCookie);
241+
final Cookie[] cookies = req.getCookies();
242+
if (cookies != null) {
243+
for (final Cookie cookie : cookies) {
244+
cookie.setValue("");
245+
cookie.setMaxAge(0);
246+
resp.addCookie(cookie);
247+
}
248+
}
244249
}
245250
HttpUtils.writeHttpResponse(resp, responseString, httpResponseCode, responseType, ApiServer.JSONcontentType.value());
246251
return;

0 commit comments

Comments
 (0)