Answer the question
In order to leave comments, you need to log in
Why do you need to specify the encoding on each page to avoid XSS, if an attacker can still change it?
Hello. I read an article on Habré on protecting a PHP site from XSS: https://habr.com/company/pentestit/blog/211494/ .
The third paragraph of this article reads as follows:
3. Specify the encoding on each web page.
If the tag is located before the tag and is filled with user data
Answer the question
In order to leave comments, you need to log in
The advice is somewhat outdated, and that's what it's for.
There is a frankly strange encoding called UTF-7 that was used in black for XSS. For example:
The hacker's task was to make the browser believe that the text is in UTF-7 before the encoding marker comes in the HTML.
IE11 supported UTF-7, whether Edge supports it is not in the know. The rest of the browsers gave up ten years ago.
More details:
https://nedbatchelder.com/blog/200704/xss_with_utf...
Well, it will be simply ugly if user data appears before the encoding marker and the browser incorrectly recognized this encoding. But at least XSS will not be in any encoding based on ASCII.
XSS is exploitation of vulnerabilities in HTML, JS and other scripts.
3. Specify the encoding on each web page.
The encoding must be specified, as some browsers may incorrectly determine it and the text content on the site will become unreadable.
If the tag is located before the tag and is filled with user data
You need to filter user data, including when it is embedded in HTML markup.
For example, you allow users to change the background picture on their profile.
You have a text field where the user enters a link to an image. After that, you substitute the user's picture, for example from the database, into the $user_background variable.
Thus, the code on the user page looks something like this:
<body style="background: #282b31 url($user_background) 50% 0 repeat;">
...
</body>
<body style="background: #282b31 url(http://example.com/image.png) 50% 0 repeat;">
...
</body>
htmlspecialchars($user_background, ENT_QUOTES, 'UTF-8');
thus, the code shown above will no longer work. Next, you need to set httponly for session Cookies (if not already), for this you need to replace your construction with something like this:
or like thisDidn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question