T09 · Insecure Skill Coding Practices
- Location
scripts/layerback_convert.py:191- Finding
Configurable API Endpoint Can Exfiltrate the API Key and Source Image
- Content
View full analysis
Vulnerability Details
File Location:
scripts/layerback_convert.py, lines 65-75 and 191-217
Vulnerability Type: Unrestricted sensitive-data destination
Risk Level: HighVulnerable Code
python def api_json( method: str, url: str, api_key: str, *, body: Optional[bytes] = None, content_type: Optional[str] = None, ) -> Dict[str, Any]: headers = { "Accept": "application/json", "User-Agent": "LayerBack-Skill/1.0", "x-api-key": api_key, } if content_type: headers["Content-Type"] = content_typepython api_base_url = os.getenv( "LAYERBACK_API_BASE_URL", DEFAULT_API_BASE_URL ).strip().rstrip("/") parsed_base_url = urllib.parse.urlparse(api_base_url) local_hosts = {"localhost", "127.0.0.1", "::1"} if parsed_base_url.scheme != "https" and not ( parsed_base_url.scheme == "http" and parsed_base_url.hostname in local_hosts ): die("LAYERBACK_API_BASE_URL must use HTTPS (HTTP is allowed for localhost).") destination = ( Path(args.out).expanduser().resolve() if args.out else source.with_suffix(f".{args.format}") ) started = time.monotonic() try: created = api_json( "POST", f"{api_base_url}/convert", api_key, body=source.read_bytes(), content_type="application/octet-stream", )Technical Analysis
The converter reads
LAYERBACK_API_BASE_URLfrom the process environment and permits any endpoint that uses HTTPS. It does not restrict the hostname to the documented LayerBack service, validate an approved port, reject embedded user information, or require separate credentials for custom endpoints.The selected endpoint receives both the complete source image as the HTTP request body and
LAYERBACK_API_KEYin thex-api-keyheader. Consequently, control of the environment variable is sufficient to redirect s ...[truncated 1821 chars]- Remediation
View remediation
Remediation Suggestions
- Restrict normal operation to the exact official origin and expected API path:
- Scheme:
https - Hostname:
layerback.com - Expected base path:
/api/v1 - Reject unexpected ports, usernames, passwords, fragments, or query strings.
- Scheme:
- Remove
LAYERBACK_API_BASE_URLunless endpoint customization is essential to the supported functionality. - If custom endpoints are required for development, place them behind an explicit option such as
--allow-custom-api-endpoint, display the destination, and require interactive confirmation before transmitting any data. - Never send a production
LAYERBACK_API_KEYto a custom endpoint. Require a separate development credential or omit authentication for local test servers. - Validate the final constructed URL rather than validating only the raw base URL.
- Document the endpoint trust boundary and ensure users are told the exact hostname receiving the image and credential before conversion.
- Add tests confirming that lookalike domains, embedded credentials, unexpected ports, malformed URLs, and non-approved hosts are rejected.
- Restrict normal operation to the exact official origin and expected API path:
