V
ViperDK
What is the best way for that?
I store all Data in the original form in the Database. To prevent output
fields (especially the fields everyone can use) to do bad things like
killing the page-design or even worse attacking my site with javascript
directives i use stuff like
(WebControls.Label)Output.Text = HttpUtility.HtmlEncode(userDefinedData);
and my own functions which allow Line-Breaks and handle links.
But that way seems not to be very safe since it happens that you forget a
htmlEncode and then there is a security risc.
I saw that a "HtmlControls.HtmlGenericControl" (a html label converted to
RunAt Server) has the very useful attributes "InnerText" and "InnerHtml".
InnerHtml works like the text property of the Label WebControl but InnerText
automatically converts all special signs to the html codes. Why isn't there
a thing like "InnerText" in the Label WebControl? Seems very usefull to me
and it's more likely to forget a HtmlEncode before a Label than to use the
wrong property for setting the controls text.
Or maybe is the beste solution to HtmlEncode all user-input before writing
it to the database? On the one side it could be easier and more secure to
focus on the well-formed data in the database but on the other side i think
to care about valid html data is the business of the asp.net apllication,
not of the database.
I store all Data in the original form in the Database. To prevent output
fields (especially the fields everyone can use) to do bad things like
killing the page-design or even worse attacking my site with javascript
directives i use stuff like
(WebControls.Label)Output.Text = HttpUtility.HtmlEncode(userDefinedData);
and my own functions which allow Line-Breaks and handle links.
But that way seems not to be very safe since it happens that you forget a
htmlEncode and then there is a security risc.
I saw that a "HtmlControls.HtmlGenericControl" (a html label converted to
RunAt Server) has the very useful attributes "InnerText" and "InnerHtml".
InnerHtml works like the text property of the Label WebControl but InnerText
automatically converts all special signs to the html codes. Why isn't there
a thing like "InnerText" in the Label WebControl? Seems very usefull to me
and it's more likely to forget a HtmlEncode before a Label than to use the
wrong property for setting the controls text.
Or maybe is the beste solution to HtmlEncode all user-input before writing
it to the database? On the one side it could be easier and more secure to
focus on the well-formed data in the database but on the other side i think
to care about valid html data is the business of the asp.net apllication,
not of the database.