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 56217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:30:00+00:00 2026-05-10T17:30:00+00:00

What’s an example of something dangerous that would not be caught by the code

  • 0

What’s an example of something dangerous that would not be caught by the code below?

EDIT: After some of the comments I added another line, commented below. See Vinko’s comment in David Grant’s answer. So far only Vinko has answered the question, which asks for specific examples that would slip through this function. Vinko provided one, but I’ve edited the code to close that hole. If another of you can think of another specific example, you’ll have my vote!

public static string strip_dangerous_tags(string text_with_tags) {     string s = Regex.Replace(text_with_tags, @'<script', '<scrSAFEipt', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'</script', '</scrSAFEipt', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'<object', '</objSAFEct', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'</object', '</obSAFEct', RegexOptions.IgnoreCase);     // ADDED AFTER THIS QUESTION WAS POSTED     s = Regex.Replace(s, @'javascript', 'javaSAFEscript', RegexOptions.IgnoreCase);      s = Regex.Replace(s, @'onabort', 'onSAFEabort', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onblur', 'onSAFEblur', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onchange', 'onSAFEchange', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onclick', 'onSAFEclick', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'ondblclick', 'onSAFEdblclick', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onerror', 'onSAFEerror', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onfocus', 'onSAFEfocus', RegexOptions.IgnoreCase);      s = Regex.Replace(s, @'onkeydown', 'onSAFEkeydown', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onkeypress', 'onSAFEkeypress', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onkeyup', 'onSAFEkeyup', RegexOptions.IgnoreCase);      s = Regex.Replace(s, @'onload', 'onSAFEload', RegexOptions.IgnoreCase);      s = Regex.Replace(s, @'onmousedown', 'onSAFEmousedown', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onmousemove', 'onSAFEmousemove', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onmouseout', 'onSAFEmouseout', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onmouseup', 'onSAFEmouseup', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onmouseup', 'onSAFEmouseup', RegexOptions.IgnoreCase);      s = Regex.Replace(s, @'onreset', 'onSAFEresetK', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onresize', 'onSAFEresize', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onselect', 'onSAFEselect', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onsubmit', 'onSAFEsubmit', RegexOptions.IgnoreCase);     s = Regex.Replace(s, @'onunload', 'onSAFEunload', RegexOptions.IgnoreCase);      return s; } 
  • 1 1 Answer
  • 0 Views
  • 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-10T17:30:00+00:00Added an answer on May 10, 2026 at 5:30 pm

    It’s never enough – whitelist, don’t blacklist

    For example javascript: pseudo-URL can be obfuscated with HTML entities, you’ve forgotten about <embed> and there are dangerous CSS properties like behavior and expression in IE.

    There are countless ways to evade filters and such approach is bound to fail. Even if you find and block all exploits possible today, new unsafe elements and attributes may be added in the future.

    There are only two good ways to secure HTML:

    • convert it to text by replacing every < with &lt;.
      If you want to allow users enter formatted text, you can use your own markup (e.g. markdown like SO does).

    • parse HTML into DOM, check every element and attribute and remove everything that is not whitelisted.
      You will also need to check contents of allowed attributes like href (make sure that URLs use safe protocol, block all unknown protocols).
      Once you’ve cleaned up the DOM, generate new, valid HTML from it. Never work on HTML as if it was text, because invalid markup, comments, entities, etc. can easily fool your filter.

    Also make sure your page declares its encoding, because there are exploits that take advantage of browsers auto-detecting wrong encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One other possible solution would be to create views in… May 11, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer Check out jQuery Uploadify EDIT: There's also a similar question:… May 11, 2026 at 5:16 pm
  • Editorial Team
    Editorial Team added an answer Found here: http://aaron-powell.spaces.live.com/blog/cns!91A824220E2BF369!150.entry DataContractJsonSerializer The primary purpose of the DataContractJsonSerializer… May 11, 2026 at 5:16 pm

Related Questions

I am currently running into a problem where an element is coming back from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
What is a programmer’s life like?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.