T09 · Insecure Skill Coding Practices
- Location
scripts/openclaw_api_client.mjs:8- Finding
Unrestricted API Base URL Can Expose Bearer Credentials and Uploaded Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/openclaw_api_client.mjs, lines 8-18, 77-89, and 196-221
Vulnerability Type: Unvalidated network destination for sensitive authenticated requests
Risk Level: HighComplete Code Snippet
js const DEFAULT_BASE_URL = 'https://openclaw-as-a-service.com/api'; const MAX_UPLOAD_BYTES = 5 * 1024 * 1024; function normalizeBaseUrl(rawValue) { const trimmed = String(rawValue || '').trim(); if (!trimmed) { return DEFAULT_BASE_URL; } const withoutTrailing = trimmed.replace(/\/+$/, ''); return withoutTrailing.endsWith('/api') ? withoutTrailing : `${withoutTrailing}/api`; } const API_BASE_URL = normalizeBaseUrl(process.env.OPENCLAW_API_BASE_URL); const API_KEY = String(process.env.OPENCLAW_API_KEY || '').trim();js async function apiRequest(method, pathname, { query = null, body = undefined, expect = 'json' } = {}) { ensureApiKey(); const url = new URL(pathname.replace(/^\//, ''), `${API_BASE_URL.replace(/\/+$/, '')}/`); if (query && typeof query === 'object') { for (const [key, value] of Object.entries(query)) { if (value === undefined || value === null || value === '') { continue; } url.searchParams.set(key, String(value)); } } const response = await fetch(url, { method, headers: { Authorization: `Bearer ${API_KEY}`, ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}) }, body: body !== undefined ? JSON.stringify(body) : undefined });js for (const filePath of files) { const relativeFile = path.relative(absoluteSource, filePath); const buffer = await fs.readFile(filePath); if (buffer.length > MAX_UPLOAD_BYTES) { skipped.push({ path: filePath, reason: 'too_large' }); continue; } if (!isLikelyTextFile(buffer)) { skipped.push({ path: filePath, reason: 'binary_or_unsupp ...[truncated 3860 chars]- Remediation
View remediation
Remediation Suggestions
- Parse the configured base URL and require
https:before sending credentials. - Allow the documented production hostname by default. If custom deployments must be supported, require an explicit opt-in setting and display the exact destination before transmitting the bearer token.
- Reject URLs containing embedded usernames or passwords, unsupported schemes, fragments, or unexpected ports.
- Consider maintaining a configurable hostname allowlist for managed environments.
- Bind credentials to approved origins and never automatically forward the bearer token across redirects to a different origin.
- Add default recursive-upload exclusions for
.env,.git, private-key formats, cloud credential directories, token stores, and other common secret-bearing files. - Support an ignore file or explicit include patterns so users can constrain recursive uploads.
- Present a pre-upload summary of destination host, source directory, file count, and sensitive-file warnings, then require confirmation where interactive operation is possible.
- Update
SKILL.mdto explain that custom endpoints receive the bearer token and that recursive uploads may contain secrets. - Add tests confirming rejection of HTTP URLs, unexpected schemes, disallowed hosts, cross-origin redirects, and sensitive files during recursive upload.
- Parse the configured base URL and require
