Nginx prevents SQL Injection

Source: Internet
Author: User

The best way to prevent SQL injection is to filter and escape all data submitted to the background.

For simple cases, such as single quotation marks ('), semicolons (;), <,>, and other characters, you can use rewrite to directly subscribe to the 404 page.

There is a premise to use rewrite. Generally, rewrite is used for regular matching and can only match the URI of the webpage, that is, the url? First part ,? Later parts are request parameters.

The request parameters following the question mark are displayed in the $ query_string table in nginx. They cannot be matched in rewrite. if is required

For example, match the 'with single quotes in the parameter and then direct it to the error page,

/Plus/list. php? Tid = 19 & mid = 1124'

Rewrite ^. * ([; '<>]). */error.html break;

Directly Writing such an rewrite will certainly not match correctly, because the rewrite parameter will only match the requested uri, that is, the/plus/list. php part.

You need to use $ query_string to determine with if. if the query string contains special characters, 404 is returned.

If ($ query_string ~ * ". * [; '<>]. *") {

Return 404;

}

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.