T05 · Unauthorized Access and Privilege Escalation
- Location
openrouter_free.py:14- Finding
Silent Access to a Hard-Coded Root Workspace Credential File
- Content
View full analysis
Vulnerability Details
File Location:
openrouter_free.py, lines 14–33
Vulnerability Type: Unauthorized credential access and insecure credential handling
Risk Level: MediumVulnerable Code
python API_KEY = os.environ.get('OPENROUTER_API_KEY', '') if not API_KEY: try: with open('/root/.openclaw/workspace/.env', 'r') as f: for line in f: line = line.strip() if line and not line.startswith('#') and 'OPENROUTER_API_KEY' in line: API_KEY = line.split('=', 1)[1].strip() except: pass API_BASE = "https://openrouter.ai/api/v1" HEADERS = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json", "HTTP-Referer": "https://openclaw.ai", "X-Title": "OpenClaw Free Models" }The credential is transmitted by the following request operations:
python resp = requests.get(f"{API_BASE}/models", headers=HEADERS, timeout=15)python resp = requests.post(url, headers=HEADERS, json=data, timeout=60)Technical Analysis
When
OPENROUTER_API_KEYis absent from the process environment, the program silently attempts to read/root/.openclaw/workspace/.env. This fixed, privileged path may belong to a different workspace or execution context and is not the project-local.envimplied by the documentation.This behavior violates least privilege because listing models or submitting a chat request does not require searching another workspace for credentials. If the process can read the file, it may acquire and use a key that the invoking user did not explicitly provide to this Skill.
Credential parsing is also imprecise: the condition checks whether
OPENROUTER_API_KEYoccurs anywhere in a line rather than requiring an exact variable name. A line such asBACKUP_OPENROUTER_API_KEY=valuecould therefore be selected unintentionally. The bareexceptsuppr ...[truncated 1969 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the fallback that reads
/root/.openclaw/workspace/.env. - Require callers to provide
OPENROUTER_API_KEYexplicitly through the process environment or an approved secret manager. - If
.envsupport is required, load only a project-local or explicitly supplied path after obtaining user consent. Resolve and validate the path to prevent crossing workspace boundaries. - Parse environment files with a maintained parser and require an exact key-name match rather than substring matching.
- Replace the bare
exceptwith specific exception handling, such asFileNotFoundError,PermissionError, and parsing errors. Report failures without printing secret values. - Do not place an authorization header on endpoints that can be accessed without authentication. Construct request headers per operation.
- Document exactly which information is transmitted to OpenRouter: the API key, model identifier, and user-provided chat content.
- Keep credentials out of logs and error messages, apply restrictive file permissions where local secret files are explicitly used, and rotate any key suspected of having been accessed by an unintended workspace.
- Remove the fallback that reads
