admin管理员组文章数量:1345725
I'm having to work on an old web app that a previous developer left. It is using addslashes() to prevent XSS on a HTTML attribute.
Here is an example:
<?php
// all $_POST vars are put through addslashes()
echo "<input type='hidden' value='" . $_POST['id'] . "' />";
?>
Is this vulnerable to XSS? Is there any way javascript can run in a value attribute like it can in an src attribute for example, src='javascript:alert(99)'. Or can the value attribute be broken out of and then script tags can be inserted?
Edit: Thanks to Quentin, I believe it is vulnerable.
I'm having to work on an old web app that a previous developer left. It is using addslashes() to prevent XSS on a HTTML attribute.
Here is an example:
<?php
// all $_POST vars are put through addslashes()
echo "<input type='hidden' value='" . $_POST['id'] . "' />";
?>
Is this vulnerable to XSS? Is there any way javascript can run in a value attribute like it can in an src attribute for example, src='javascript:alert(99)'. Or can the value attribute be broken out of and then script tags can be inserted?
Edit: Thanks to Quentin, I believe it is vulnerable.
Share Improve this question edited Dec 2, 2011 at 9:16 MrCode asked Dec 2, 2011 at 8:45 MrCodeMrCode 64.5k10 gold badges92 silver badges113 bronze badges2 Answers
Reset to default 9Is addslashes() safe to prevent XSS in a HTML attribute?
It is highly ineffective.
Is this vulnerable to XSS?
Yes.
Is there any way javascript can run in a value attribute like it can in an src attribute for example, src='javascript:alert(99)'.
No
Or can the value attribute be broken out of and then script tags can be inserted?
The data just has to include a "
and the attribute is broken out of.
Use htmlspecialchars
when you want to insert an arbitrary string into an attribute value.
addslashes()
is not appropriate for this task. Use htmlspecialchars()
or htmlentities()
instead, eg
<input type="hidden"
value="<?php echo htmlspecialchars($_POST['id'], ENT_QUOTES, 'UTF-8') ?>">
本文标签: phpIs addslashes() safe to prevent XSS in a HTML attributeStack Overflow
版权声明:本文标题:php - Is addslashes() safe to prevent XSS in a HTML attribute? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743800716a2541260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论