T09 · Insecure Skill Coding Practices
- Location
scripts/aifans-runtime-bridge.js:155- Finding
Bearer Credential Exfiltration Through a Configurable API Origin
- Content
View full analysis
Vulnerability Details
File Location:
scripts/aifans-runtime-bridge.js:155-164, 232-275, 331-340;SKILL.md:21-22, 33
Vulnerability Type: Unvalidated destination for authenticated network requests
Risk Level: HighComplete Code Snippet
js function buildAgentRequestHeaders({ stateDir, extraHeaders = {} }) { const session = loadRuntimeSession({ stateDir }); const accessValue = resolveAgentAccessValue(session.privateMaterial); if (!accessValue) { throw new Error('No private runtime material available for agent requests.'); } return { Authorization: `Bearer ${accessValue}`, ...extraHeaders, }; }js function createAgentActionRequest({ action, stateDir, baseUrl = process.env.AIFANS_BASE_URL || DEFAULT_BASE_URL, params = {}, query = {}, body, }) { const actionConfig = AGENT_ACTIONS[action]; if (!actionConfig) { throw new Error(`Unsupported agent action: ${action}`); } const headers = actionConfig.signed ? buildAgentRequestHeaders({ stateDir }) : {}; const request = { url: buildActionUrl({ baseUrl, pathTemplate: actionConfig.path, params, query }), init: { method: actionConfig.method, headers, }, }; if (actionConfig.body) { request.init.headers = { 'Content-Type': 'application/json', ...request.init.headers, }; request.init.body = JSON.stringify(body ?? {}); } if (actionConfig.multipart) { request.init.body = createMultipartBody(body); } return request; } async function executeAgentAction(options) { const request = createAgentActionRequest(options); const response = await fetch(request.url, request.init); const text = await response.text(); const payload = text ? JSON.parse(text) : null; return { ok: response.ok, status: response.status, payload, }; }` ...[truncated 2331 chars]
- Remediation
View remediation
Remediation Suggestions
- Maintain an explicit allowlist of trusted HTTPS origins and reject every other origin before constructing authenticated headers.
- Remove the unrestricted
--base-urloverride for signed production actions, or require the configured origin to match an administrator-controlled allowlist. - Reject non-HTTPS URLs except for an explicitly enabled local development mode.
- Configure redirects manually or disable them, and never forward credentials across an origin change.
- Validate the final response URL before processing a redirected response.
- Separate development credentials from production credentials.
- Log only the selected origin and action name, never authorization values.
- Rotate the Agent credential if an untrusted base URL may previously have been configured.
