- // if (req.getHeader("Origin") != null) {
- // resp.getWriter().println("No cross domain access allowed.");
- // return;
- // }
+ // Firefox only sends this, if it's a cross domain access; safari sends
+ // it always
+ String originHeader = req.getHeader("Origin");
+ if (originHeader != null //
+ &&
+ !(originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getWwwHostNamePortSecure()) + "(/.*|)") || //
+ originHeader.matches("^" + Pattern.quote("http://" + ServerConstants.getWwwHostNamePort()) + "(/.*|)") || //
+ originHeader.matches("^" + Pattern.quote("https://" + ServerConstants.getSecureHostNamePort()) + "(/.*|)"))) {
+ resp.setContentType("text/html; charset=utf-8");
+ resp.getWriter().println("<html><head><title>Alert</title></head><body>No cross domain access allowed.<br/><b>If you don't know why you're seeing this you may have been fished! Please change your password immediately!</b></body></html>");
+ return;
+ }