Results 1 to 4 of 4

Thread: How filter user input for bad HTML/Javascript

  1. #1
    Join Date
    Mar 2005
    Posts
    19

    Default How filter user input for bad HTML/Javascript

    Hey guys,

    I'm writing an app that accepts user input in the form of free-form text.

    The problem is that the Spring HTML escaping tags are WAY too harsh for me. I want to allow links, <IMG SRC...> and formatting like <br/>, etc, but not free-form Javascript, stylesheets, etc.

    With the Spring tags, I can turn the HTML and JavaScript off completely, but nothing in between.

    Do you guys have any thoughts on how to best deal with this?

    Ideally, we would pass in a list of valid tags into a parser, and then ask it to automatically parse and/or validate the user input.

    Any other good approaches, or libraries? Like a modular Java-based BBCode type implementation?

    Any thoughts would be welcome.

    Andrew
    Seattle, WA

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    but nothing in between
    Can you define exactly how this should behave?

    ask it to automatically parse and/or validate the user input
    Do you mean check for valid HTML tags?

  3. #3
    Join Date
    Mar 2005
    Posts
    19

    Default

    So rather than strip out ALL the HTML, I want to allow some in there. For example, I'd like to allow <P>, <I>, <IMG SRC ... >, <A HREF ...> , etc., but not allow tables of stylesheets of Javascript.

    My question is, are there folks using any libraries to automatically parse the user input to strip out bad tags and allow good tags?

    It seems like one of these things that everyone probably has their home-cooked set of regexes for, but it would be nice to use something more standard.

  4. #4

    Default

    I see this thread is 3 years old but I did the due diligence of searching and found this thread. Is there such an API in Spring (or elsewhere) or should I just start writing some RegEx'es?

Similar Threads

  1. Problem with HibernateInterceptor
    By prane in forum Data
    Replies: 5
    Last Post: Oct 16th, 2007, 08:01 AM
  2. Replies: 11
    Last Post: Jun 1st, 2006, 04:30 PM
  3. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  4. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  5. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM

Posting Permissions

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