From fa9f60bcd995f8de614c804d5bb3a17d17fbae39 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 25 Dec 2019 12:18:00 +0000 Subject: [PATCH] Console, webapps: CSP improvements i2ptunnel, susidns: Add headers.jsi Console: Remove onload and use nonce for inline scripts where able Version remaining js links --- .../org/klomp/snark/web/I2PSnarkServlet.java | 2 +- apps/i2ptunnel/jsp/edit.jsp | 2 +- apps/i2ptunnel/jsp/headers.jsi | 15 ++++++++++++++ apps/i2ptunnel/jsp/index.jsp | 15 +------------- apps/i2ptunnel/jsp/register.jsp | 11 +--------- apps/i2ptunnel/jsp/ssl.jsp | 11 +--------- apps/i2ptunnel/jsp/wizard.jsp | 15 +------------- .../src/net/i2p/servlet/ErrorServlet.java | 3 ++- apps/routerconsole/jsp/certs.jsp | 3 +-- apps/routerconsole/jsp/config.jsp | 6 +----- apps/routerconsole/jsp/configadvanced.jsp | 6 +----- apps/routerconsole/jsp/configclients.jsp | 7 ++----- apps/routerconsole/jsp/configfamily.jsp | 6 +----- apps/routerconsole/jsp/confighome.jsp | 5 +---- apps/routerconsole/jsp/configi2cp.jsp | 6 +----- apps/routerconsole/jsp/configkeyring.jsp | 5 +---- apps/routerconsole/jsp/configlogging.jsp | 5 +---- apps/routerconsole/jsp/confignet.jsp | 6 +----- apps/routerconsole/jsp/configpeer.jsp | 3 +-- apps/routerconsole/jsp/configplugins.jsp | 6 +----- apps/routerconsole/jsp/configreseed.jsp | 6 +----- apps/routerconsole/jsp/configservice.jsp | 5 +---- apps/routerconsole/jsp/configsidebar.jsp | 5 +---- apps/routerconsole/jsp/configstats.jsp | 5 ++--- apps/routerconsole/jsp/configtunnels.jsp | 6 +----- apps/routerconsole/jsp/configui.jsp | 6 +----- apps/routerconsole/jsp/configupdate.jsp | 5 +---- apps/routerconsole/jsp/configwebapps.jsp | 6 +----- apps/routerconsole/jsp/console.jsp | 6 +----- apps/routerconsole/jsp/csp-unsafe.jsi | 4 ++++ apps/routerconsole/jsp/css.jsi | 6 +++++- apps/routerconsole/jsp/debug.jsp | 3 +-- apps/routerconsole/jsp/dns.jsp | 11 ++++------ apps/routerconsole/jsp/error.jsp | 3 +-- apps/routerconsole/jsp/events.jsp | 4 +--- apps/routerconsole/jsp/graph.jsp | 4 +--- apps/routerconsole/jsp/graphs.jsp | 4 +--- apps/routerconsole/jsp/help.jsp | 3 +-- apps/routerconsole/jsp/home.jsp | 3 +-- apps/routerconsole/jsp/i2ptunnelmgr.jsp | 9 ++++----- apps/routerconsole/jsp/jars.jsp | 4 +--- apps/routerconsole/jsp/jobs.jsp | 4 +--- apps/routerconsole/jsp/logs.jsp | 4 +--- apps/routerconsole/jsp/netdb.jsp | 4 +--- apps/routerconsole/jsp/news.jsp | 4 +--- apps/routerconsole/jsp/nowebapp.jsp | 3 +-- apps/routerconsole/jsp/oldconsole.jsp | 3 +-- apps/routerconsole/jsp/peers.jsp | 4 +--- apps/routerconsole/jsp/profiles.jsp | 4 +--- apps/routerconsole/jsp/proof.jsp | 4 +--- apps/routerconsole/jsp/stats.jsp | 4 +--- apps/routerconsole/jsp/summaryajax.jsi | 4 +++- apps/routerconsole/jsp/torrents.jsp | 11 ++++------ apps/routerconsole/jsp/tunnels.jsp | 4 +--- apps/routerconsole/jsp/viewprofile.jsp | 4 +--- apps/routerconsole/jsp/webmail.jsp | 11 ++++------ apps/routerconsole/jsp/welcome.jsp | 20 +++++-------------- apps/susidns/src/jsp/addressbook.jsp | 4 ++-- apps/susidns/src/jsp/config.jsp | 13 +----------- apps/susidns/src/jsp/details.jsp | 13 +----------- apps/susidns/src/jsp/headers.jsi | 12 +++++++++++ apps/susidns/src/jsp/index.jsp | 2 +- apps/susidns/src/jsp/subscriptions.jsp | 13 +----------- .../src/src/i2p/susi/webmail/WebMail.java | 2 +- 64 files changed, 118 insertions(+), 279 deletions(-) create mode 100644 apps/i2ptunnel/jsp/headers.jsi create mode 100644 apps/routerconsole/jsp/csp-unsafe.jsi create mode 100644 apps/susidns/src/jsp/headers.jsi diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 9dc2b6658..6ed333882 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -414,7 +414,7 @@ public class I2PSnarkServlet extends BasicServlet { resp.setContentType("text/html; charset=UTF-8"); // "no-store, max-age=0" forces all our images to be reloaded on ajax refresh resp.setHeader("Cache-Control", "max-age=86400, no-cache, must-revalidate"); - resp.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'"); + resp.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; form-action 'self'; frame-ancestors 'self'; object-src 'none'"); resp.setDateHeader("Expires", 86400); resp.setHeader("Pragma", "no-cache"); resp.setHeader("X-Frame-Options", "SAMEORIGIN"); diff --git a/apps/i2ptunnel/jsp/edit.jsp b/apps/i2ptunnel/jsp/edit.jsp index e92b2ff56..3b341cc3c 100644 --- a/apps/i2ptunnel/jsp/edit.jsp +++ b/apps/i2ptunnel/jsp/edit.jsp @@ -3,7 +3,7 @@ response.setHeader("X-Frame-Options", "SAMEORIGIN"); // edit pages need script for the delete button 'are you sure' - response.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'"); + response.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; form-action 'self'; frame-ancestors 'self'; object-src 'none'; media-src 'none'"); response.setHeader("X-XSS-Protection", "1; mode=block"); response.setHeader("X-Content-Type-Options", "nosniff"); response.setHeader("Referrer-Policy", "no-referrer"); diff --git a/apps/i2ptunnel/jsp/headers.jsi b/apps/i2ptunnel/jsp/headers.jsi new file mode 100644 index 000000000..1ce03c28f --- /dev/null +++ b/apps/i2ptunnel/jsp/headers.jsi @@ -0,0 +1,15 @@ +<% + // NOTE: Do the header carefully so there is no whitespace before the diff --git a/apps/i2ptunnel/jsp/index.jsp b/apps/i2ptunnel/jsp/index.jsp index 5e98a0a49..c00741d6a 100644 --- a/apps/i2ptunnel/jsp/index.jsp +++ b/apps/i2ptunnel/jsp/index.jsp @@ -1,17 +1,4 @@ -<% - // NOTE: Do the header carefully so there is no whitespace before the <%@page pageEncoding="UTF-8" %><%@page trimDirectiveWhitespaces="true" %><%@page contentType="text/html" import="net.i2p.i2ptunnel.web.IndexBean" diff --git a/apps/i2ptunnel/jsp/register.jsp b/apps/i2ptunnel/jsp/register.jsp index 91bcf7b78..57fa92512 100644 --- a/apps/i2ptunnel/jsp/register.jsp +++ b/apps/i2ptunnel/jsp/register.jsp @@ -1,13 +1,4 @@ -<% - // NOTE: Do the header carefully so there is no whitespace before the <%@page pageEncoding="UTF-8" %><%@page contentType="text/html" import="java.io.InputStream,net.i2p.i2ptunnel.web.EditBean,net.i2p.servlet.RequestWrapper,net.i2p.client.I2PSessionException,net.i2p.client.naming.HostTxtEntry,net.i2p.data.PrivateKeyFile,net.i2p.data.SigningPrivateKey,net.i2p.util.OrderedProperties" %><%@page diff --git a/apps/i2ptunnel/jsp/ssl.jsp b/apps/i2ptunnel/jsp/ssl.jsp index c2427d867..f285eaab8 100644 --- a/apps/i2ptunnel/jsp/ssl.jsp +++ b/apps/i2ptunnel/jsp/ssl.jsp @@ -1,13 +1,4 @@ -<% - // NOTE: Do the header carefully so there is no whitespace before the <%@page pageEncoding="UTF-8" %><%@page contentType="text/html" import="java.io.File,java.io.IOException,net.i2p.crypto.KeyStoreUtil,net.i2p.data.DataHelper,net.i2p.jetty.JettyXmlConfigurationParser" %><%@page diff --git a/apps/i2ptunnel/jsp/wizard.jsp b/apps/i2ptunnel/jsp/wizard.jsp index b02bd4694..d919698b3 100644 --- a/apps/i2ptunnel/jsp/wizard.jsp +++ b/apps/i2ptunnel/jsp/wizard.jsp @@ -1,17 +1,4 @@ -<% - // NOTE: Do the header carefully so there is no whitespace before the <%@page pageEncoding="UTF-8" %><%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean" %> diff --git a/apps/jetty/java/src/net/i2p/servlet/ErrorServlet.java b/apps/jetty/java/src/net/i2p/servlet/ErrorServlet.java index fb4922721..aa0ce5704 100644 --- a/apps/jetty/java/src/net/i2p/servlet/ErrorServlet.java +++ b/apps/jetty/java/src/net/i2p/servlet/ErrorServlet.java @@ -90,7 +90,7 @@ public class ErrorServlet extends HttpServlet { resp.setDateHeader("Expires", 0); resp.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); - resp.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'none'"); + resp.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'none'; form-action 'none'; frame-ancestors 'self'; object-src 'none'; media-src 'none'"); Integer ERROR_CODE = (Integer) req.getAttribute("javax.servlet.error.status_code"); String ERROR_URI = (String) req.getAttribute("javax.servlet.error.request_uri"); String ERROR_MESSAGE = (String) req.getAttribute("javax.servlet.error.message"); @@ -114,6 +114,7 @@ public class ErrorServlet extends HttpServlet { ERROR_URI.endsWith(".ico") || ERROR_URI.endsWith(".svg") || ERROR_URI.endsWith(".txt") || + ERROR_URI.endsWith(".js") || ERROR_URI.endsWith(".css"))) { // keep it simple resp.setContentType("text/plain"); diff --git a/apps/routerconsole/jsp/certs.jsp b/apps/routerconsole/jsp/certs.jsp index c7658af96..0f19f0979 100644 --- a/apps/routerconsole/jsp/certs.jsp +++ b/apps/routerconsole/jsp/certs.jsp @@ -5,9 +5,8 @@ <%@include file="css.jsi" %> <%=intl.title("Certificates")%> - <%@include file="summaryajax.jsi" %> - + <%@include file="summary.jsi" %>

<%=intl._t("Certificates")%>

diff --git a/apps/routerconsole/jsp/config.jsp b/apps/routerconsole/jsp/config.jsp index 3006fa49c..099c95d09 100644 --- a/apps/routerconsole/jsp/config.jsp +++ b/apps/routerconsole/jsp/config.jsp @@ -2,16 +2,12 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("configure bandwidth")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Bandwidth Configuration")%>

diff --git a/apps/routerconsole/jsp/configadvanced.jsp b/apps/routerconsole/jsp/configadvanced.jsp index 16c28c565..0ebf056ab 100644 --- a/apps/routerconsole/jsp/configadvanced.jsp +++ b/apps/routerconsole/jsp/configadvanced.jsp @@ -2,16 +2,12 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config advanced")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - diff --git a/apps/routerconsole/jsp/configclients.jsp b/apps/routerconsole/jsp/configclients.jsp index 45b44a60a..ace704112 100644 --- a/apps/routerconsole/jsp/configclients.jsp +++ b/apps/routerconsole/jsp/configclients.jsp @@ -1,9 +1,9 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> +<%@include file="csp-unsafe.jsi" %> <%=intl.title("config clients")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - " /> diff --git a/apps/routerconsole/jsp/configfamily.jsp b/apps/routerconsole/jsp/configfamily.jsp index 46b683a52..e6200e3f9 100644 --- a/apps/routerconsole/jsp/configfamily.jsp +++ b/apps/routerconsole/jsp/configfamily.jsp @@ -1,16 +1,12 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config router family")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Router Family Configuration")%>

