This website uses cookies

To provide the highest level of service we use cookies on this site.
Your continued use of the site means that you agree to their use in accordance with our terms and conditions.

Pentest Chronicles

Unicode's role in XSS vulnerabilities.

Jacek Siwek

March 04, 2024

Web application security is a crucial concern in today's digital landscape. Cross-Site Scripting (XSS) attacks pose a significant threat to web applications, allowing attackers to inject malicious scripts into trusted websites. Request validation mechanisms are implemented to mitigate such attacks by blocking certain characters or patterns commonly associated with malicious code. However, recent discoveries suggest that there is a possibility of bypassing these validation mechanisms using Unicode characters, which could lead to successful XSS attacks.


One method of bypassing request validation involves leveraging Unicode characters as substitutes for blocked characters. The manipulation lies in exploiting specific behaviors of database systems, such as Microsoft SQL Server, which convert certain Unicode characters into their ASCII equivalents during data storage. This behavior can inadvertently allow an ASP.Net application to become vulnerable to XSS attacks, even when employing an HTML vector.
In the context of web security, an HTML vector refers to any method or technique that leverages HTML content to carry out malicious activities.

Before we delve into our example, it's crucial to understand why databases, such as Microsoft SQL Server, sometimes convert Unicode characters into their ASCII equivalents. This behavior often depends on the database's encoding settings, which may not be explicitly configured to handle Unicode characters uniformly. By default, some databases attempt to optimize storage or maintain compatibility by converting certain Unicode characters into ASCII. This conversion process, while seemingly harmless, can open up vulnerabilities in web applications, especially when the transformed characters bypass security measures designed to filter out potential XSS attack vectors.

Now to illustrate the problem, let’s consider the following example:

<script>alert(document.domain)</script>

If this code snippet is saved and returned by the database, the application may interpret it as a harmless HTML tag. However, due to the conversion of the Unicode characters into their ASCII equivalents by the database, the resulting code would be:

<script>alert(1)</script>

In this example, the Unicode characters used and their corresponding Unicode and ASCII codes are as follows:

Char Unicode
< U+FF1C
> U+FF1E

To better illustrate the difference, we have the following three signs:
< ﹤ <

where:
< is the less-than sign (U+003C)
﹤ is the small less-than sign (U+FE64)
< is the fullwidth less-than sign (U+FF1C)

The XSS vulnerability arises from the failure of the request validation mechanism to properly handle the converted Unicode characters. Although the initial input may appear benign and conform to the allowed character set, the subsequent conversion can introduce unexpected behavior, resulting in the execution of malicious code.

In the provided example, the use of Unicode characters allows an attacker to evade the restrictions imposed by the validation mechanism. By replacing the blocked characters (< and >) with visually similar Unicode characters (< and >), the attacker tricks the application into treating the injected code as harmless HTML, thereby bypassing the validation checks.

To mitigate the risk of such bypasses and protect against XSS attacks, it is crucial to implement a multi-layered approach to web application security. Consider the following best practices:

  • Implement Context-Aware Output Encoding: Use output encoding libraries or frameworks that enforce context-aware escaping to neutralize potential XSS vectors. This approach ensures that any user-supplied input is appropriately sanitized before being rendered.
  • Employ a Web Application Firewall (WAF): Implement a WAF that includes XSS protection capabilities. A WAF can help detect and block malicious requests, including those attempting to bypass validation mechanisms using Unicode characters.
  • Validate and Sanitize User Input: Conduct thorough input validation and sanitization to ensure that user-supplied data does not contain potentially malicious scripts or characters.






  • #WebSecurity #Cybersecurity #InfoSec #ApplicationSecurity


    Next Pentest Chronicles

    When Usernames Become Passwords: A Real-World Case Study of Weak Password Practices

    Michał WNękowicz

    9 June 2023

    In today's world, ensuring the security of our accounts is more crucial than ever. Just as keys protect the doors to our homes, passwords serve as the first line of defense for our data and assets. It's easy to assume that technical individuals, such as developers and IT professionals, always use strong, unique passwords to keep ...

    SOCMINT – or rather OSINT of social media

    Tomasz Turba

    October 15 2022

    SOCMINT is the process of gathering and analyzing the information collected from various social networks, channels and communication groups in order to track down an object, gather as much partial data as possible, and potentially to understand its operation. All this in order to analyze the collected information and to achieve that goal by making …

    PyScript – or rather Python in your browser + what can be done with it?

    michał bentkowski

    10 september 2022

    PyScript – or rather Python in your browser + what can be done with it? A few days ago, the Anaconda project announced the PyScript framework, which allows Python code to be executed directly in the browser. Additionally, it also covers its integration with HTML and JS code. An execution of the Python code in …

    Any questions?

    Happy to get a call or email
    and help!

    Terms and conditions
    © 2023 Securitum. All rights reserved.