允许视频嵌入时需要注意哪些 XSS/CSRF 攻击(如果有)?

发布于 2024-08-25 15:22:14 字数 653 浏览 7 评论 0原文

我被分配了一个网站项目,允许用户上传视频(使用 YouTube API),但更重要的是(对我来说)他们还可以提交视频嵌入代码(来自众多视频网站、YouTube、Vimeo)等)。

没有允许用户嵌入视频的经验:
如何最好地防范专门针对视频嵌入的跨站点脚本和/或跨站点请求伪造攻击?有哪些需要注意的常见陷阱?

至少我会考虑删除除 之外的所有标签。但我有一种感觉,这还不够,不是吗?

编辑
另外:
您认为在 属性中仅允许已知视频域名足以防止流氓 Flash 电影被盗吗?嵌入那些属性中?
/edit

如果很重要,环境将是:

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牛↙奶布丁 2024-09-01 15:22:14

第一个也是最危险的 xss(?)是 flash 可以读取您的 DOM...不要在用户可以输入他/她的登录数据的页面上嵌入视频。登录表单应该分开。

通常 Flash 嵌入使用类似于以下内容的代码:

Youtube:

<object width="425" height="350">
  <param name="movie" value="http://www.youtube.com/v/AyPzM5WK8ys" />
  <param name="wmode" value="transparent" />
  <embed src="http://www.youtube.com/v/AyPzM5WK8ys"
         type="application/x-shockwave-flash"
         wmode="transparent" width="425" height="350" />
</object>

Vimeo:

<object width="400" height="225">
  <param name="allowfullscreen" value="true" />
  <param name="allowscriptaccess" value="always" />
  <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=10239065&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" />
  <embed src="http://vimeo.com/moogaloop.swf?clip_id=10239065&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed>
</object>
<p><a href="http://vimeo.com/10239065">La Fete (HD - 2010)</a> from <a href="http://vimeo.com/animalcolm">Malcolm Sutherland</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

Metacafe:

<embed src="http://www.metacafe.com/fplayer/4317045/bmx_face_slide.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_4317045"> </embed>
<br><font size = 1><a href="http://www.metacafe.com/watch/4317045/bmx_face_slide/">BMX Face Slide</a> - <a href="http://www.metacafe.com/">Free videos are just a click away</a></font>

启用嵌入内容的最佳解决方案是从示例中剥离标签,但 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:

<object width="425" height="350">
  <param name="movie" value="http://www.youtube.com/v/AyPzM5WK8ys" />
  <param name="wmode" value="transparent" />
  <embed src="http://www.youtube.com/v/AyPzM5WK8ys"
         type="application/x-shockwave-flash"
         wmode="transparent" width="425" height="350" />
</object>

Vimeo:

<object width="400" height="225">
  <param name="allowfullscreen" value="true" />
  <param name="allowscriptaccess" value="always" />
  <param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=10239065&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" />
  <embed src="http://vimeo.com/moogaloop.swf?clip_id=10239065&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed>
</object>
<p><a href="http://vimeo.com/10239065">La Fete (HD - 2010)</a> from <a href="http://vimeo.com/animalcolm">Malcolm Sutherland</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

Metacafe:

<embed src="http://www.metacafe.com/fplayer/4317045/bmx_face_slide.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_4317045"> </embed>
<br><font size = 1><a href="http://www.metacafe.com/watch/4317045/bmx_face_slide/">BMX Face Slide</a> - <a href="http://www.metacafe.com/">Free videos are just a click away</a></font>

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 :)

计㈡愣 2024-09-01 15:22:14

您为什么不访问所有网站,保存其嵌入代码,然后只允许您的用户提交所需网站的参数?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文