使用HTTP Headers 防禦WEB攻擊

來源:互聯網
上載者:User

使用HTTP Headers 防禦WEB攻擊

   再次載入頁面,便會彈出一個警告框

  在FireFox中進行同樣的測試,成功執行。

  現在將X-XSS-Protection頭的值修改為1,再次嘗試。

  header("X-XSS-Protection: 1");

  你能夠輕鬆體會到已經成功開啟了X-XSS-Protection。

  HTTP/1.1 200 OK

  Date: Sun, 12 Apr 2015 14:54:42 GMT

  Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8y DAV/2 mod_perl/2.0.8 Perl/v5.20.0

  X-Powered-By: PHP/5.6.2

  Expires: Thu, 19 Nov 1981 08:52:00 GMT

  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

  Pragma: no-cache

  Set-Cookie: PHPSESSID=8dfb86b13ec9750d1f1afdfc004f5042; path=/

  X-XSS-Protection: 1

  Content-Length: 820

  Keep-Alive: timeout=5, max=100

  Connection: Keep-Alive

  Content-Type: text/html; charset=UTF-8

  再次在漏洞頁面執行JavaScript,指令碼不會執行。進入Chrome的控制台,看看發生了什麼事

  從上面的控制台資訊中,我們可以得知指令碼沒有得到執行。

  header("X-XSS-Protection: 1");

  上面這個頭沒有添加其他的參數,僅僅只是阻止指令碼的執行。

  我們可以添加一些其他參數,比如:

  header("X-XSS-Protection: 1; mode=block");

  這時再次測試,瀏覽器會阻止指令碼執行,並且返回一個空白頁。

  下面為HTTP頭資訊

  HTTP/1.1 200 OK

  Date: Mon, 13 Apr 2015 09:59:22 GMT

  Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8y DAV/2 mod_perl/2.0.8 Perl/v5.20.0

  X-Powered-By: PHP/5.6.2

  Expires: Thu, 19 Nov 1981 08:52:00 GMT

  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

  Pragma: no-cache

  Set-Cookie: PHPSESSID=729f2f716310ccfe353c81ced1602cf0; path=/

  X-XSS-Protection: 1; mode=block

  Content-Length: 846

  Keep-Alive: timeout=5, max=100

  Connection: Keep-Alive

  Content-Type: text/html; charset=UTF-8

  儘管在一些主流瀏覽器(IE,Chrome,Safari)中可以完美實現。但在FireFox中並不支援這個頭,所以我們仍然可以看到彈出警告框

  總結

  所以,X-XSS-Protection頭應該用於深度防禦。由於它無法完全保護網站,因此開發人員必須確保他們有其他一些手段來進行防護。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.