diff --git a/apps/routerconsole/jsp/confighome.jsp b/apps/routerconsole/jsp/confighome.jsp index a621e307d..9b91ba5d6 100644 --- a/apps/routerconsole/jsp/confighome.jsp +++ b/apps/routerconsole/jsp/confighome.jsp @@ -1,7 +1,6 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config home")%> @@ -12,10 +11,8 @@ input.default { visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Home Page Configuration")%>

diff --git a/apps/routerconsole/jsp/configi2cp.jsp b/apps/routerconsole/jsp/configi2cp.jsp index 29eba95fb..cab3dfa0f 100644 --- a/apps/routerconsole/jsp/configi2cp.jsp +++ b/apps/routerconsole/jsp/configi2cp.jsp @@ -1,7 +1,6 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config clients")%> @@ -11,12 +10,9 @@ button span.hide{ } input.default { width: 1px; height: 1px; visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - " /> diff --git a/apps/routerconsole/jsp/configkeyring.jsp b/apps/routerconsole/jsp/configkeyring.jsp index 903c3acf2..b80007781 100644 --- a/apps/routerconsole/jsp/configkeyring.jsp +++ b/apps/routerconsole/jsp/configkeyring.jsp @@ -1,14 +1,11 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config keyring")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Keyring Configuration")%>

diff --git a/apps/routerconsole/jsp/configlogging.jsp b/apps/routerconsole/jsp/configlogging.jsp index c374032d2..906abb6fb 100644 --- a/apps/routerconsole/jsp/configlogging.jsp +++ b/apps/routerconsole/jsp/configlogging.jsp @@ -2,16 +2,13 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config logging")%> - <%@include file="summaryajax.jsi" %> - + - <%@include file="summary.jsi" %>

<%=intl._t("I2P Logging Configuration")%>

diff --git a/apps/routerconsole/jsp/confignet.jsp b/apps/routerconsole/jsp/confignet.jsp index 003eb63c3..2c93d86f0 100644 --- a/apps/routerconsole/jsp/confignet.jsp +++ b/apps/routerconsole/jsp/confignet.jsp @@ -1,16 +1,12 @@ <%@page contentType="text/html" %> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config networking")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Network Configuration")%>

diff --git a/apps/routerconsole/jsp/configpeer.jsp b/apps/routerconsole/jsp/configpeer.jsp index b433027e2..a222c005e 100644 --- a/apps/routerconsole/jsp/configpeer.jsp +++ b/apps/routerconsole/jsp/configpeer.jsp @@ -4,9 +4,8 @@ <%@include file="css.jsi" %> <%=intl.title("config peers")%> - <%@include file="summaryajax.jsi" %> - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Peer Configuration")%>

