允许视频嵌入时需要注意哪些 XSS/CSRF 攻击(如果有)?
我被分配了一个网站项目,允许用户上传视频(使用 YouTube API),但更重要的是(对我来说)他们还可以提交视频嵌入代码(来自众多视频网站、YouTube、Vimeo)等)。
没有允许用户嵌入视频的经验:
如何最好地防范专门针对视频嵌入的跨站点脚本和/或跨站点请求伪造攻击?有哪些需要注意的常见陷阱?
至少我会考虑删除除
编辑
另外:
您认为在
如果很重要,环境将是:
- PHP/Zend Framework
- MySQL
奖励点:
视频嵌入代码是否有一个通用的最小黄金规则/代码模板,该模板在所有视频网站上都有效,我可以用它来过滤输入?
I've been assigned a project for a website where users will be allowed to upload video's (using a YouTube API) but more importantly (for me) they will also be allowed to submit video embed codes (from numerous video sites, YouTube, Vimeo, etc. etc.).
Having no experience with allowing users to embed video:
How can I best protect against cross site scripting and/or cross site request forgery attacks specifically for video embedding? What are some of the common pitfalls to watch for?
At a minumum I would think to strip all tags except <object>
, <param>
and <embed>
. But I have a feeling this will not be enough, will it?
edit
Also:
Do you think allowing only known video domainnames in the <embed src=
and <param name="movie" value=
attributes is enough to prevent rogue flash movies from being embedded in those attributes?
/edit
If it is of importance, the environment will be:
- PHP/Zend Framework
- MySQL
Bonuspoints:
Is there a common minimum golden rule/code template for video embed codes that are valid across all video sites that I could use to filter the input?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个也是最危险的 xss(?)是 flash 可以读取您的 DOM...不要在用户可以输入他/她的登录数据的页面上嵌入视频。登录表单应该分开。
通常 Flash 嵌入使用类似于以下内容的代码:
Youtube:
Vimeo:
Metacafe:
启用嵌入内容的最佳解决方案是从示例中剥离标签,但 embed、param、object 和属性列表除外。可以使用。
请记住,某些属性可以运行 javascript 代码以及锚点的 href...
编辑:
在 src 和 param 的 value 属性中只允许受信任的站点是防止 hAx0rs 做坏事的好方法,但它并不是完美的。另一件大事:阅读有关allowScriptAccess 的更多信息。您应该删除它的 Param 属性或将其设置为 sameDomain / never。它将阻止 SWF 运行 javascript :)
First and most dangerous xss (?) is that flash can read your DOM... Don't embed videos on pages where user can input his/hers login data. Login forms should be separated.
Usually flash embeds uses code that looks similar to:
Youtube:
Vimeo:
Metacafe:
Best solution for enabling embeded content is to strip tags with exception for embed, param, object and list of attributes from the the samples that can be used.
Remember, some attributes can run javascript code as well as anchor's href...
Edit:
Allowing only trusted sites in src and param's value attribute is kinda good way to prevent hAx0rs from doing bad things but it's not flawles. Another big thing: read more about allowScriptAccess. Its a Param's attribute you should remove or set to sameDomain / never. It will prevent SWF from running javascript :)
您为什么不访问所有网站,保存其嵌入代码,然后只允许您的用户提交所需网站的参数?
Why don't you just visit all the sites, save their embed code, and then only allow your users to submit the required site's parameters?