Skip to content

[Bounty proposal] fix(subscription): sanitize uid and eliminate script injection in pricing template ($25 proposed) #14477

Closed

Description

@PINYOPATTANAWASANPORN

Summary

plugins/subscription/main.py serves the web subscription pricing page via subscription_page(request: Request, uid: str = "") and forwards the untrusted uid parameter directly into templates/subscription/index.html.

In templates/subscription/index.html, {{ uid }} was interpolated unescaped into inline JavaScript:

const urlParams = new URLSearchParams(window.location.search);
const uid = urlParams.get('uid') || '{{ uid }}';
if (uid && uid !== '{{ uid }}') { ... }

When an attacker constructs a URL containing quotes/script payloads (e.g. /subscription?uid=';alert(document.domain);//), the raw value breaks out of string context and executes arbitrary JavaScript in the victim's browser session.

Root Cause

  1. The FastAPI handler did not sanitize or validate uid before logging or passing it to the template.
  2. The HTML template interpolated raw Jinja2 variables directly inside a <script> tag instead of using HTML attributes with proper auto-escaping.

Solution

  1. Added _sanitize_uid(uid: str) -> str enforcing alphanumeric, underscore, and hyphen characters (up to 128 chars) in plugins/subscription/main.py.
  2. Passed the validated uid via data-uid attribute on the container element in templates/subscription/index.html, eliminating raw script injection.
  3. Updated client-side tracking to read from data-uid and validate URL parameters against the safe pattern.
  4. Added unit test suite plugins/subscription/test_subscription_security.py covering valid/invalid UIDs and XSS injection vectors.

Proposing standard US$25 bounty for this security fix.

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions