Home > Web Front-end > JS Tutorial > Why does Google prepend `while(1);` to its JSON responses?

Why does Google prepend `while(1);` to its JSON responses?

DDD
Release: 2024-11-30 05:26:10
Original
367 people have browsed it

Why does Google prepend `while(1);` to its JSON responses?

Why Google's JSON Responses Begin with while(1);

Question: Why does Google prepend while(1); to its JSON responses?

Answer:

Google's practice of prepending while(1); to JSON responses is a security measure aimed at preventing JSON hijacking.

JSON hijacking occurs when an external website embeds a JSON-retrieving URL within a script tag on its page. Exploiting the same-origin policy, the external site can retrieve JSON data from the target website (e.g., Google) using the user's cookies.

The malicious script can intercept the JSON content, modify its properties, or extract sensitive information. By overriding global array constructor or accessor methods, the external site could gain control over the data manipulation process.

The addition of while(1); or &&&BLAH&&& to the beginning of the JSON string disrupts this process. When the JSON response is loaded via an AJAX request, it is parsed and processed before being displayed. However, when the JSON string is executed within a script tag, it encounters an infinite loop or syntax error, preventing malicious code from accessing the data.

This measure helps protect users from cross-site scripting attacks and ensures that Google's JSON responses remain secure and uncompromised by unauthorized sources.

The above is the detailed content of Why does Google prepend `while(1);` to its JSON responses?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template