Information Security Asked by Awaaaaarghhh on January 12, 2021
There is a standard XSS exploitation technique where one can use javascript keyword in <a href="">
to execute javascript code. Example:
<a href="javascript:alert(42);">please clickme</a>
Let’s us consider PHP code which uses htmlspecialchars
with combination of a prefix check, where the URL must always start with https://
. Is there any way to exploit it in modern browsers like firefox, chrome?
<?php
// PHP 7
$url = htmlspecialchars($_GET["url"] ?? "", ENT_QUOTES);
$text = htmlspecialchars($_GET["text"] ?? "", ENT_QUOTES);
if ((substr($url, 0, 8) !== "https://")) {
$url = "https://" . $url;
}
?>
<a href="<?= $url; >"><?= $text; ></a>
I know that there is a open redirect vulnerability. I tried things like https://@javascript://://alert();
but it seems that google chrome blocks it (medium.com 2017: Say goodbye to URLs with embedded credentials). [This question is not about securing that code – this question is solely about exploiting.]
Here are more examples from the past:
When using htmlspecialchars
, all HTML tags will be escaped.
So let's say you type in <a href="https://hello">hello</a>
.
In source:
<a href="https://hello">hello</a>
<a href="https://hello"></a>
.In browser:
<a href="https://hello">hello</a>
Answered by JNic on January 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP