HawkScan Test Info for Relative Path Confusion

Relative Path Confusion


Plugin Id: 10051 | CWE: 20


To mitigate the vulnerability of Relative Path Confusion, the following steps can be taken:

  1. Use absolute URLs: Instead of using relative URLs for resources (CSS, images, etc.), use absolute URLs. This ensures that the correct path is always followed and eliminates any confusion.


    <link rel="stylesheet" href="https://example.com/css/style.css">
  2. Validate user input: Implement strict input validation to prevent any malicious input from being processed by the web server. This helps to prevent any potential attacks that exploit the confusion in relative paths.


    import re
    def validate_input(input):
        if re.match(r'^[a-zA-Z0-9_-]+$', input):
            return True
            return False
  3. Implement Content Security Policy (CSP): CSP allows you to specify the sources from which your web application can load resources, such as scripts, stylesheets, and images. By defining a strict CSP, you can prevent the browser from loading resources from unexpected or untrusted sources.


    Content-Security-Policy: default-src 'self';


The vulnerability of Relative Path Confusion occurs when a web server is configured to serve responses to ambiguous URLs in a way that can lead to confusion about the correct “relative path” for the URL. This confusion arises when resources (such as CSS, images, etc.) are specified in the page response using relative URLs instead of absolute URLs.

In an attack scenario, if the web browser parses the “cross-content” response in a permissive manner or can be tricked into permissively parsing the “cross-content” response (e.g., through framing techniques), the browser may be fooled into interpreting HTML as CSS (or other content types). This can lead to a Cross-Site Scripting (XSS) vulnerability, allowing an attacker to inject malicious code into the web page and potentially compromise user data or perform unauthorized actions.


The Relative Path Confusion vulnerability poses several risks to the security of a web application:

  1. Cross-Site Scripting (XSS) attacks: By tricking the web browser into interpreting HTML as CSS (or other content types), an attacker can inject malicious code into the web page. This can lead to the execution of arbitrary scripts, theft of sensitive information, or unauthorized actions on behalf of the user.

  2. Data leakage: If the web browser misinterprets the relative path and loads resources from unexpected or untrusted sources, it may inadvertently leak sensitive information to the attacker. This can include session tokens, user credentials, or other confidential data.

  3. Compromised user experience: The confusion in relative paths can result in broken or missing resources on the web page. This can lead to a degraded user experience, loss of functionality, or even complete unavailability of certain features.

It is crucial to address and remediate the Relative Path Confusion vulnerability to ensure the security and integrity of the web application and protect users from potential attacks.