|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Visão geral de scripts maliciosos
The application displays a form where users enter comments. The malicious user writes a comment that includes a <script> block in it. The form is posted and the malicious user's comment is stored in a database. Another user visits the site. When the page is constructed, it reads comments out of the database and puts them into the page. The malicious user's <script> block is written into the page as if it were a text comment. When the second user's browser displays the page, it gets to the <script> block and executes it.
Observação |
|---|
"Select * From Customers where CustomerName = " & txtCustomerName.Value
Select * From Customers Where CustomerName = 'a' Delete From Customers Where CustomerName > ''
ASP.NET performs request validation against query-string and form variables as well as cookie values. By default, if the current Request contains HTML-encoded elements or certain HTML characters (such as — for an em dash), the ASP.NET page framework raises an error. If you want to display strings in your application but do not trust them, apply HTML encoding to them when the strings are written back in a response. For example, with encoding, the tag <b> becomes <b>. You might do this if the strings that you are displaying are from a database whose contents you are not sure that you can trust. If you want your application to accept some HTML (for example, some formatting instructions from users), you should encode the HTML at the client before it is submitted to the server. For more information, see Como: proteger contra scripts maliciosos em um aplicativo da Web aplicando a codificação HTML a sequências de caracteres. To help protect against SQL statement exploits, never create SQL queries using string concatenation. Instead, use a parameterized query and assign user input to parameter objects. Always validate form input against a set of expected values and string formatting/type validation. Por exemplo, se umavariável de formuláriode específico deve ser um inteiro, use o TryParsemétodo para verificar o que realmente o valor é um inteiro e usar o intervalo de verificação para ajudar a garantir que o valor está dentro do intervalo aceitável.
Observação