Preventing Cross Site Scripting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Qaurk Noble

    #1

    Preventing Cross Site Scripting

    Can anyone help?

    I need to html encode all text field values on the client just before
    sending them to the server. A javascript equilalent of Server.HTMLEnco de in
    IIS. I also need to be able to perform the reverse.

    All I am trying to do is ensure that if a user enters html tags in the a
    form, that the tags does not get parsed by the browser.


  • Martin Honnen

    #2
    Re: Preventing Cross Site Scripting



    Qaurk Noble wrote:
    [color=blue]
    > Can anyone help?
    >
    > I need to html encode all text field values on the client just before
    > sending them to the server. A javascript equilalent of Server.HTMLEnco de in
    > IIS. I also need to be able to perform the reverse.
    >
    > All I am trying to do is ensure that if a user enters html tags in the a
    > form, that the tags does not get parsed by the browser.[/color]

    Well, you need to use server side scripting anyway or otherwise someone
    could disable JavaScript or set up his own form with out the encoding.
    Thus if you have ASP on the server then simply use that, don't bother
    with client-side encoding.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Qaurk Noble

      #3
      Re: Preventing Cross Site Scripting

      Thanks for replying Martin

      I agree entirely about do the encoding on the server side. The biggest
      challenge I face at the moment is that this project is using JSP and I am
      new to java. I have not yet located a JSP equivalent of ASP's
      Server.HTMLEnco de.

      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:3fd89784$1 @olaf.komtel.ne t...[color=blue]
      >
      >
      > Qaurk Noble wrote:
      >[color=green]
      > > Can anyone help?
      > >
      > > I need to html encode all text field values on the client just before
      > > sending them to the server. A javascript equilalent of[/color][/color]
      Server.HTMLEnco de in[color=blue][color=green]
      > > IIS. I also need to be able to perform the reverse.
      > >
      > > All I am trying to do is ensure that if a user enters html tags in the a
      > > form, that the tags does not get parsed by the browser.[/color]
      >
      > Well, you need to use server side scripting anyway or otherwise someone
      > could disable JavaScript or set up his own form with out the encoding.
      > Thus if you have ASP on the server then simply use that, don't bother
      > with client-side encoding.
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]


      Comment

      • Fox

        #4
        Re: Preventing Cross Site Scripting



        Qaurk Noble wrote:[color=blue]
        >
        > Thanks for replying Martin
        >
        > I agree entirely about do the encoding on the server side. The biggest
        > challenge I face at the moment is that this project is using JSP and I am
        > new to java. I have not yet located a JSP equivalent of ASP's
        > Server.HTMLEnco de.[/color]

        In JS, you can use escape(string) and unescape(string );

        if you want to strip out html inputted by the user:

        string.replace(/(<([^>]+)>)/g,""); // before escaping

        [color=blue]
        >
        > "Martin Honnen" <mahotrash@yaho o.de> wrote in message
        > news:3fd89784$1 @olaf.komtel.ne t...[color=green]
        > >
        > >
        > > Qaurk Noble wrote:
        > >[color=darkred]
        > > > Can anyone help?
        > > >
        > > > I need to html encode all text field values on the client just before
        > > > sending them to the server. A javascript equilalent of[/color][/color]
        > Server.HTMLEnco de in[color=green][color=darkred]
        > > > IIS. I also need to be able to perform the reverse.
        > > >
        > > > All I am trying to do is ensure that if a user enters html tags in the a
        > > > form, that the tags does not get parsed by the browser.[/color]
        > >
        > > Well, you need to use server side scripting anyway or otherwise someone
        > > could disable JavaScript or set up his own form with out the encoding.
        > > Thus if you have ASP on the server then simply use that, don't bother
        > > with client-side encoding.
        > >
        > > --
        > >
        > > Martin Honnen
        > > http://JavaScript.FAQTs.com/
        > >[/color][/color]

        Comment

        • Dr John Stockton

          #5
          Re: Preventing Cross Site Scripting

          JRS: In article <3FD8F5B5.46874 347@spam.com>, seen in
          news:comp.lang. javascript, Fox <dont@spam.co m> posted at Thu, 11 Dec
          2003 16:54:45 :-[color=blue]
          >
          >if you want to strip out html inputted by the user:
          >
          >string.replace (/(<([^>]+)>)/g,""); // before escaping[/color]

          That can change non-HTML text :

          Try S = "J'appelle mon petit chien <<Idefix>>"
          or S = "This works : if (X<12) and (Y>3) then Write('Ooh!') ;"
          then S.replace(/(<([^>]+)>)/g,"");

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> Jsc maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/Jsc/&c, FAQ topics, links.

          Comment

          Working...