HTML5 Security Risk Analysis II: Web Storage attacks

Source: Internet
Author: User
Tags sessionstorage

Previous: http://www.bkjia.com/Article/201209/154081.html

1. Introduction to WebStorage

HTML5 supports WebStorage. developers can create local storage for applications and store some useful information. For example, LocalStorage can be stored for a long time and has a large storage space of 5 MB, this greatly solves the problems of small data storage capacity, inconvenient access, and easy to be cleared by using cookies. This function provides great flexibility for the client.

Ii. attack methods

LocalStorage APIs are provided through Javascript, so that attackers can steal information through XSS attacks, such as user tokens or data. Attackers can use the following script to traverse local storage.

 
If (localStorage. length ){
For (I in localStorage ){
Console. log (I );
Console. log (localStorage. getItem (I ));
}
}
At the same time, LocalStorage is not the only method to expose local information. Many developers have a bad habit of putting a lot of key information into global variables for convenience, such as usernames, passwords, and mailboxes. If the data is not placed in the appropriate scope, it may cause serious security problems. For example, we can use the following script to traverse global variables to obtain information.
 
For (iin window ){
Obj = window [I];
If (obj! = Null | obj! = Undefined)
Var type = typeof (obj );
If (type = "object" | type = "string "){
Console. log ("Name:" + I );
Try {
My = JSON. stringify (obj );
Console. log (my );
} Catch (ex ){}
}
}

Iii. attack tools

HTML5dump is defined as "JavaScriptthat dump all HTML5 local storage". It can also output HTML5 SessionStorage, global variables, LocalStorage, and local database storage.

 

Iv. Defense

The following measures are taken to defend against WebStorage Attacks:

1. Place data in the appropriate scope

For example, user sessionID should be stored in sessionStorage instead of LocalStorage. User data should not be stored in global variables, but in temporary or local variables.

2. Do not store sensitive information.

Because we cannot always know whether there will be some security issues on the page, we must not store important data in WebStorage.

From: http://blog.csdn.net/hfahe/article/details/7961618

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.