Django製の
で、
警告に
前提
Wicket × Dropwizard で
まだ
環境情報
OS Version
sw_vers ---------------------------- ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G1108 ----------------------------
Wicket version 7.6.0です。
<dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket-core</artifactId> <version>7.6.0</version> </dependency>
Dropwizard version 1.0.6です。
<dependency> <groupId>io.dropwizard</groupId> <artifactId>dropwizard-core</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>io.dropwizard</groupId> <artifactId>dropwizard-servlets</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>io.dropwizard</groupId> <artifactId>dropwizard-assets</artifactId> <version>1.0.6</version> </dependency>
検証の 内容
OWASP ZAP
はデフォルト設定で、 プロキシ設定なしの、 標準モードで 実行
インストールして起動すると 表示される クイックスタートに、
localhost のアプリケーションの URL を 入力するだけです。 検証対象の
URL プロトコルは HTTP
localhost での検証となり、 HTTPS での 検証は できて おりません。 TOP 画面に
入力項目の 有無 入力項目は ありません
検証結果に 対しての 対応方針
- 脆弱性が
見つかり、 Wicket でも、 Dropwizard でも 対応できる 場合は、 Wicket側で 対応する。
Dropwizard が、HTTP サーバ× AP サーバの レイヤとなるため、 本来 Dropwizard 側での 対応が 良い気は します。
個人的な興味から、 Wicket 側に 実装します。
アプリケーションの TOP URL を 指定した 検証結果
以下の
X-Frame-Options ヘッダの
欠如 Webブラウザの
XSS防止機能が 有効に なっていません。 X-Content-Type-Optionsヘッダの
設定ミス Cross-Domain JavaScript Source File Inclusion
Cookie No HttpOnly Flag
対応方法
参考
wicket の
Wicket で、 HttpResponseHeader を 設定する
これで
X-Frame-Options ヘッダの
欠如 Web ブラウザの
XSS 防止機能が 有効に なっていません。 X-Content-Type-Options ヘッダの
設定ミス
wicket の
response header の
HttpHeaderAddingRequestCycleListener.java
import org.apache.wicket.request.cycle.AbstractRequestCycleListener; import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.http.WebResponse; /** * HttpHeaderAddingRequestCycleListener */ public class HttpHeaderAddingRequestCycleListener extends AbstractRequestCycleListener { private boolean isDeployment; /** * Construct. * * @param isDeployment */ public HttpHeaderAddingRequestCycleListener(boolean isDeployment) { this.isDeployment = isDeployment; } @Override public void onEndRequest(RequestCycle cycle) { WebResponse response = (WebResponse) cycle.getResponse(); response.setHeader("X-XSS-Protection", "1; mode=block"); response.setHeader("X-Content-Type-Options", "nosniff"); response.setHeader("X-Frame-Options", "sameorigin"); // In the deployment mode, the Https related header is set if (isDeployment) { response.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload"); response.setHeader("Content-Security-Policy", "default-src https:"); } } }
説明 以下の
Headerに ついては、 localhostで、 http通信時は 問題が ありますので、
Deploymentモードの場合のみ、 出力するようにしました。 response.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload"); response.setHeader("Content-Security-Policy", "default-src https:");
Applicationクラスでは
getRequestCycleListeners().add(new HttpHeaderAddingRequestCycleListener(usesDeploymentConfig()));
Dropwizard で、 HttpResponseHeader を 設定する
- X-Content-Type-Options ヘッダの
設定ミス
は静的コンテンツ類でも
静的コンテンツ類の
この
こちらは
以下、
CORS に
対応させる ための Servlet Filter - seratch’s weblog in Japanese NoSniffAssetBundle.java
import io.dropwizard.assets.AssetsBundle; import io.dropwizard.setup.Environment; import org.eclipse.jetty.servlet.FilterHolder; import javax.servlet.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.EnumSet; /** * NoSniffAssetBundle */ public class NoSniffAssetBundle extends AssetsBundle { public NoSniffAssetBundle() { this("/assets", "/assets", "index.htm", "assets"); } public NoSniffAssetBundle(String path) { this(path, path, "index.htm", "assets"); } public NoSniffAssetBundle(String resourcePath, String uriPath) { this(resourcePath, uriPath, "index.htm", "assets"); } public NoSniffAssetBundle(String resourcePath, String uriPath, String indexFile) { this(resourcePath, uriPath, indexFile, "assets"); } public NoSniffAssetBundle(String resourcePath, String uriPath, String indexFile, String assetsName) { super(resourcePath, uriPath, indexFile, assetsName); } public void run(Environment environment) { super.run(environment); environment.getApplicationContext() .addFilter(newNoSniffResponseFilterHolder(), getUriPath(), EnumSet.of(DispatcherType.ASYNC, DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR)); } private FilterHolder newNoSniffResponseFilterHolder() { FilterHolder holder = new FilterHolder(); holder.setName("NoSniffResponseFilter"); holder.setFilter(new Filter() { @Override public void init(FilterConfig filterConfig) throws ServletException { //Do Nothing... } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("X-Content-Type-Options", "nosniff"); chain.doFilter(request, response); } @Override public void destroy() { //Do Nothing... } }); return holder; } }
Cross-Domain JavaScript Source File Inclusion
外部サイトの
こちらの
Cookie No HttpOnly Flag
これは、jsessionid
が
Dropwizard (とSessionManager
のsetHttpOnly()
で
設定が
以下のtrue
を
sessionManager.setHttpOnly(true); env.servlets().setSessionHandler(new SessionHandler(sessionManager));
上記対処で、
- Cross-Domain JavaScript Source File Inclusion
のみに
以上です。
コメント