Re: Storage of html markup code in database

From: Nicole Calinoiu (calinoiu)
Date: 10/08/04


Date: Fri, 8 Oct 2004 08:01:19 -0400

This is not usually a particularly good idea for a few reasons. The biggest
problems are the following:

1. The web UI may not be (now or at some time in the future) the only
interface via which the data is read. The stored HTML-encoding will lead to
rendering annoyances when the data is displayed elsewhere. These alternate
UIs may include reports and database management tools, not just other
applications created for end-users.

2. Modifying the stored string representations will interfere with
searching the database. Of course, you could also HTML-encode all search
terms, but that gets even uglier if you consider the possibility of
alternate consumers of the data.

3. This only works if all data is entered via a UI that HTML-encodes the
data prior to saving. However, regardless of any additional protections you
might want to put into place (aside from some that are even more work than
the render-time encoding you are trying to avoid), the dba is going to be
able to edit the data directly, thereby bypassing your protection.

4. The details of your desired HTML-encoding may change over time. They
may also differ between display locations within your application. (e.g.: A
given string may be displayed with line breaks replaced by "<br>" tags on a
given page where there is a lot of vertical room for the text, but line
breaks might be suppressed when the same text is displayed as a single item
in a long list on another page.) If you store the pre-encoded text,
changing it either over time or space will be more difficult.

That said, ASP.NET provides a relatively convenient environment (at least as
compared to standard ASP <g>) in which to ensure that you use render-time
HTML-encoding. While it's unfortunate that the built-in controls are not
more consistent with respect to applying encoding during rendering, it's
relatively trivial to inherit from these controls in order to create new
controls that behave the way you might prefer. If you then want to ensure
that you consistently use your modified controls rather than the built-in
controls, it might be worth considering running FxCop with a custom rule
that screens for use of the built-in controls.

HTH,
Nicole

"Shabam" <blislecp@hotmail.com> wrote in message
news:A8KdnTmQHcIJ_PjcRVn-qA@adelphia.com...
>I have an application that needs to fetch client data from the database and
> show them on a web page. However, I don't want clients to inject html
> into
> any web pages so I've decided to change all instances of "<" to "&lt;" and
> ">" to "&gt;".
>
> However, having to convert those strings dynamically every time a page is
> to
> be displayed is rather tedious, and I may miss something down the line.
>
> So, I'm thinking that every time user data is received, the html markup
> tags
> are translated and stored in the database that way. That way when it
> comes
> time to display, no dynamic code is needed to translate them.
>
> What are your thoughts on this?
>
>



Relevant Pages

  • Re: Print Preview of form
    ... The details section is visible but controls /1 are invisible when ... if the Display When on a form's section or a control is set to ... The only other possibility is some corruption of the database. ...
    (microsoft.public.access.forms)
  • Re: Blank Form Will Not Appear
    ... information that used to come from a flat table from another database (which ... So I wrote a query to create a flat record for each order, ... the form still opened with all the controls showing. ... Access won't display the detail section for any form when there are no existing records to display and no new records can be added. ...
    (microsoft.public.access.forms)
  • Re: Making a text box a find field.
    ... The way my database is ... You need two controls for. ... In the AfterUpdate event of IDFilter have code... ... If there is not the form will display the blank (new ...
    (microsoft.public.access.formscoding)
  • Re: adding controls at run time
    ... that approach will not work if you don't know how many controls you need. ... For example, in my Java work doing front ends for databases, frequently we ... want to display options to a user based on data in the database. ... display exactly that number of radio buttons to a user to pick from. ...
    (microsoft.public.vc.ide_general)
  • RE: Display a record - several questions
    ... ObjectDataSource set up to get the correct record on a select. ... sub controls in the certain tepmlate and modify them. ... How do I display a RadioButtonList and CheckBox value where it is ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)