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

  • SEARCH
  • Home
  • 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 9228951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:27:10+00:00 2026-06-18T05:27:10+00:00

The question did arise from this one: Why does the browser modify the ID

  • 0

The question did arise from this one:
Why does the browser modify the ID of an HTML element that contains &#x?

Given the following web page:

<html>
  <head>
    <script type="text/javascript">
      // --------------------------------------------------------
      // could calling this method produce an XSS attack?
      // --------------------------------------------------------
      function decodeEntity(text){
        text = text.replace(/<(.*?)>/g,''); // strip out all HTML tags, to prevent possible XSS
        var div = document.createElement('div');
        div.innerHTML = text;
        return div.textContent?div.textContent:div.innerText;
      }
      function echoValue(){
        var e = document.getElementById(decodeEntity("/path/&#x24;whatever"));
        if(e) {
          alert(e.innerHTML);
        }
        else {
          alert("not found\n");
        }
      }
    </script>
  </head>
  <body>
    <p id="/path/&#x24;whatever">The Value</p>
    <button onclick="echoValue()">Tell me</button>
  </body>
</html>

The id of the <p> element contains characters that were escaped in order to prevent XSS attacks. The HTML part and JS part are generated by the server and the server inserts the same escaped value (which could origin from an unsecure source) on both parts.

The server escapes the following character ranges in the &#x format:

  • 0x00 – 0x2D
  • 0x3A – 0x40
  • 0x5B – 0x5E
  • 0x60
  • 0x7B – 0xFF
  • 0x0100 – 0xFFFF

In other words: the only characters that are not escaped are:

  • 0x2E – 0x39 (., /, 0123456789)
  • 0x41 – 0x5A (A – Z)
  • 0x5F (_)
  • 0x61 – 0x7A (a – z)

Now, I have to get access to that <p> through javascript. The function echoValue() in the referenced question always failed because the browser converts &#x24; to $ in the HTML part but leaves it as &#x24; in the JS part.

So, Gareth came up with an answer that is simple and works.

My concern is that the possibility of an XSS attack that was eliminated by escaping the dynamic strings will arise again when using the decodeEntity() function provided in the referenced answer.

Could anybody point out whether there might be security concerns (which?) or not (why not?)?

  • 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. Editorial Team
    Editorial Team
    2026-06-18T05:27:12+00:00Added an answer on June 18, 2026 at 5:27 am

    I first suggest you have a look at the following links discussing HTML sanitation in JavaScript and XSS in Javascript:

    • Sanitize/Rewrite HTML on the Client Side
    • How to prevent Javascript injection attacks within user-generated HTML

    Security Lesson no 1:
    Don’t reinvent the wheel. If something has been done before, chances are they did a better job than your ad hoc solution.

    Even though I can’t from the top of my mind find a way to exploit your simple regex I am not conviced it really captures all cases. The first link provides a solution that is more elaborated and has been reviewed and tested thoroughly.

    I also suggest you look at XSS Filter Evasion Cheat Sheet. Shows you real good what kind of nasty things people might come up with.

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

Sidebar

Related Questions

This is actually an extension of this question. The answers of that question did
Does any Java Interface implicitly implements java.lang.Object? This question arose when I did something
I have asked this question before but did not get the satisfied answer as
I did not find an answer to this question. I have a VOIP application.
I posted this question on Reddit Programming and did not get a single response.
My question is essentially the same as the following one but the answer did
Hello I asked this question to superuser but I did not get a good
This started as a question, but turned into a solution as I did some
This question arose out of something strange that I noticed after investigating this question
I was interviewed yesterday and this question arise: public class Main { public static

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.