12-line JS code for browser crashes (Dos attack analysis and defense) _javascript tips

Source: Internet
Author: User
Tags memory usage

Ajax and Pjax

Ajax is "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), a technology used to create fast dynamic Web pages. AJAX enables asynchronous updating of Web pages by making a small amount of data exchange in the background with the server. This means you can update a part of a Web page without reloading the entire page-no refresh operation.

However, Ajax applications can also create additional problems that can easily cause browsers to fail to move forward and backward, which is a headache, and developers must increase their workload (such as through a hidden iframe, or change the Location.hash value, etc.) to solve the problem.

In order to solve the problems caused by traditional Ajax, HTML5 introduced a new API:history.pushState, it and Ajax, after the combination of a new name is Pjax. is a new technology based on ajax+history.pushstate that can change the content of a page without refreshing, and can change the URL of a page. Pjax is a ajax+pushstate package, while supporting local storage, animation, and many other functions. Currently support jquery, Qwrap, Kissy and many other versions.

HTML5.history.pushState

HTML5 can manipulate browser history through the Pushstate and Replacestate interfaces, and change the URL of the current page.

Pushstate adds the specified URL to the browser history, storing the current history point. Replacestate replaces the specified URL with the current URL. At the same time, these methods will work with the window.onpostate event.

history.pushState(data, title, url) : Adds a record to the top of the history stack; data passes as a parameter when the Onpopstate event is triggered; title is the title of the page, which is generally ignored by all browsers; The URL is the page address, optional, and the default is the current page address. Specific details:

The state– object is a JavaScript state object that records the extra objects of the history point and can be empty. It relates to the pushState()方 New history entity created by the law. Used to store information about the entries you want to insert into the history.

title-This parameter is generally ignored by all browsers, although it may be used in the future. The safest way to use it now is to pass an empty string to prevent future modifications, or you can pass a short title to represent state.

url-This parameter is used to pass the URL of the new history entity, the new URL must be the same domain as the existing URL, or the pushstate () will throw an exception. This parameter is optional and, if empty, is placed as the current URL for document.

12 Line Code Analysis

 
 

The above is 12 lines of code, the key point is for total this URL loop: history.pushState(0,0,total); constantly modify the URL, the loop 1 million times, constantly to the history of the stack of new records, will lead to high CPU and memory usage and firefox,chrome, The Safari browser crashes and allows the iphone to reboot.

In the XP virtual machine (i7 single core 3.4G, 512 memory) measured personally:

When the above cycle is more than 100,000 of the level, CPU, memory usage instantaneous 100%, and then crash panic;

When the above cycle is reduced to about 10000 of the time, CPU, memory usage rate in about 20 seconds to gradually rise to 100%, and then crash panic;

When the above cycle is reduced to about 500, the CPU utilization rate gradually increased to 100%, again instantaneous restore to a stable state, memory use from about 130M up to 230M, and open the 192.168.56.106/12.html this page, The link inside the address bar also becomes: http://192.168.56.106/0123456789101112131415161718192021 ... 494495496497498499

As you can see, as you add new records to the history stack by looping, the page will refresh to the new address of the jump, is a "pseudo address" cumulative, when this length overrun, it will cause DOS, the effectiveness and efficiency of the attack depends entirely on the number of cycles and Tagret hardware configuration.

Related defense

Believe that everyone's safety awareness has been very strong, but still need to alarm bells, do not believe any stranger by any means to send you a link, attachment, mail, pictures, etc. any information, of course, do not rule out good base friends of the mischief of friends, so the small partners remember often ctrl+s oh, Otherwise it would be very depressing to get caught.

The internet since the birth of the day, it is exposed to hacker attacks, the early hacker attack how many still have technical test and show off, but with the global Internet infrastructure expansion, the unlimited connection growth and the rapid expansion of the number of users, hacker attack frequency increases correspondingly, hacker technology is also developing continuously, The black industrial chain with the aim of illegally acquiring economic benefits is gradually appearing. The technology of the Internet security protection is by leaps and bounds, while outsmart, attack and defend, in this Internet time every minute is happening.

Network security protection, seven points rely on technology, three points by consciousness, to protect these problems, in addition to relying on security manufacturers of products and services, but also need to continuously improve the network security awareness. For example: Pay attention to personal password management, pay attention to personal privacy protection, do not easily access public WiFi, do not easily believe unfamiliar/familiar with friends of the link or file, pay attention to mobile payment security, do not let equipment "naked" and so on

Summarize

The above is the entire content of this article, I hope to be able to learn or work to bring certain help, if you have questions you can message exchange.

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.