addslashes()是否可以安全地阻止HTML属性中的XSS? [英] Is addslashes() safe to prevent XSS in a HTML attribute?

查看:189
本文介绍了addslashes()是否可以安全地阻止HTML属性中的XSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不处理以前的开发人员离开的旧网络应用程序。它使用addslashes()来防止HTTML属性上的XSS。

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.

这是一个例子:

<?php
  // all $_POST vars are put through addslashes()

  echo "<input type='hidden' value='" . $_POST['id'] . "' />";
?>

这是否容易受到XSS攻击?有没有什么方法可以在一个值属性中运行javascript,就像在src属性中一样,例如,src ='javascript:alert(99)'。或者可以打开value属性,然后插入脚本标签?

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?

编辑:感谢Quentin,我认为它很容易受到攻击。

Thanks to Quentin, I believe it is vulnerable.

推荐答案


addslashes()是否可以安全地阻止HTML属性中的XSS?

Is addslashes() safe to prevent XSS in a HTML attribute?

非常无效。


这是否容易受到XSS攻击?

Is this vulnerable to XSS?

是。


有没有什么方法可以运行javascript像src属性中的值属性,例如,src ='javascript:alert(99)'。

Is there any way javascript can run in a value attribute like it can in an src attribute for example, src='javascript:alert(99)'.


或者可以打开value属性然后插入脚本标签吗?

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.

如果要插入任意字符串,请使用 htmlspecialchars n到属性值。

Use htmlspecialchars when you want to insert an arbitrary string into an attribute value.

这篇关于addslashes()是否可以安全地阻止HTML属性中的XSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