Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 128419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:37:57+00:00 2026-05-11T05:37:57+00:00

Jeff actually posted about this in Sanitize HTML . But his example is in

  • 0

Jeff actually posted about this in Sanitize HTML. But his example is in C# and I’m actually more interested in a Java version. Does anyone have a better version for Java? Is his example good enough to just convert directly from C# to Java?

[Update] I have put a bounty on this question because SO wasn’t as popular when I asked the question as it is today (*). As for anything related to security, the more people look into it, the better it is!

(*) In fact, I think it was still in closed beta

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:37:57+00:00Added an answer on May 11, 2026 at 5:37 am

    Don’t do this with regular expressions. Remember, you’re not protecting just against valid HTML; you’re protecting against the DOM that web browsers create. Browsers can be tricked into producing valid DOM from invalid HTML quite easily.

    For example, see this list of obfuscated XSS attacks. Are you prepared to tailor a regex to prevent this real world attack on Yahoo and Hotmail on IE6/7/8?

    <HTML><BODY> <?xml:namespace prefix='t' ns='urn:schemas-microsoft-com:time'> <?import namespace='t' implementation='#default#time2'> <t:set attributeName='innerHTML' to='XSS&lt;SCRIPT DEFER&gt;alert(&quot;XSS&quot;)&lt;/SCRIPT&gt;'> </BODY></HTML> 

    How about this attack that works on IE6?

    <TABLE BACKGROUND='javascript:alert('XSS')'> 

    How about attacks that are not listed on this site? The problem with Jeff’s approach is that it’s not a whitelist, as claimed. As someone on that page adeptly notes:

    The problem with it, is that the html must be clean. There are cases where you can pass in hacked html, and it won’t match it, in which case it’ll return the hacked html string as it won’t match anything to replace. This isn’t strictly whitelisting.

    I would suggest a purpose built tool like AntiSamy. It works by actually parsing the HTML, and then traversing the DOM and removing anything that’s not in the configurable whitelist. The major difference is the ability to gracefully handle malformed HTML.

    The best part is that it actually unit tests for all the XSS attacks on the above site. Besides, what could be easier than this API call:

    public String toSafeHtml(String html) throws ScanException, PolicyException {      Policy policy = Policy.getInstance(POLICY_FILE);     AntiSamy antiSamy = new AntiSamy();     CleanResults cleanResults = antiSamy.scan(html, policy);     return cleanResults.getCleanHTML().trim(); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Jeff wrote about getting a file version/datestamp a while back. Visual studio doesn't increment
Jeff Atwood wrote about this here , and while I understand the theoretical performance
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Jeff mentioned the concept of 'Progressive Enhancement' when talking about using JQuery to write
Jeff has previously blogged about using the cache to perform "out of band" processing
Jeff's recent article linked to a time management example of the First Fit Decreasing
Let me apologize in advance for the simplicity of this question (I heard Jeff's
Suppose I have this data: Employee Task IsCurrent -------- ---- --------- Jeff 1 Yes
I'm not even sure if this is even possible, but I've just started WPF
I'm not familiar with this format: {d:{\Table\:[{\pCol\:12345,\fCol\:\jeff\,\lCol\:\Smith\,\dId\:1111111,\tDate\:\\\/Date(1153033200000-0700)\\/\}]}} I'm using Newtonsoft to serialize my DataSet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.