This is some vulnerable JavaScript code:

    var payload = unescape(document.location.hash.substr(1));
    document.body.innerText = "The payload is: " + payload;

When I tried exploiting it with this input

http://localhost/xss.html#<img src=x onerror=alert(0)>

it worked fine, popping up the alert. My case is slightly different, there's a little filter that prevents the exploit:

    var payload = unescape(document.location.hash.substr(1));
    payload = payload.split('=')[0];  // <------- The new filter
    document.body.innerText = "The payload is: " + payload;

It truncates everything after the "=" character, which means I can't inject attributes. I already tried the following, but it did not work:

  • HTML encode the equal character (onerror&equal;alert())
  • <script>alert(0);</script>

Anyone have an idea what I can do to bypass this filter?

  • Owh, sorry i forgot to mention this - The payload works on Internet Explorer. IE does not have that auto url encoding feature. – AlmightyGoat Apr 8 '18 at 18:38

I think it is safe to say at this point that there is no trivial/text-book bypass for this filter using a modern browser. I shared this snippet of code with a group of friends and colleagues who I consider proficient in XSS and none of them could construct a bypass.


You can try the encoded character equivalent to what you are trying to input. Try using URL encoding on the payload portion of your input to bypass this filter.

For instance, you can URL encode "=" to %3D or URL encode <img src=x onerror=alert(0)> to %3Cimg+src%3Dx+onerror%3Dalert%280%29%3E

This will bypass the filter if it is expecting "="

Alternatively, since it looks like you are running this on your localhost, use a proxy tool such as Burp Suite to intercept your requests/responses, you can play around with different payloads to test your XSS payloads.

  • The question contains the code of the filter: it will decode any URL-encoded payload. This bypass, quite useful in other cases, can't work here. – Benoit Esnard Sep 27 '18 at 14:08

If you haven't already gotten an answer have you tried the ASCII equivalent of '=', &#61? I don't have a handy way to test, but might work in your case.


you should encode it. something like this will work:

 eval(String.fromCharCode(/*list of codes of payload*/))

you need to split payload into the caracters and convert them one-by-one into ints. you can make a script for it.

also you might want to look at atob and btoa.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.