users using &, ", ', and other chars in input fields

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Hill

    #1

    users using &, ", ', and other chars in input fields

    I have a general question about how people generally tend to deal with
    users data that they enter.

    As an example users enter double quotes in a text field surrounding a
    specific piece of text they want to hi-lite and then it barfs during
    the oracle insert step because the string is not properly delimited.

    Another example is where the ampersand causes trouble when used on an
    xml page so provisions are made to insert it into the table
    using the ascii equavalent & . But the field is only 25 characters
    so when a string with 25 characters that has an ampersand is being
    input and we change the ampersand to the ascii equavalent we now have
    more then 25 characters and update fails beacuse we have
    too many characters. We could truncate them before the insert, or we
    could write some code to deal with them onthe client.

    Others copy and paste from word documents into a text field and in it
    there are hidden formatting fields like bullets.

    The users barf and complain about the application, but what we have here
    is bad data.

    How do most handle these?

    Mike

  • McKirahan

    #2
    Re: users using &, ", ', and other chars in input fields

    "Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
    news:40199D9B.5 98765E0@ram.lmt as.lmco.com...[color=blue]
    > I have a general question about how people generally tend to deal with
    > users data that they enter.[/color]


    I use something like the following; watch for word-wrap.


    function validate() {
    var form = document.forms[0];
    var regs = "'\n\nInval id characters: \" & '";
    var regx = /\"|\&|\'/
    for (var i=0; i<form.elements .length; i++) {
    if (regx.test(form .elements[i].value)) {
    alert("Invalid character(s) in '" + form.elements[i].name +
    regs);
    return false;
    }
    }
    return true;
    }



    Comment

    • Silvio Bierman

      #3
      Re: users using &amp;, &quot;, ', and other chars in input fields


      "Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
      news:40199D9B.5 98765E0@ram.lmt as.lmco.com...[color=blue]
      > I have a general question about how people generally tend to deal with
      > users data that they enter.
      >
      > As an example users enter double quotes in a text field surrounding a
      > specific piece of text they want to hi-lite and then it barfs during
      > the oracle insert step because the string is not properly delimited.
      >
      > Another example is where the ampersand causes trouble when used on an
      > xml page so provisions are made to insert it into the table
      > using the ascii equavalent &amp; . But the field is only 25 characters
      > so when a string with 25 characters that has an ampersand is being
      > input and we change the ampersand to the ascii equavalent we now have
      > more then 25 characters and update fails beacuse we have
      > too many characters. We could truncate them before the insert, or we
      > could write some code to deal with them onthe client.
      >
      > Others copy and paste from word documents into a text field and in it
      > there are hidden formatting fields like bullets.
      >
      > The users barf and complain about the application, but what we have here
      > is bad data.
      >
      > How do most handle these?
      >
      > Mike
      >[/color]

      Your Oracle problems come from fiddling with sql text and text literals. Use
      prepared statements and statement parameters to prevent such problems. That
      means do not use

      "insert into tab(col) values ('" + colVal + "')"

      but use

      "insert into tab(col) values (?)" (JDBC syntax) or something similar for
      OCI.

      When generating HTML pages/forms containing data from the database you
      should always be aware of invalid characters in the data. Use a proper
      escaping function to handle that. I would advise escaping to ASCII only
      instead of UTF-8 but that is a matter of taste.

      Regards,

      Silvio Bierman


      Comment

      • Michael Hill

        #4
        Re: users using &amp;, &quot;, ', and other chars in input fields

        "McKirahan" <News@McKirahan .com> wrote in message
        news:B7iSb.1403 26$sv6.763636@a ttbi_s52...[color=blue]
        > "Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
        > news:40199D9B.5 98765E0@ram.lmt as.lmco.com...[color=green]
        > > I have a general question about how people generally tend to deal with
        > > users data that they enter.[/color]
        >
        >
        > I use something like the following; watch for word-wrap.
        >
        >
        > function validate() {
        > var form = document.forms[0];
        > var regs = "'\n\nInval id characters: \" & '";
        > var regx = /\"|\&|\'/
        > for (var i=0; i<form.elements .length; i++) {
        > if (regx.test(form .elements[i].value)) {
        > alert("Invalid character(s) in '" + form.elements[i].name +
        > regs);
        > return false;
        > }
        > }
        > return true;
        > }[/color]

        So you are saying strip out the characters even if the users cry, bitch,
        moan, and do other baby like stuff?

        Mike


        Comment

        • McKirahan

          #5
          Re: users using &amp;, &quot;, ', and other chars in input fields

          "Michael Hill" <hillmw@charter .net> wrote in message
          news:101krgikjj noh01@corp.supe rnews.com...[color=blue]
          > "McKirahan" <News@McKirahan .com> wrote in message
          > news:B7iSb.1403 26$sv6.763636@a ttbi_s52...[color=green]
          > > "Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
          > > news:40199D9B.5 98765E0@ram.lmt as.lmco.com...[color=darkred]
          > > > I have a general question about how people generally tend to deal with
          > > > users data that they enter.[/color]
          > >[/color][/color]
          [color=blue]
          > So you are saying strip out the characters even if the users cry, bitch,
          > moan, and do other baby like stuff?
          >
          > Mike[/color]

          Would you rather have your application "cry, bitch, moan, and do other baby
          like stuff?"

          You could always substitute restricted characters before using (e.g.
          storing) them...


          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: users using &amp;, &quot;, ', and other chars in input fields

            "McKirahan" <News@McKirahan .com> writes:
            [color=blue]
            > Would you rather have your application "cry, bitch, moan, and do other baby
            > like stuff?"[/color]

            Ofcourse not, it should handle all possible inputs gracefully.
            Especially sine client-side validation will not always be able to
            filter out problematic inputs.
            [color=blue]
            > You could always substitute restricted characters before using (e.g.
            > storing) them...[/color]

            That would be the prettier choice.

            Your application has problems with certain characters. You should solve
            that instead of passing the problem on to the unsuspecting user. It's
            not their fault, and they really don't need to know.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            Working...