diff --git a/apps/routerconsole/jsp/configplugins.jsp b/apps/routerconsole/jsp/configplugins.jsp index 27adbd632..c6bb9ca50 100644 --- a/apps/routerconsole/jsp/configplugins.jsp +++ b/apps/routerconsole/jsp/configplugins.jsp @@ -1,7 +1,6 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config plugins")%> @@ -11,12 +10,9 @@ button span.hide{ } input.default { width: 1px; height: 1px; visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - " /> diff --git a/apps/routerconsole/jsp/configreseed.jsp b/apps/routerconsole/jsp/configreseed.jsp index 728d3862b..e75301ab5 100644 --- a/apps/routerconsole/jsp/configreseed.jsp +++ b/apps/routerconsole/jsp/configreseed.jsp @@ -1,16 +1,12 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config reseeding")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Reseeding Configuration")%>

diff --git a/apps/routerconsole/jsp/configservice.jsp b/apps/routerconsole/jsp/configservice.jsp index eeccee022..940635a6b 100644 --- a/apps/routerconsole/jsp/configservice.jsp +++ b/apps/routerconsole/jsp/configservice.jsp @@ -1,14 +1,11 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config service")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Service Configuration")%>

diff --git a/apps/routerconsole/jsp/configsidebar.jsp b/apps/routerconsole/jsp/configsidebar.jsp index ea071841b..ff2d01699 100644 --- a/apps/routerconsole/jsp/configsidebar.jsp +++ b/apps/routerconsole/jsp/configsidebar.jsp @@ -1,7 +1,6 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config sidebar")%> @@ -12,10 +11,8 @@ input.default { visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Sidebar Configuration")%>

diff --git a/apps/routerconsole/jsp/configstats.jsp b/apps/routerconsole/jsp/configstats.jsp index dc65311d0..7dd5bfc21 100644 --- a/apps/routerconsole/jsp/configstats.jsp +++ b/apps/routerconsole/jsp/configstats.jsp @@ -2,14 +2,13 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> +<%@include file="csp-unsafe.jsi" %> <%=intl.title("config stats")%> - <%@include file="summaryajax.jsi" %> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Tunnel Configuration")%>

