T09 · Insecure Skill Coding Practices
- Location
scripts/ecommerce_ad_copy_generator_free.py:25- Finding
User-Controlled Identifier Is Inserted into Payment URL Without Encoding
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ecommerce_ad_copy_generator_free.py, lines 25-30
Vulnerability Type: Improper encoding of a user-controlled URL query parameter
Risk Level: Lowpython def _payment_url(user_id: str) -> str: template = os.getenv("SKILLPAY_PAYMENT_URL_TEMPLATE", "").strip() if template: return template.format(user_id=user_id) base = os.getenv("SKILLPAY_TOPUP_BASE_URL", "https://skillpay.me/pay").strip() sep = "&" if "?" in base else "?" return f"{base}{sep}user_id={user_id}"Technical Analysis
The
_payment_urlfunction inserts the user-controlleduser_iddirectly into a URL template or query string. The input validation elsewhere in the application only requiresuser_idto be nonempty; it does not impose a safe identifier grammar, length limit, or URL encoding.Consequently, reserved URL characters such as an ampersand, number sign, equals sign, or question mark can change the structure or interpretation of the generated payment URL. In the fallback path, an attacker can inject additional query parameters. The configured template path has the same underlying weakness because
str.formatperforms no contextual URL encoding.This is a URL construction vulnerability rather than server-side request forgery: the audited code returns the generated URL in JSON but does not make a network request itself.
Attack Path
- An attacker supplies a crafted
user_id, for example through the--user-idcommand-line argument or an input JSON payload. - The value passes validation because it is nonempty.
run()passes the identifier to_payment_url()._payment_url()interpolates it without percent-encoding.- A value such as
victim&redirect=https://example.invalidproduces a URL containing an injectedredirectquery parameter. - The modified URL is returned in the
upgrade.payment_urlfield. - If a cons ...[truncated 785 chars]
- An attacker supplies a crafted
- Remediation
View remediation
Remediation Suggestions
- Validate
user_idagainst an explicit allowlist appropriate for the identifier format, such as ASCII letters, digits, underscores, and hyphens, and enforce a reasonable maximum length. - Build query strings with
urllib.parse.urlencoderather than direct string concatenation. - Parse and reconstruct configured base URLs with
urllib.parse.urlsplit,parse_qsl, andurlunsplitso existing query parameters are preserved safely. - Avoid applying
str.formatdirectly to a URL template with unencoded user input. Percent-encode the identifier before substitution, or replace URL templates with structured URL construction. - Validate configured payment URLs to permit only expected HTTPS origins if deployment configuration is not fully trusted.
- Add tests covering ampersands, number signs, equals signs, question marks, Unicode input, duplicate parameters, and base URLs that already contain query strings.
- Validate
