Re: Displaying User-Supplied String
- From: Jesse Houwing <jesse.houwing@xxxxxxxxxxxxxxxx>
- Date: Wed, 3 Oct 2007 23:29:08 +0000 (UTC)
Hello Jonathan,
Right. I tested it by surrounding my input with <b> and </b>. To my
surprise, it causes an unhandled exception: A potentially dangerous
Request.Form value was detected from the client
(ctl00$ContentPlaceHolder1$description="<b>Property1</b>").
Not sure yet where the error is being thrown from exactly, but I'm
looking into it.
By default any input containing either a piece of javascript code or a html tag will be rejected by ASP.NET from versin 1.1 and higher.
You can switch this automatic validation off from the web.config or the page directive of teh aspx file in question:
http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_server_error_potentially_dangerous.htm
Jesse
"Jesse Houwing" <jesse.houwing@xxxxxxxxxxxxxxxx> wrote in message--
news:21effc90205bd8c9d43b6960ffef@xxxxxxxxxxxxxxxxxxxxx
Hello Mark Rae [MVP],
"Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx> wrote in messageThere's more than SQL injection at work here. apart from SQL
news:OqKJvmgBIHA.5868@xxxxxxxxxxxxxxxxxxxxxxx
Okay, I have a site that displays information based on user input,Are you talking about SQL Injection i.e. the strings supplied by the
a couple of the items are plain strings that the user entered.
I understand the risk here is that they could insert javascript or
whatever in their string and, when my page displays it, that script
could be executed.
What is the best approach for preventing that?
users are used to look up records in a database?
If so, you need to use parameterised queries or stored procedures.
Google "SQL injection"
injection there is the risk of cross site scripting as the original
poster correctly identified. Best way to prevent that is to call
Server.HTMLEncode on each field before displaying it. I usually don't
encode the data before putting it into the database as the data migth
be used in a non-web environment as well (reporting, windows client
etc).
So encode before displaying.
--
Jesse Houwing
jesse.houwing at sogeti.nl
Jesse Houwing
jesse.houwing at sogeti.nl
.
- Follow-Ups:
- Re: Displaying User-Supplied String
- From: Jonathan Wood
- Re: Displaying User-Supplied String
- References:
- Re: Displaying User-Supplied String
- From: Jonathan Wood
- Re: Displaying User-Supplied String
- Prev by Date: Re: Exteding the AdRotator Control and Advert.xml file to track advert stats
- Next by Date: Re: Displaying User-Supplied String
- Previous by thread: Re: Displaying User-Supplied String
- Next by thread: Re: Displaying User-Supplied String
- Index(es):
Relevant Pages
|