views:

194

answers:

1

For the site i am building i would like the users to be able to provide embed codes for video and audio sites. i know this poses a security risk, so i wanted to find out, within Django, how best to filter the html provided so that only certain tags and certain sites are allowed.

Does anyone have any references to how i can accomplish this with Django?

+1  A: 

You may be better off using a lightweight markup language and then converting to HTML. This prevents them from playing games to get around whatever HTML checking you do. Fully and correctly checking HTML for 'gotchas' is very difficult to do.

Doing it this way is sort of from the school of That which is not explicitly permitted is prohibited.

Peter Rowell
If you use creoleparser (http://pypi.python.org/pypi/Creoleparser/0.6.1), you can create macros that generate the embed code (e.g. define a `youtube` macro so people can use `<<youtube some_video_id>>` in their markup, a `googlevideo` macro, etc.).
LeafStorm
@LeafStorm: Thanks for the link. I hadn't seen this particular one before.
Peter Rowell