Skip to content

Potential Security Vulnerability - DOM-based XSS #41

@shwet04

Description

@shwet04

The jc.parseHTML function appears to be vulnerable to DOM-based XSS because it directly uses innerHTML to insert a user-provided string without proper sanitization. If a user can control the input string, they can inject arbitrary HTML and JavaScript code, which will be executed in the user's browser.

Path :- https://github.com/xujeff/tianti/blob/master/tianti-modules/tianti-module-admin/src/main/webapp/static/js/common.js#L396

Image

To reproduce the vulnerability, you can inject the following payload as the str parameter:

"<img src=x onerror=alert('XSS Vulnerability')>"

For example, if the str parameter comes from a URL parameter, a user could craft a malicious URL like this:

[Application URL]?param=<img src=x onerror=alert('XSS Vulnerability')>

When this HTML is processed by jc.parseHTML, the onerror event will trigger, and the alert function will execute.

Impact:

  1. A successful XSS attack could allow an attacker to:
  2. Steal sensitive user data (e.g., cookies, session tokens).
  3. Perform unauthorized actions on behalf of the user.
  4. Deface the website.
  5. Redirect users to malicious websites.
  6. Install malware.

POC code ::

Image

Image

Recommended Fix:

To mitigate this vulnerability, I recommend the following:

  1. Use textContent if possible: If the function is intended to parse plain text, use textContent instead of innerHTML.
  2. Sanitize user input: If HTML parsing is necessary, sanitize the input string to remove any potentially malicious code before assigning it to innerHTML. Libraries like DOMPurify are designed for this purpose.
  3. Contextual Output Encoding: If you must use innerHTML, encode the user provided string.

Please let me know your thoughts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions