T09 · Insecure Skill Coding Practices
- Location
scripts/nano_banana_generate.py:25- Finding
Bearer API Key May Be Forwarded Across Origins During HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/nano_banana_generate.py, lines 25-38
Vulnerability Type: Credential disclosure through unrestricted HTTP redirects
Risk Level: Mediumpython request = urllib.request.Request( url, data=body, headers={ "Content-Type": "application/json", "Authorization": f"Bearer {api_key}", "User-Agent": user_agent, "Accept": "application/json, text/plain, */*", "Origin": "https://nanophoto.ai", "Referer": "https://nanophoto.ai/", }, method="POST", ) try: with urllib.request.urlopen(request, timeout=timeout) as response:Technical Analysis
The script places the NanoPhoto API key in the
Authorizationheader and submits requests usingurllib.request.urlopen. The defaulturllibopener supports automatic HTTP redirects, while this implementation neither disables redirects nor validates the destination scheme, hostname, port, or origin of a redirected request.Consequently, a redirect response could move the authenticated request outside the intended
https://nanophoto.aiorigin. Depending on redirect handling, the bearer credential may be attached to the redirected request. Authentication headers should never be allowed to cross an origin boundary without an explicit security decision.Exploitation requires an attacker to influence the response from the configured NanoPhoto endpoint, such as through service compromise, DNS or routing compromise, or another condition that permits a malicious redirect. The destination URLs themselves are fixed constants and cannot be directly supplied by an ordinary command-line user, which limits exploitability.
Attack Path
- The user runs the Skill with a valid
NANOPHOTO_API_KEY. - The script sends an authenticated request to a fixed NanoPhoto API endpoint.
- An attacker-controlled or compromised endpoint returns an HTTP redirect ...[truncated 690 chars]
- The user runs the Skill with a valid
- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for authenticated API requests and treat redirect responses as errors.
- Alternatively, implement a custom redirect handler that only permits HTTPS destinations whose normalized hostname is exactly
nanophoto.aiand whose expected port is used. - Remove the
Authorizationheader whenever the scheme, host, or port changes. - Apply a strict redirect-count limit to prevent redirect loops.
- Consider certificate pinning only if the service has an operationally reliable pin-rotation process.
- Add automated tests confirming that bearer credentials are not transmitted to a different origin following
301,302,303,307, or308responses.
