How to Prevent request attacks using ajax server scripts

Source: Internet
Author: User
To prevent users from simulating logon or other requests through ajax interfaces, for example, writing a script or manually making requests to you. How to prevent it? To prevent users from simulating logon or other requests through ajax interfaces, for example, writing a script or manually making requests to you. How to prevent it?

Reply content:

To prevent users from simulating logon or other requests through ajax interfaces, for example, writing a script or manually making requests to you. How to prevent it?

  1. Verify the AJAX request. For example, PHP code:
Define ('is _ AJAX ', isset ($ _ SERVER ['HTTP _ X_REQUESTED_WITH']) & strtolower ($ _ SERVER ['HTTP _ X_REQUESTED_WITH ']) = 'xmlhttprequest ');

(Environmental variables in this step can be forged, but many hacker (bai) can be filtered out ))
2. frequency limit. For IP address restrictions, you can do this at the server layer (Tengine has this function ). For the frequency limit of logged-on users, Douban does this. If the frequency is exceeded, enter the verification code.
3. csrftoken is of little significance.

First, there is no absolute solution to prevent this situation.

Second, there are only two solutions to consider:
1. Verify the routes
2. Added verification data (such as cookie and hidden input). csrftoken is similar to hidden input.

Some abnormal people will perform verification codes --#

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.