I am using a contentEditable div that allows users to edit the body HTML and then post it directly to site using an AJAX request. Naturally, I have to do some security checks on it. The most obvious was ensuring that no script tags were submitted by searching for <script
in the submitted HTML. This is done after first running htmlentities
, transferring the data to another server, and then running html_entity_decode
. In addition, every tag that is opened must be closed and every tag that is closed must be opened within the user submitted HTML.
Disregarding unrelated security risks (such as SQL injection) and non-security risks (such as a user posting an inappropriate image), what are other security risks, if any, specifically linked to allowing a user to add HTML directly to a page?
To be more specific,
- Are there ways to put scripts in the page without explicitly using a script tag, OR
- Are there ways to compromise the security of a site or its users by editing the HTML without using scripts?