Created
December 8, 2017 09:21
-
-
Save antic183/3de21f71d4e416a95791d86f1d5c7088 to your computer and use it in GitHub Desktop.
php htmlspecialchars is not enough to prevent an xss attack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>php htmlspecialchars()</h1> | |
<h3>without END_QUOTES flag is an xss attack possible:</h3> | |
<?php | |
echo "<a href='" . htmlspecialchars("'onmouseover='a()'") . "'>link</a><br/>"; | |
echo "<textarea style='overflow: none; width: 350px; border: none; resize: none; line-break: none;'>"; | |
echo "<a href=''onmouseover='a()''>link</a>"; | |
echo "</textarea><br/>"; | |
echo "<a href='" . htmlspecialchars("'onmouseover='alert(123)'") . "'>link</a><br/>"; | |
echo "<textarea style='overflow: none; width: 350px; border: none; resize: none; line-break: none;'>"; | |
echo "<a href=''onmouseover='alert(123)''>link</a>"; | |
echo "</textarea>"; | |
?> | |
<h3>use the END_QUOTES flag for more security:</h3> | |
<?php | |
echo "<a href='" . htmlspecialchars("'onmouseover='a()'", ENT_QUOTES) . "'>link</a><br/>"; | |
echo "<textarea style='overflow: none; width: 350px; border: none; resize: none; line-break: none;'>"; | |
echo "<a href=''onmouseover='a()''>link</a>"; | |
echo "</textarea>"; | |
?> | |
<script>function a() {alert('xss: execute internal function !');}</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment