2015年8月8日土曜日

Blocked loading mixed active contentが出た時に気をつけること

FirefoxのFirebugで"Blocked loading mixed active content..."というエラーが出てるので調べてみると、どうやらCDNを使ってHTMLページでインポートしてるJS/CSSファイルが読み込まれていない。

さらに掘り下げてみると、httpsで読み込んでるページからhttpでこれらのCDNからJS/CSSを読み込もうとするとエラーが出てるようだ。

What is Mixed Content?When a user visits a page served over HTTP, their connection is open for eavesdropping and man-in-the-middle (MITM) attacks. When a user visits a page served over HTTPS, their connection with the web server is authenticated and encrypted with SSL and hence safeguarded from eavesdroppers and MITM attacks.However, if an HTTPS page includes HTTP content, the HTTP portion can be read or modified by attackers, even though the main page is served over HTTPS. When an HTTPS page has HTTP content, we call that content “mixed”. The webpage that the user is visiting is only partially encrypted, since some of the content is retrieved unencrypted over HTTP. The Mixed Content Blocker blocks certain HTTP requests on HTTPS pages.
引用:
http://stackoverflow.com/questions/18251128/why-am-i-suddenly-getting-a-blocked-loading-mixed-active-content-issue-in-fire

要するに、HTTPSのページにHTTPリクエストで呼ばれているコンテンツがあると、それを”mixied(混在した)”コンテンツとみなし、MITM攻撃の被害になりえるのでやめて下さいとFirefoxが新しいバージョンではエラーとして表示してくれているようだ。

一般的な解決策は意外と簡単で、インポートしてるファイル(js/css)の構文をhttpからhttpsに変えてやればいい。もしくは//みたいな書き方でURLをブラウザが自動判別してくれるということ。

http://stackoverflow.com/questions/4831741/can-i-change-all-my-http-links-to-just

追加:

ただ、CDNによってはhttpからhttpsになぜかリクエストが変わってくれなかったので、そういうケースは泣く泣くCDNを使わずローカルにファイルを保存したりして回避した。

2015年8月5日水曜日

Tomcat6でjsessionidをURLから表示させないようにするには?

Tomcat6でjsessionidをURLから表示させないようにするには、context.xmlでContextの属性値をdisableURLRewriting="true"にしてやる。

<Context disableURLRewriting="true">
....
</Context>

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

2015年8月1日土曜日

Antでビルドする時にサーバー環境によってweb.xmlの内容を書き換えたいのでcopyタスクのFilterChainsを使う

Antでビルドする時にサーバー環境によってweb.xmlの内容や他の設定ファイル類の内容を書き換えたいので調べてみたら、copyタスクにFilterChainsというタスクで指定した文字列を書き換える事ができると分かったのでやってみた。

やり方の流れ:


  1. 書き換えたいファイルのテンプレートとなるファイルを作る(web_template.xml)
  2. テンプレートで書き換わる文字列をプロパティとして設定したファイルを作る(server1.xml)
  3. ビルドファイルにテンプレートと変数を元に生成するファイル(web.xml)を作るルールを書く(build.xml)
1.web_template.xml

....
<context-param>
    <param-name>someparameter</param-name>
    <param-value>@somevariable@</param-value>
</context-param>
....

※@~@の@は分かり易くつけてるだけです。

2.server1.xml

<project>
    <property name="server.host" value="abc.com" />
</project>

3.build.xml

<target name="rewriteXmlFile" >

    <copy file="/template/web_template.xml"  tofile="/WEB-INF/web.xml" overwrite="true">
        <filterchain>
            <tokenfilter>
                <replacestring from="@somevariable@" to="${server.host}"/>        
            </tokenfilter>
        </filterchain>
    </copy>

</target>



http://stackoverflow.com/questions/5217501/ant-copy-filterset
http://ant.apache.org/manual/Tasks/copy.html
http://ant.apache.org/manual/Types/filterchain.html#replacestring