Add checks for cookieDomain validity (bug 219)
http://helma.org/bugs/show_bug.cgi?id=219
This commit is contained in:
parent
8a5e24a574
commit
85401cd71f
1 changed files with 27 additions and 16 deletions
|
@ -49,6 +49,8 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
uploadLimit = upstr == null ? 1024 : Integer.parseInt (upstr);
|
uploadLimit = upstr == null ? 1024 : Integer.parseInt (upstr);
|
||||||
// get cookie domain
|
// get cookie domain
|
||||||
cookieDomain = init.getInitParameter ("cookieDomain");
|
cookieDomain = init.getInitParameter ("cookieDomain");
|
||||||
|
if (cookieDomain != null)
|
||||||
|
cookieDomain = cookieDomain.toLowerCase();
|
||||||
// get default encoding
|
// get default encoding
|
||||||
defaultEncoding = init.getInitParameter ("charset");
|
defaultEncoding = init.getInitParameter ("charset");
|
||||||
debug = ("true".equalsIgnoreCase (init.getInitParameter ("debug")));
|
debug = ("true".equalsIgnoreCase (init.getInitParameter ("debug")));
|
||||||
|
@ -73,7 +75,6 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
protected void execute (HttpServletRequest request,
|
protected void execute (HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
byte method) {
|
byte method) {
|
||||||
Cookie[] cookies = request.getCookies();
|
|
||||||
|
|
||||||
RequestTrans reqtrans = new RequestTrans (method);
|
RequestTrans reqtrans = new RequestTrans (method);
|
||||||
// get app and path from original request path
|
// get app and path from original request path
|
||||||
|
@ -120,11 +121,12 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read cookies
|
// read cookies
|
||||||
if (cookies != null) {
|
Cookie[] reqCookies = request.getCookies();
|
||||||
for (int i=0; i < cookies.length;i++) try {
|
if (reqCookies != null) {
|
||||||
|
for (int i=0; i < reqCookies.length;i++) try {
|
||||||
// get Cookies
|
// get Cookies
|
||||||
String nextKey = cookies[i].getName ();
|
String nextKey = reqCookies[i].getName ();
|
||||||
String nextPart = cookies[i].getValue ();
|
String nextPart = reqCookies[i].getValue ();
|
||||||
if ("HopSession".equals (nextKey))
|
if ("HopSession".equals (nextKey))
|
||||||
reqtrans.session = nextPart;
|
reqtrans.session = nextPart;
|
||||||
else
|
else
|
||||||
|
@ -157,6 +159,14 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
if (remotehost != null)
|
if (remotehost != null)
|
||||||
reqtrans.set ("http_remotehost", remotehost);
|
reqtrans.set ("http_remotehost", remotehost);
|
||||||
|
|
||||||
|
// get the cookie domain to use for this response, if any.
|
||||||
|
String resCookieDomain = cookieDomain;
|
||||||
|
if (resCookieDomain != null) {
|
||||||
|
// check if cookieDomain is valid for this response.
|
||||||
|
// (note: cookieDomain is guaranteed to be lower case)
|
||||||
|
if (host != null && host.toLowerCase().indexOf (cookieDomain) == -1)
|
||||||
|
resCookieDomain = null;
|
||||||
|
}
|
||||||
// check if we need to create a session id. also handle the
|
// check if we need to create a session id. also handle the
|
||||||
// case that the session id doesn't match the remote host address
|
// case that the session id doesn't match the remote host address
|
||||||
if (reqtrans.session == null || !reqtrans.session.startsWith (remotehost)) {
|
if (reqtrans.session == null || !reqtrans.session.startsWith (remotehost)) {
|
||||||
|
@ -165,8 +175,8 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
System.currentTimeMillis (), 36);
|
System.currentTimeMillis (), 36);
|
||||||
Cookie c = new Cookie("HopSession", reqtrans.session);
|
Cookie c = new Cookie("HopSession", reqtrans.session);
|
||||||
c.setPath ("/");
|
c.setPath ("/");
|
||||||
if (cookieDomain != null)
|
if (resCookieDomain != null)
|
||||||
c.setDomain (cookieDomain);
|
c.setDomain (resCookieDomain);
|
||||||
response.addCookie(c);
|
response.addCookie(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +193,16 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
reqtrans.path = getPathInfo (request);
|
reqtrans.path = getPathInfo (request);
|
||||||
ResponseTrans restrans = execute (reqtrans);
|
ResponseTrans restrans = execute (reqtrans);
|
||||||
|
|
||||||
|
// set cookies
|
||||||
|
int ncookies = restrans.countCookies();
|
||||||
|
if (restrans.countCookies() > 0) {
|
||||||
|
CookieTrans[] resCookies = restrans.getCookies ();
|
||||||
|
for (int i = 0; i < resCookies.length; i++) try {
|
||||||
|
Cookie c = resCookies[i].getCookie ("/", resCookieDomain);
|
||||||
|
response.addCookie(c);
|
||||||
|
} catch (Exception ignore) {}
|
||||||
|
}
|
||||||
|
// write response
|
||||||
writeResponse (request, response, restrans);
|
writeResponse (request, response, restrans);
|
||||||
|
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
|
@ -210,15 +230,6 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
HttpServletResponse res,
|
HttpServletResponse res,
|
||||||
ResponseTrans hopres) {
|
ResponseTrans hopres) {
|
||||||
|
|
||||||
int ncookies = hopres.countCookies();
|
|
||||||
if (hopres.countCookies() > 0) {
|
|
||||||
CookieTrans[] cookies = hopres.getCookies ();
|
|
||||||
for (int i = 0; i < cookies.length; i++) try {
|
|
||||||
Cookie c = cookies[i].getCookie ("/", cookieDomain);
|
|
||||||
res.addCookie(c);
|
|
||||||
} catch (Exception ignore) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hopres.getETag() != null) {
|
if (hopres.getETag() != null) {
|
||||||
res.setHeader ("ETag", hopres.getETag());
|
res.setHeader ("ETag", hopres.getETag());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue