Secure Database-Driven output to Web-Controls like Repeater

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Secure Database-Driven output to Web-Controls like Repeater

    scenario: users can store data (guestbook entries, ther usernames and so on)
    on a database-driven website and i have to care about that they don't insert
    (aggressive) javascripts or html tags that destroy my layout. but it's not
    an option to deny characters like ', " or < at all.

    one option i got suggested is to make all the input to valid html output (Do
    a HtmlEncode) before i store it in the database but i think that is not that
    great because its to limited and bad design. if i make an winform
    application or something else that is not web-based i'd have to handle and
    undo all the html stuff that is only useful for html pages.

    the two right solutions for this that i think of is to code controls like
    Repeater with an property like "UseRawHtmlData" and let it automatically
    HtmlEncode all output unless it is set for RawHtmlData. That would be a
    safe design i think but it has the disadvantage that ms didn't do it and i'd
    have to make many modified controls that do.
    the other solution i think of is to code an SqlDataReader and a
    SqlDataAdapter that also automatically HtmlEncode all text data.

    I think the second way makes more sense - i would only have to use that
    modified sql classes and i would not have to touch the data-webcontrols like
    repeater, datagrid and so on.

    does anyone have such classes to use instead of the normal Sql classes or is
    there a better alternative to solve that problem. to HtmlEncode every field
    manually like i do now seems to be the worst answer since it makes much work
    and is error prone.


    ViperDK \(Daniel K.\) Guest

  2. Similar Questions and Discussions

    1. Database driven CMS and Contribute
      I am looking to create a hybrid of contribute and database driven CMS (like Joomla or Drupal). Anyone ever tied to do anything similar? Any...
    2. Database driven articles
      Hello, I am supernew to ColdFusion and to these forums, and I'm sorry if this is an overly obvious/retarded question. That said: I am...
    3. Database driven web site
      Hi, I want to create a website where people can sign up to the site and put there company details on it. Then when a user searches for a...
    4. database driven website using SAN
      We want to develop database driven website. because of enormous amount of data (300GB) customers's tech advisor is insisting on using SAN instead...
    5. Modifying output in Repeater
      I am having trouble figuring out how to modify the databound field data that is bound to a Repeater control, before it is output to the browser. I'm...
  3. #2

    Default Re: Secure Database-Driven output to Web-Controls like Repeater

    Well, before I can offer a solution I need a few pointers:

    - are you intending to store the actual html in the database?
    - you said you dont care about JS/HTML that can destroy layout, which makes
    things easier

    unless I'm mistaken I dont believe the "BoundColumns" in DataGrids change
    the valid HTML to be Encoded HTML,
    and since the repeater utilizes templates, then you are in better control.

    In your repeater template, are you using "<asp:label runat=server text='<%#
    DataBinder.Eval... %>'>"? if so then the Text property is automatically HTML
    encoded, trying changing to using the HtmlControls, specifically the
    HtmlGenericControl and setting the InnerHtml property, whereas this property
    takes a string and outputs it verbatim.

    HTH


    --
    Eric Newton
    [email]eric@ensoft-software.com[/email]
    C#/ASP.net Solutions developer

    "ViperDK (Daniel K.)" <ViperDK@gmx.net> wrote in message
    news:bhdkh4$ffo$04$1@news.t-online.com...
    > scenario: users can store data (guestbook entries, ther usernames and so
    on)
    > on a database-driven website and i have to care about that they don't
    insert
    > (aggressive) javascripts or html tags that destroy my layout. but it's not
    > an option to deny characters like ', " or < at all.
    >
    > one option i got suggested is to make all the input to valid html output
    (Do
    > a HtmlEncode) before i store it in the database but i think that is not
    that
    > great because its to limited and bad design. if i make an winform
    > application or something else that is not web-based i'd have to handle and
    > undo all the html stuff that is only useful for html pages.
    >
    > the two right solutions for this that i think of is to code controls like
    > Repeater with an property like "UseRawHtmlData" and let it automatically
    > HtmlEncode all output unless it is set for RawHtmlData. That would be a
    > safe design i think but it has the disadvantage that ms didn't do it and
    i'd
    > have to make many modified controls that do.
    > the other solution i think of is to code an SqlDataReader and a
    > SqlDataAdapter that also automatically HtmlEncode all text data.
    >
    > I think the second way makes more sense - i would only have to use that
    > modified sql classes and i would not have to touch the data-webcontrols
    like
    > repeater, datagrid and so on.
    >
    > does anyone have such classes to use instead of the normal Sql classes or
    is
    > there a better alternative to solve that problem. to HtmlEncode every
    field
    > manually like i do now seems to be the worst answer since it makes much
    work
    > and is error prone.
    >
    >

    Eric Newton Guest

  4. #3

    Default Re: Secure Database-Driven output to Web-Controls like Repeater

    no i want to store all data as it is. if someone writes stuff like "i like
    <i> tags" it should get 1:1 into the database and i want an easy way to
    verify in the output that it does get encoded.

    i usually use DataGrids with BoundColumns like
    <asp:BoundColumn DataField="Comment" HeaderText="Comment"></asp:BoundColumn>

    and yes i saw that the HtmlGenericControl has a property for the encodet and
    the raw content. i wonder why the the TextBox WebControl hasn't that
    functionality. thought they should be first choice.

    "Eric Newton" <ericnewton76@hotmail.com> wrote in message
    news:#ddq561YDHA.2236@TK2MSFTNGP10.phx.gbl...
    > Well, before I can offer a solution I need a few pointers:
    >
    > - are you intending to store the actual html in the database?
    > - you said you dont care about JS/HTML that can destroy layout, which
    makes
    > things easier
    >
    > unless I'm mistaken I dont believe the "BoundColumns" in DataGrids change
    > the valid HTML to be Encoded HTML,
    > and since the repeater utilizes templates, then you are in better control.
    >
    > In your repeater template, are you using "<asp:label runat=server
    text='<%#
    > DataBinder.Eval... %>'>"? if so then the Text property is automatically
    HTML
    > encoded, trying changing to using the HtmlControls, specifically the
    > HtmlGenericControl and setting the InnerHtml property, whereas this
    property
    > takes a string and outputs it verbatim.
    >
    > HTH
    >
    >
    > --
    > Eric Newton
    > [email]eric@ensoft-software.com[/email]
    > C#/ASP.net Solutions developer


    ViperDK \(Daniel K.\) Guest

  5. #4

    Default Re: Secure Database-Driven output to Web-Controls like Repeater

    Yeah, I guess the textboxes were designed from the start to be HTML proper,
    ie, if they have HTML in their text property then its HTMLEncoded so that
    what is in the text is exactly what you see...

    I would guess it'll always stay this way, but a simple boolean property
    wouldnt hurt ;-)


    --
    Eric Newton
    [email]eric@ensoft-software.com[/email]
    C#/ASP.net Solutions developer

    "ViperDK (Daniel K.)" <ViperDK@gmx.net> wrote in message
    news:bhk2bl$hge$01$1@news.t-online.com...
    > no i want to store all data as it is. if someone writes stuff like "i like
    > <i> tags" it should get 1:1 into the database and i want an easy way to
    > verify in the output that it does get encoded.
    >
    > i usually use DataGrids with BoundColumns like
    > <asp:BoundColumn DataField="Comment"
    HeaderText="Comment"></asp:BoundColumn>
    >
    > and yes i saw that the HtmlGenericControl has a property for the encodet
    and
    > the raw content. i wonder why the the TextBox WebControl hasn't that
    > functionality. thought they should be first choice.
    >
    > "Eric Newton" <ericnewton76@hotmail.com> wrote in message
    > news:#ddq561YDHA.2236@TK2MSFTNGP10.phx.gbl...
    > > Well, before I can offer a solution I need a few pointers:
    > >
    > > - are you intending to store the actual html in the database?
    > > - you said you dont care about JS/HTML that can destroy layout, which
    > makes
    > > things easier
    > >
    > > unless I'm mistaken I dont believe the "BoundColumns" in DataGrids
    change
    > > the valid HTML to be Encoded HTML,
    > > and since the repeater utilizes templates, then you are in better
    control.
    > >
    > > In your repeater template, are you using "<asp:label runat=server
    > text='<%#
    > > DataBinder.Eval... %>'>"? if so then the Text property is automatically
    > HTML
    > > encoded, trying changing to using the HtmlControls, specifically the
    > > HtmlGenericControl and setting the InnerHtml property, whereas this
    > property
    > > takes a string and outputs it verbatim.
    > >
    > > HTH
    > >
    > >
    > > --
    > > Eric Newton
    > > [email]eric@ensoft-software.com[/email]
    > > C#/ASP.net Solutions developer
    >
    >
    >

    Eric Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139