I want to allow users to paste <embed> and <object> HTML fragments (video players) via an HTML form. The server-side code is PHP. How can I protect against malicious pasted code, JavaScript, etc? I could parse the pasted code, but I’m not sure I could account for all variations. Is there a better way?
I want to allow users to paste <embed> and <object> HTML fragments (video players)
Share
I’m not really sure what parameters
EMBEDandOBJECTtake as I’ve never really dealt with putting media on a page (which is actually kind of shocking to think about) but I would take a BB Code approach to it and do something likeand then you can parse out the URL and anything else, make sure they are legit and make your own<EMBED>tag.edit: Alright, something like this should be fine:
This will output:
From then on it’s pretty straight forward. For things like width/height you can verify them with
is_numericand with the rest you can run the values throughhtmlentitiesand construct your own<embed>tag from the information. I am pretty certain this would be safe. You can even make the full-fledged<object>one like YouTube (which I assume works in more places) with links from blip.tv, since you would have all the required data.I am sure you may see some quirks with links from other video-sharing websites but this will hopefully get you started. Good luck.