diff --git a/apps/routerconsole/jsp/configui.jsp b/apps/routerconsole/jsp/configui.jsp index 3f8b3a6e8..6caccc6d0 100644 --- a/apps/routerconsole/jsp/configui.jsp +++ b/apps/routerconsole/jsp/configui.jsp @@ -2,7 +2,6 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config UI")%> @@ -13,12 +12,9 @@ input.default { visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - diff --git a/apps/routerconsole/jsp/configupdate.jsp b/apps/routerconsole/jsp/configupdate.jsp index 0401fa017..ae6b0c450 100644 --- a/apps/routerconsole/jsp/configupdate.jsp +++ b/apps/routerconsole/jsp/configupdate.jsp @@ -2,14 +2,11 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config update")%> - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %>

<%=intl._t("I2P Update Configuration")%>

diff --git a/apps/routerconsole/jsp/configwebapps.jsp b/apps/routerconsole/jsp/configwebapps.jsp index 2b563283c..f379a12c6 100644 --- a/apps/routerconsole/jsp/configwebapps.jsp +++ b/apps/routerconsole/jsp/configwebapps.jsp @@ -1,7 +1,6 @@ <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("config webapps")%> @@ -11,12 +10,9 @@ button span.hide{ } input.default { width: 1px; height: 1px; visibility: hidden; } - <%@include file="summaryajax.jsi" %> - - + <%@include file="summary.jsi" %> - " /> diff --git a/apps/routerconsole/jsp/console.jsp b/apps/routerconsole/jsp/console.jsp index 3ed8353ce..446e51b85 100644 --- a/apps/routerconsole/jsp/console.jsp +++ b/apps/routerconsole/jsp/console.jsp @@ -2,19 +2,15 @@ <%@page trimDirectiveWhitespaces="true"%> <%@page pageEncoding="UTF-8"%> - <%@include file="css.jsi" %> <%=intl.title("home")%> - <%@include file="summaryajax.jsi" %> - + <% String consoleNonce = net.i2p.router.web.CSSHelper.getNonce(); %> - <%@include file="summary.jsi" %> -

<%=intl._t("I2P Router Console")%>

<% diff --git a/apps/routerconsole/jsp/csp-unsafe.jsi b/apps/routerconsole/jsp/csp-unsafe.jsi new file mode 100644 index 000000000..720a26a17 --- /dev/null +++ b/apps/routerconsole/jsp/csp-unsafe.jsi @@ -0,0 +1,4 @@ +<% + // Add this AFTER css.jsi if there's any onclick attributes in the page + response.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; form-action 'self'; frame-ancestors 'self'; object-src 'none'; media-src 'none'"); +%> diff --git a/apps/routerconsole/jsp/css.jsi b/apps/routerconsole/jsp/css.jsi index 2687e532e..0550b226f 100644 --- a/apps/routerconsole/jsp/css.jsi +++ b/apps/routerconsole/jsp/css.jsi @@ -34,10 +34,14 @@ images/favicon.ico"><% response.setHeader("Accept-Ranges", "none"); + String cspNonce = Integer.toHexString(net.i2p.util.RandomSource.getInstance().nextInt()); + // clickjacking if (intl.shouldSendXFrame()) { response.setHeader("X-Frame-Options", "SAMEORIGIN"); - response.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'"); + // unsafe-inline is a fallback for browsers not supporting nonce + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src + response.setHeader("Content-Security-Policy", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'nonce-" + cspNonce + "'; form-action 'self'; frame-ancestors 'self'; object-src 'none'; media-src 'none'"); response.setHeader("X-XSS-Protection", "1; mode=block"); response.setHeader("X-Content-Type-Options", "nosniff"); } diff --git a/apps/routerconsole/jsp/debug.jsp b/apps/routerconsole/jsp/debug.jsp index c93986352..cdbaa8456 100644 --- a/apps/routerconsole/jsp/debug.jsp +++ b/apps/routerconsole/jsp/debug.jsp @@ -9,9 +9,8 @@ %> I2P Router Console - Debug <%@include file="css.jsi" %> - <%@include file="summaryajax.jsi" %> - + <%@include file="summary.jsi" %>

Router Debug

diff --git a/apps/routerconsole/jsp/dns.jsp b/apps/routerconsole/jsp/dns.jsp index 6a3021424..3826be399 100644 --- a/apps/routerconsole/jsp/dns.jsp +++ b/apps/routerconsole/jsp/dns.jsp @@ -21,24 +21,21 @@ } else { %> - <%@include file="css.jsi" %> +<%@include file="csp-unsafe.jsi" %> <%=intl.title("addressbook")%> - - + <%@include file="summaryajax.jsi" %> - - - + <%@include file="summary.jsi" %> -

<%=intl._t("I2P Addressbook")%> ">images/newtab.png" />