views:

66

answers:

1

Greetings friends,

I am developing a web application that will allow the customer to enter a personalized message, which will then be converted to HTML. Well, the problem is that I can not allow the insertion of Javascript code. So I need a method that filters the text, searching for and remove it. I think the regular expressions to solve my problem, but I'm having difficulty building. Some of his friends could help me, or has already developed something for this.

Thank you.

+4  A: 

You don't need to worry at what the customer enters and is saved into the database. You need to worry what you are showing in the View. All you need is to html encode the message before displaying it:

<%= Html.Encode(Model.TheMessage) %>

or using the new ASP.NET 4.0 code nugget:

<%: Model.TheMessage %>
Darin Dimitrov
Friend, sorry did not explain, but I need to send the html email, and even export it, then I need to remove the javascript code.Issues of application security, as defined in the analysis.Thanks
Ph.E
When you generate this HTML you need to encode properly HTML encode the user input.
Darin Dimitrov
Buddy! Formats output like UTF-8?
Ph.E
not a good advice "You don't need to worry at what the customer enters and is saved into the database" it a potential XSS vulnerability.
Cesar
@Cesar, as long as you filter what you are showing in the HTML no XSS is possible.
Darin Dimitrov