T09 · Insecure Skill Coding Practices
- Location
fal_api.py:85- Finding
API Credential May Be Disclosed Through Cross-Origin HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
fal_api.py, lines 60–65 and 85–99
Vulnerability Type: Unrestricted forwarding of an authorization header during automatic redirects
Risk Level: MediumVulnerable Code:
python self.api_key = api_key self.headers = { "Authorization": f"Key {self.api_key}", "Content-Type": "application/json", "Accept": "application/json", "User-Agent": "Mozilla/5.0 (compatible; Klawf/1.0; +https://clawdhub.com/agmmnn/fal-api)" }python def _request(self, method: str, url: str, data: dict = None) -> dict: """Make HTTP request to fal.ai API.""" req = urllib.request.Request(url, method=method) for k, v in self.headers.items(): if method == "GET" and k.lower() == "content-type": continue req.add_header(k, v) if data: req.data = json.dumps(data).encode() with urllib.request.urlopen(req, timeout=120) as response: return json.loads(response.read().decode())Technical Analysis
The client attaches the
FAL_KEYauthorization credential to every request and usesurllib.request.urlopen, which automatically processes HTTP redirects. The implementation does not validate redirect destinations, restrict redirects to the originalqueue.fal.runorigin, or explicitly remove theAuthorizationheader when the origin changes.Consequently, if a credential-bearing endpoint returns a redirect to a different origin and the authorization header is retained by the runtime redirect flow, the API key can be sent to that destination. The public API methods also accept arbitrary model path strings rather than limiting requests to the declared
MODELSallowlist, increasing the number of server-side paths that can be requested.Sending the API key to fal.ai is necessary for the Skill's declared functionality. The security issue is the lack of an origin boundary around subsequent redire ...[truncated 1205 chars]
- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for authenticated requests, or implement a custom
HTTPRedirectHandler. - Permit redirects only when the normalized destination uses HTTPS and its hostname is exactly
queue.fal.run. - Never forward
Authorizationwhen the scheme, hostname, or port changes. - Validate the final URL before every credential-bearing request rather than validating only the initial URL.
- Restrict
modelto keys or endpoint values in the declaredMODELSallowlist unless arbitrary endpoints are explicitly required. - Validate
request_idand endpoint components against conservative character allowlists before URL construction. - Consider using
Request.add_unredirected_headerfor credentials in conjunction with explicit redirect controls. - Add tests covering cross-origin, scheme-changing, protocol-relative, and malformed redirects.
- Disable automatic redirects for authenticated requests, or implement a custom
