Home  >  Article  >  Web Front-end  >  How to protect your data and prevent JSON vulnerabilities and hijacking

How to protect your data and prevent JSON vulnerabilities and hijacking

青灯夜游
青灯夜游Original
2018-11-14 16:50:313273browse

The content of this article is to introduce how to protect data and prevent JSON vulnerabilities and hijacking. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .

JSON is not as completely secure as we think, and hackers can obtain sensitive user data from unsuspecting users through cross-site request forgery (CSRF) in JSON arrays.

This mainly exposes JSON services containing JSON arrays, sensitive data, responses to GET requests, JavaScript-enabled requests, and requests that support the defineSetter method.

So how to prevent JSON vulnerabilities and JSON hijacking, that is, prevent CRSF attacks and achieve the purpose of protecting sensitive data, this is what this article will introduce to you.

1. All request methods must be POST and prevent your code from only accepting POST requests (This is the most important )

$ .ajax({
    url:'http://yourdomainname.com/login',
    dataType:'json',
    data:JSON.stringify(dataObject),
    contentType:'application / json; charset=utf-8' ,
    type: 'POST',
    success:function(jsonData){
        //成功回调
    },
    error:function(){
        //要处理的任何错误
    }
 });

2. Add in the request The unique CSRF token prevents applications from cookie hijacking and bad requests.

3. Always use secure transfer protocol (HTTPS) in requests.

4. Before providing a response to the request, check for special headers such as X-Requested-With: XMLHttpRequest or Content-Type: application/json.

5. Manage user access logs to check which user activities.

6. Use API and end URL authentication to verify the current endpoint.

7. Use token-based API access, such as JSON Web Tokens (JWT).

8. Implement error handling and do not provide any technical details in API calls.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of How to protect your data and prevent JSON vulnerabilities and hijacking. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn