import java.util.Locale;
import java.util.Map;
import java.util.Properties;
+import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.dbObjects.User;
import org.cacert.gigi.localisation.Language;
import org.cacert.gigi.output.Form.CSRFException;
import org.cacert.gigi.output.Menu;
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
boolean isSecure = req.getServerPort() == ServerConstants.getSecurePort();
addXSSHeaders(resp, isSecure);
- // 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;
+ }
HttpSession hs = req.getSession();
if (req.getParameter("lang") != null) {
Locale l = Language.getLocaleFromString(req.getParameter("lang"));
return;
}
HashMap<String, Object> vars = new HashMap<String, Object>();
-
- resp.setContentType("text/html; charset=utf-8");
Outputable content = new Outputable() {
@Override
vars.put("static", getStaticTemplateVar(isSecure));
vars.put("year", Calendar.getInstance().get(Calendar.YEAR));
vars.put("content", content);
+ resp.setContentType("text/html; charset=utf-8");
baseTemplate.output(resp.getWriter(), Page.getLanguage(req), vars);
} else {
resp.sendError(404, "Page not found.");