Best Practice: User generated HTML cleaning

前端 未结 4 1198
旧巷少年郎
旧巷少年郎 2021-01-02 22:47

I\'m coding a WYSIWYG editor width designMode=\"on\" on a iframe. The editor works fine and i store the code as is in the database.

Before outputing the html i need

4条回答
  •  星月不相逢
    2021-01-02 23:29

    The best practice is to allow only certain things you know aren't dangerous, and remove/escape all the rest. See the paper Automated Malicious Code Detection and Removal on the Web (OWASP AntiSamy) for a discussion on this (the library is for Java, but the principles apply for any language).

提交回复
热议问题