Skip to content

Security Weakness: Origin validation using in function #18

Open

Description

File: /app/app/javascript/widget/utils.ts
Function: isValidHost

Issue: The isValidHost function uses url.host.endsWith(ROOT_DOMAIN) and url.host.endsWith(customDomain) to validate the origin of postMessages. This method is potentially insecure because it can be bypassed if an attacker registers a domain that ends with the expected ROOT_DOMAIN or customDomain (e.g., attacker.com.trusted.com would pass if trusted.com is the domain).

Impact: Currently, the message handlers using isValidHost (in embed.ts and overlay.ts) only pass data to safe sinks (style.height, ariaLabel), so there is no immediate XSS vulnerability. However, this weak validation poses a future risk. If new message handlers are added or existing ones are modified to use message data in dangerous sinks (like innerHTML, eval, location.href, etc.), this vulnerability could become exploitable.

Recommendation: Refactor isValidHost to perform stricter origin validation. Options include:

  1. Exact matching against a list of known, trusted origins.
  2. Using a more robust library or method for suffix checking that accounts for domain boundaries (e.g., ensuring the character before the suffix is a dot .)
  3. Comparing against process.env.ROOT_DOMAIN, process.env.SHORT_DOMAIN, and customDomain using exact equality checks (===) if subdomains are not expected or required for messaging.

Addressing this proactively will prevent potential future XSS vulnerabilities.

Activity

  1. msrkp commented on Apr 12, 2025

    @msrkp
    Contributor

    This is valid. A domain with testgumroad.com can send following postmessages.

    top.postMessage({"type":"height","height":10},'*')
    
    

    Unfortunately no dangerous sinks

  2. transferred this issue fromon Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions