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?
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 🙂