note: "The default access restriction has been elevated from NONE to PUSH and anonymous push access has been disabled."
html: ~
text: ~
- security: ~
+ security:
+ - ''issue-361: Cookies were not reset on administrative password change of a user account.
+ This allowed accounts with changed passwords to continue authenticating.
+ Cookies are now reset on password changes, they are validated on each page request,
+ AND they will now expire 7 days after generation.
+ ''
fixes:
- Fixed incorrect tagger attribution in the dashboard (issue-276)
- Fixed support for implied SSH urls in web.otherUrls (issue-311)
}\r
read();\r
originalUser = users.remove(username.toLowerCase());\r
+ if (originalUser != null) {\r
+ cookies.remove(originalUser.cookie);\r
+ }\r
users.put(model.username.toLowerCase(), model);\r
// null check on "final" teams because JSON-sourced UserModel\r
// can have a null teams object\r
return false;\r
}\r
\r
+ // change the cookie\r
+ user.cookie = StringUtils.getSHA1(user.username + password);\r
+\r
String type = settings.get(Keys.realm.passwordStorage).getString("md5");\r
if (type.equalsIgnoreCase("md5")) {\r
// store MD5 digest of password\r
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
return null;
}
+ UserModel user = null;
+
// try to authenticate by cookie
- UserModel user = authenticate(httpRequest.getCookies());
- if (user != null) {
- flagWicketSession(AuthenticationType.COOKIE);
- logger.debug(MessageFormat.format("{0} authenticated by cookie from {1}",
+ String cookie = getCookie(httpRequest);
+ if (!StringUtils.isEmpty(cookie)) {
+ user = userManager.getUserModel(cookie.toCharArray());
+ if (user != null) {
+ flagWicketSession(AuthenticationType.COOKIE);
+ logger.debug(MessageFormat.format("{0} authenticated by cookie from {1}",
user.username, httpRequest.getRemoteAddr()));
- return user;
+ return user;
+ }
}
// try to authenticate by BASIC
return null;
}
- /**
- * Authenticate a user based on their cookie.
- *
- * @param cookies
- * @return a user object or null
- */
- protected UserModel authenticate(Cookie[] cookies) {
- if (settings.getBoolean(Keys.web.allowCookieAuthentication, true)) {
- if (cookies != null && cookies.length > 0) {
- for (Cookie cookie : cookies) {
- if (cookie.getName().equals(Constants.NAME)) {
- String value = cookie.getValue();
- return userManager.getUserModel(value.toCharArray());
- }
- }
- }
- }
- return null;
- }
-
protected void flagWicketSession(AuthenticationType authenticationType) {
RequestCycle requestCycle = RequestCycle.get();
if (requestCycle != null) {
return user;
}
+ /**
+ * Returns the Gitlbit cookie in the request.
+ *
+ * @param request
+ * @return the Gitblit cookie for the request or null if not found
+ */
+ @Override
+ public String getCookie(HttpServletRequest request) {
+ if (settings.getBoolean(Keys.web.allowCookieAuthentication, true)) {
+ Cookie[] cookies = request.getCookies();
+ if (cookies != null && cookies.length > 0) {
+ for (Cookie cookie : cookies) {
+ if (cookie.getName().equals(Constants.NAME)) {
+ String value = cookie.getValue();
+ return value;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
/**
* Sets a cookie for the specified user.
*
} else {
// create real cookie
userCookie = new Cookie(Constants.NAME, cookie);
- userCookie.setMaxAge(Integer.MAX_VALUE);
+ // expire the cookie in 7 days
+ userCookie.setMaxAge((int) TimeUnit.DAYS.toSeconds(7));
}
}
userCookie.setPath("/");
return user;
}
+ @Override
+ public String getCookie(HttpServletRequest request) {
+ return authenticationManager.getCookie(request);
+ }
+
@Override
public void setCookie(HttpServletResponse response, UserModel user) {
authenticationManager.setCookie(response, user);
*/
UserModel authenticate(String username, char[] password);
+ /**
+ * Returns the Gitlbit cookie in the request.
+ *
+ * @param request
+ * @return the Gitblit cookie for the request or null if not found
+ */
+ String getCookie(HttpServletRequest request);
+
/**
* Sets a cookie for the specified user.
*
return;\r
}\r
\r
+ // change the cookie\r
+ userModel.cookie = StringUtils.getSHA1(userModel.username + password);\r
+\r
// Optionally store the password MD5 digest.\r
String type = app().settings().getString(Keys.realm.passwordStorage, "md5");\r
if (type.equalsIgnoreCase("md5")) {\r
package com.gitblit.wicket.pages;\r
\r
import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
\r
import org.apache.wicket.PageParameters;\r
import org.apache.wicket.markup.html.WebPage;\r
\r
import com.gitblit.Keys;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebApp;\r
import com.gitblit.wicket.GitBlitWebSession;\r
\r
// already have a session, refresh usermodel to pick up\r
// any changes to permissions or roles (issue-186)\r
UserModel user = app().users().getUserModel(session.getUser().username);\r
+\r
+ // validate cookie during session (issue-361)\r
+ if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, true)) {\r
+ HttpServletRequest request = ((WebRequest) getRequestCycle().getRequest())\r
+ .getHttpServletRequest();\r
+ String requestCookie = app().authentication().getCookie(request);\r
+ if (!StringUtils.isEmpty(requestCookie) && !StringUtils.isEmpty(user.cookie)) {\r
+ if (!requestCookie.equals(user.cookie)) {\r
+ // cookie was changed during our session\r
+ HttpServletResponse response = ((WebResponse) getRequestCycle().getResponse())\r
+ .getHttpServletResponse();\r
+ app().authentication().logout(response, user);\r
+ session.setUser(null);\r
+ session.invalidateNow();\r
+ return;\r
+ }\r
+ }\r
+ }\r
session.setUser(user);\r
return;\r
}\r