Filtering JavaScript out of HTML

后端 未结 6 1629
走了就别回头了
走了就别回头了 2020-12-16 05:29

I have a rich text editor that passes HTML to the server. That HTML is then displayed to other users. I want to make sure there is no JavaScript in that HTML. Is there any w

6条回答
  •  爱一瞬间的悲伤
    2020-12-16 05:50

    The simplest thing to do would be to either strip out tags with a regex. Trouble is that you could do plenty of nasty things without script tags (e.g. imbed dodgy images, have links to other sites that have nasty Javascript) . Disabling HTML completely by convert the less than/greater than characters into their HTML entities forms (e.g. <) could also be an option.

    If you want a more powerful solution, in the past I have used AntiSamy to sanitize incoming text so that it's safe for viewing.

提交回复
热议问题