<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 上下文轉義 網站和Web應用程序容易受到[XSS](https://www.owasp.org/index.php/XSS)攻擊,雖然PHP提供了轉義功能,但在某些情況下,它還不夠/適當。`Phalcon\Escaper`提供了上下文轉義,并以Zephir編寫,在轉義不同類型的文本時提供最小的開銷。 我們基于[OWASP](https://www.owasp.org)創建的[XSS(Cross Site Scripting)](https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet)預防備忘單設計了這個組件。 此外,該組件依賴于 [mbstring](http://php.net/manual/en/book.mbstring.php) 來支持幾乎任何字符集。 為了說明此組件的工作原理及其重要性,請考慮以下示例: ```php <?php use Phalcon\Escaper; // 使用惡意的額外HTML標記記錄標題 $maliciousTitle = "</title><script>alert(1)</script>"; // 惡意CSS類名稱 $className = ";`("; // 惡意CSS字體名稱 $fontName = "Verdana\"</style>"; // 惡意Javascript文本 $javascriptText = "';</script>Hello"; // 創建一個escaper $e = new Escaper(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> <?php echo $e->escapeHtml($maliciousTitle); ?> </title> <style type="text/css"> .<?php echo $e->escapeCss($className); ?> { font-family: "<?php echo $e->escapeCss($fontName); ?>"; color: red; } </style> </head> <body> <div class='<?php echo $e->escapeHtmlAttr($className); ?>'> hello </div> <script> var some = '<?php echo $e->escapeJs($javascriptText); ?>'; </script> </body> </html> ``` 其中產生以下內容: ```html <br />&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt; &lt;/title&gt;&lt;script&gt;alert(1)&lt;/script&gt; &lt;/title&gt; &lt;style type="text/css"&gt; .\3c \2f style\3e { font-family: "Verdana\22 \3c \2f style\3e"; color: red; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div class='&#x3c &#x2f style&#x3e '&gt; hello &lt;/div&gt; &lt;script&gt; var some = '\x27\x3b\x3c\2fscript\x3eHello'; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; ``` 每個文本都根據其上下文進行了轉義。使用適當的上下文對于避免XSS攻擊很重要。 ## 轉義HTML 插入不安全數據時最常見的情況是在HTML標記之間: ```html <div class="comments"> <!-- Escape untrusted data here! --> </div> ``` 您可以使用`escapeHtml`方法轉義這些數據: ```php <div class="comments"> <?php echo $e->escapeHtml('></div><h1>myattack</h1>'); ?> </div> ``` 生成: ```html <div class="comments"> &gt;&lt;/div&gt;&lt;h1&gt;myattack&lt;/h1&gt; </div> ``` ## 轉義HTML屬性 轉義HTML屬性與轉義HTML內容不同。escaper通過將每個非字母數字字符更改為表單來工作。這種轉義是針對大多數簡單的屬性,不包括像`href`或`url`這樣的復雜屬性: ```html <table width="Escape untrusted data here!"> <tr> <td> Hello </td> </tr> </table> ``` 您可以使用`escapeHtmlAttr`方法轉義HTML屬性: ```php <table width="<?php echo $e->escapeHtmlAttr('"><h1>Hello</table'); ?>"> <tr> <td> Hello </td> </tr> </table> ``` 生成: ```html <table width="&#x22;&#x3e;&#x3c;h1&#x3e;Hello&#x3c;&#x2f;table"> <tr> <td> Hello </td> </tr> </table> ``` ## 轉義網址 某些HTML屬性(如`href` 或`url`)需要以不同方式進行轉義: ```html <a href="Escape untrusted data here!"> Some link </a> ``` 您可以使用`escapeUrl`方法轉義HTML屬性: ```php <a href="<?php echo $e->escapeUrl('"><script>alert(1)</script><a href="#'); ?>"> Some link </a> ``` 生成: ```html <a href="%22%3E%3Cscript%3Ealert%281%29%3C%2Fscript%3E%3Ca%20href%3D%22%23"> Some link </a> ``` ## 轉義CSS CSS標識符/值也可以轉義: ```html <a style="color: Escape untrusted data here"> Some link </a> ``` 您可以使用`escapeCss`方法轉義CSS標識符/值: ```php <a style="color: <?php echo $e->escapeCss('"><script>alert(1)</script><a href="#'); ?>"> Some link </a> ``` 生成: ```html <a style="color: \22 \3e \3c script\3e alert\28 1\29 \3c \2f script\3e \3c a\20 href\3d \22 \23 "> Some link </a> ``` ## 轉義JavaScript 要插入JavaScript代碼的字符串也必須正確轉義: ```html <script> document.title = 'Escape untrusted data here'; </script> ``` 您可以使用`escapeJs`方法轉義JavaScript代碼: ```php <script> document.title = '<?php echo $e->escapeJs("'; alert(100); var x='"); ?>'; </script> ``` ```html <script> document.title = '\x27; alert(100); var x\x3d\x27'; </script> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看