2012-01-25 35 views
7

Đây là Default.aspx tôilỗi yêu cầu Tại sao nguy hiểm tiềm tàng thậm chí ValidateRequest = false

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %> 
<html> 
    <head runat="server"> 
     <title>xss demonstration</title> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 
     <div> 
      We are looking for your feedback. 
      <asp:TextBox ID="txtFeedback" runat="server" TextMode="MultiLine" /> 
      <br /> 
      <asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" /> 
      <br /> 
      Comment: 
      <br /> 
      <asp:Literal ID="ltlFeedback" runat="server" /> 
     </div> 
     </form> 
    </body> 
</html> 

Và dưới đây là Default.aspx.cs

public partial class _Default : System.Web.UI.Page 
{ 
    protected void submit_Click(object sender, EventArgs e) 
    { 
     this.ltlFeedback.Text = this.txtFeedback.Text; 
    } 
} 

Khi tôi chạy các ứng dụng và nhập sau trong hộp văn bản.

<script>alert('Hello')</script> 

Tôi nhận được lỗi sau.

Một giá trị Request.Form nguy hiểm đã được phát hiện từ client (txtFeedback = "alert ('Hello ...").

Câu hỏi của tôi là tại sao tôi nhận được lỗi này mặc dù ValidateRequest được thiết lập để sai trong trang?

Trả lời

0

bạn chỉ cần thêm đoạn mã sau vào cấu hình web của bạn

<system.web> 
     <compilation debug="false" targetFramework="4.0" /> 
     <httpRuntime requestValidationMode="2.0"/> 
</system.web> 

nhưng chăm sóc bằng cách làm này bạn có thể là nạn nhân của cuộc tấn công kịch bản chéo trang web

Các vấn đề liên quan