简体   繁体   English

在浏览器中显示XSS

[英]Displaying XSS in the browser

I'm building an application that retrieve any type of user input, even if the user put an xss injection code. 我正在构建一个可检索任何类型的用户输入的应用程序,即使用户放置了xss注入代码也是如此。 Beside that i'm providing an admin view to show the full content of what the user put, either they put html code, bb code, xss, javascript, etc(something like for analysis purpose). 除了提供管理员视图以显示用户输入内容的全部内容外,他们还可以输入html代码,bb代码,xss,javascript等(类似于分析目的)。

I'm thinking that htmlentities($data, ENT_QUOTES) is enough for that, but after reading https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet it makes me more confused. 我认为htmlentities($ data,ENT_QUOTES)足以满足要求,但是在阅读https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet之后,我感到更加困惑。

I don't want to remove any tag or script, i just want to display it in html with escaping. 我不想删除任何标签或脚本,我只想用转义符将其显示在html中。 Is save if i put it on textarea tag ? 如果将其放在textarea标签上,是否可以保存? I mean if the data is containing xss it would not executed if in text are ? 我的意思是,如果数据包含xss,则在文本中是否将不执行?

<textarea name="comment" rows="30" cols="100"><?php echo htmlentities($data, ENT_QUOTES); ?></textarea>

or there is any secure way to display xss on the browser but the xss it self not executed. 或有任何安全的方式在浏览器上显示xss,但自身未执行的xss。

sorry for my bad english. 对不起,我的英语不好。

Thanks 谢谢

The code you have posted is prone to XSS if your admin opens specially crafted user input the attacker can gain administrative privileges to that page. 如果您的管理员打开特制用户输入,则您发布的代码容易受到XSS的攻击,攻击者可以获得该页面的管理权限。 Placing user code within textarea or any other tag does not protect from XSS attacks. 将用户代码放在textarea或任何其他标签中并不能防止XSS攻击。 All the hacker has to do is close textarea tag in his input and do whatever he wants to. 黑客要做的就是在输入中关闭textarea标签,然后做他想做的任何事情。

I'm glad that you found owasp cheet sheet :) it's very usefull you should follow it. 我很高兴您找到了owasp速查表:)它非常有用,您应该遵循它。 Remeber to escape all user input that is placed on the page. 请记住以转义放置在页面上的所有用户输入。

I would recomend using htmlspecialchars and then do some tests with: tags presented here . 我建议使用htmlspecialchars ,然后使用此处提供的标签做一些测试。 If you won't see an JS alert then your application is to some extent protected from xss attacks. 如果您看不到JS警报,则您的应用程序在某种程度上受到了xss攻击的保护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM