Prevent GET and POST injection

Source: Internet
Author: User

Hi.baidu.com/cncxz

Generally, http requests are similar to get and post requests. If illegal characters in parameter information in all post or get requests are filtered out, SQL injection is prevented.

First, define that the request cannot contain the following characters:

| And | exec | insert | select | delete | update | count | * | % | chr | mid | master | truncate | char | declare

Separate the characters with "|" and then judge Request. QueryString. The specific code is as follows:

Invalid character filtering for get requests:

Dim SQL _injdata
SQL _injdata = "| and | exec | insert | select | delete | update | count | * | % | chr | mid | master | truncate | char | declare"
SQL _inj = split (SQL _Injdata, "| ")
If Request. QueryString <> "Then
For Each SQL _Get In Request. QueryString
For SQL _Data = 0 To Ubound (SQL _inj)
If instr (Request. QueryString (SQL _Get), SQL _Inj (SQL _DATA)> 0 Then
Response. Write "<Script Language = javascript> {alert (please do not include invalid characters in the parameter !); History. back (-1)} </Script>"
Response. end
End if
Next
Next
End If

Illegal character filtering for post requests:

If Request. Form <> "" Then
For Each SQL _Post In Request. Form
For SQL _Data = 0 To Ubound (SQL _inj)
If instr (Request. Form (SQL _Post), SQL _Inj (SQL _DATA)> 0 Then
Response. Write "<Script Language = javascript> {alert (please do not include invalid characters in the parameter !); History. back (-1)} </Script>"
Response. end
End if
Next
Next
End if

Then, you can Include the two pieces of code in the database connection file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.