Yoshinori MATSUMOTO • JPCERT/CC 早期警戒グループ 情報セキュリティアナリスト Informa7on Security Analyst in Watching and Warning Group, JPCERT Coordina7on Center • I’m interested in… Analyzing web security, targeted aHacks, CMS, mul7-‐byte domains, and so on. 3
We published a research report on security issues of HTML5 (Japanese only, English version will be coming up :p ) 5 JPCERT HTML5 Search hHps://www.jpcert.or.jp/research/html5.html
of Use • 技術書・ガイドラインのベース資料 • 仲間内の勉強会資料 • セミナの参考資料 などにどうぞ Expects to be u7lized as… • Technical paper, basic informa7on for guidelines • Material for study mee7ngs • Reference informa7on for seminars 6
Report Term of Use 引用・転載にあたっては以下を参照してください。 JPCERT/CC ご利用にあたってのお願い hHps://www.jpcert.or.jp/guide.html 記載例) 引用元: JPCERTコーディネーションセンター 「HTML5 を利用したWeb アプリケーションのセキュリティ問題に関する調査報告書」 hHps://www.jpcert.or.jp/research/HTML5-‐20131030.pdf For ci7ng or reproducing the original document, please refer the below informa7on: JPCERT/CC Terms of use hHps://www.jpcert.or.jp/guide.html (Japanese only) Sample) Source: JPCERT Coordina7on Center “Technical research report on security issue of web applica7ons u7lizing HTML5” hHps://www.jpcert.or.jp/research/HTML5-‐20131030.pdf 7
covers the following topics : • Cross Document Messaging • Web Storage • WebSocket • Offline Web Applica7on • Web Workers • XMLHHpRequest – 今日は XMLHHpRequestについて話します Today, I will explain about XMLHHpRequest. 10
with HTTP using JavaScript — 非同期通信によりインタラクティブな表現が可能 Enables interac7ve web contents by asynchronous communica7on — AJAXの普及に伴い使用される機会が増加 Widely used due to the diffusion of AJAX — HTML5以前からある機能だが、HTML5で新しくなった A func7on from previous HTML and has been renewed in HTML5 11 Java Script Java Script
from the server to communicate with cross-‐origin. – クライアントはサーバからのレスポンスを見てアクセスの可否を判断するため、 サーバ側で許可していない場合でも、リクエストは送られる The client browser checks the response from the server and evaluates the accessibility. (Even though the server is not allowing , request can be sent. ) 13 example2.com Java Script example.com Access-‐Control-‐Allow-‐Origin Origin
18 MENU B A B C D E hHp://example.com/#/b.html 1. “コンテンツB” へのリンクを hHp://example.com/#/b.html に設定 Sevng a link to “content B” in hHp://example.com/#/b.html 2. ユーザがクリックするとJavaScriptでURLからアクセス先を 取得する Parse URL with JavaScript when a user clicks it. 3. XHRでコンテンツを取得 Load contents with XHR 4. コンテンツを表示する Display contents
the client browser supports XHR Level 2, it may redirect to malicious website. • XSS 攻撃が可能になる It enables XSS aHacks. 20 evil.com MENU evil.com/evil.php A B C D E hHp://example.com/#//evil.com/evil.php DEMO
a specified list of requests. 21 var pages = [ "/", "/a.html", "/b.html", "/c.html”, ”/d.html”, ”/e.html ]; var index = loca7on.hash.substring(1) | 0; var url = pages[ index ] || ‘/’; var xhr = new XMLHHpRequest(); xhr.open( "GET", url, true ); .... MENU B A B C D E hHp://example.com/#2
origin. • サイト内にオープンリダイレクトが存在すると、任意のサイトとの通信が可能 If an open redirect vulnerability exists in the website, it may communicate with arbitrary website. • loca7on.hash を利用した場合、サーバ側にデータが残らない In case “loca7on.hash” is used, the request logs do not remain in the server. 22 var url = loca7on.hash.substring(1); if( url.indexOf( "hHp://example2.jp/" ) == 0 || url.indexOf( "hHp://example3.jp/" ) == 0 ){ // example2.jp または example3.jp のときのみ通信 var xhr = new XMLHHpRequest(); xhr.open( "GET", url, true ); .... }
Overview of the CSRF aHack 25 SERVER 攻撃者ページ The aHacker’s website アップローダのページ Uploader Page User Upload Load malicious JavaScript View aHacker’s website
サポートしていれば発生する This security issue occurs if the vic7m user uses a browser which supports XHR Level2. – WebサイトがHTML5を使用していなくても影響が ある Furthermore, even if the website is not using HTML5, this security issue will take place. 28
are added to HTML5. • 報告書ではこれらの中からいくつかセキュリティ上のポイン トを紹介している Our research report explains several security topics on these. • 今回は以下の機能について説明する Today, I will explain following topics. – <input type=“email”> – <iframe sandbox> canvas video autofocus 31
the input value is an email address. 32 検索、電話、URL、日時、色なども可能 Available searching term: Tel, URL , Date 7me, Color, and so on <SCRIPT> Browser Not EMAIL !! Good Sani7zing…
can be bypassed by edi7ng HTML or sending a request directly. • この機能をセキュリティ対策として使用してはいけない Do not use this func7on as a security measure. F12 POST HTTP… DEMO 33
as a countermeasure since JavaScript may execute due to the direct access from an aHacker. 35 example.jp index.html xss_bbs.cgi <iframe sandbox src=“hHp://example.jp/xss_bbs.cgi”> evil.com index.html <iframe src=“hHp://example.jp/xss_bbs.cgi”> xss_bbs.cgi Java Script
XSS攻撃からの保護 Protects from XSS aHack • X-‐Content-‐Type-‐Op7ons – Content-‐Typeヘッダに従ったコンテンツの取り扱い Manage contents based on configura7on in Content-‐ Type header • X-‐Frame-‐Op7ons – フレームへの埋め込みを制限 Restricts embedding into a frame such as iframe 37
Restricts the contents loaded origin • Content-‐Disposi7on – ファイルのダウンロードダイアログの制御 Controls download dialog of an file • Strict-‐Transport-‐Security – HTTPSの強制 Enforces the use of secure HTTPS connec7ons 38
• <script>や<img>、<iframe>といった要素など Elements such as <script>, <img>, and <iframe> • <div onmouseover="alert(1)">や<script>alert(1)</script>といったインラインでの JavaScriptの実行 Execu7ng inline JavaScript such as <div onmouseover="alert(1)"> and <script>alert(1)</script> • JavaScript内でのeval関数やFunc7onコンストラクタといった、文字列からのコード の実行 Execu7ng strings as a func7on such as eval func7on and Func7on constructors. • javascript スキームやdata スキーム javascript scheme and data scheme
CSP policy direc7ves hHps://developer.mozilla.org/en/docs/Security/CSP/CSP_policy_direc7ves default-‐src ディレクティブを指定していない場合のディレクティブソースを列挙する Defines the security policy for all types of content which are not expressly called out by more specific direc7ves script-‐src スクリプトとして許可するディレクティブソースを列挙する Specifies valid sources for JavaScript style-‐src スタイルシートとして許可するディレクティブソースを列挙する Specifies sources from which stylesheets may be loaded img-‐src 画像の読込み元として許可するディレクティブソースを列挙する Specifies what sources may be used for loading images and favicons frame-‐src フレームとして表示可能なディレクティブソースを列挙する Specifies valid sources for frame content loaded using the <frame> and <iframe> elements
DEMO 'self' ドキュメント自身と同一オリジンの場合にのみ許可する Refers to the host from which the protected document is being served, including the same URL scheme and port number 'none' どのオリジンも許可しない Refers to the empty set; that is, no URLs match. The single quotes are required. 'unsafe-‐inline' script-‐src、style-‐srcにおいてインラインでのスクリプト記述、スタイル記述を許 可する Allows the use of inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements. You must include the single quotes. 'unsafe-‐eval' JavaScript内でのeval、Func7on、setTimeout、setIntervalといった文字列から コードを生成する機能を許可する Allows the use of inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements. You must include the single quotes.
since there are browsers which do not support Content-‐Security-‐Policy and the way they perform differs among them. • 設定内容によっては正規のJavaScriptが動作しない場 合もあるため、導入には注意が必要 Please test before implementa7on since JavaScript may not operate due to the improper configura7on. 44
about HTML5 security issues upon using them. • 「HTML5を利用したWebアプリケーションのセ キュリティ問題に関する調査報告書」をセキュア なWebアプリケーションの開発に役立ててくださ い We hope that our research report is useful to you! 46