T09 · Insecure Skill Coding Practices
- Location
scripts/hospitable-read.js:3- Finding
Bearer Token Can Be Exfiltrated Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/hospitable-read.js, lines 3-4 and 27-29
Vulnerability Type: Unrestricted credential forwarding
Risk Level: HighVulnerable Code
js const token = process.env.HOSPITABLE_TOKEN; const base = process.env.HOSPITABLE_BASE_URL || 'https://public.api.hospitable.com/v2/';js function requestJson(path) { return new Promise((resolve, reject) => { const url = new URL(path, base); const req = https.request(url, { method: 'GET', headers: { Authorization: `Bearer ${token}`, Accept: 'application/json' } }, (res) => {The same unsafe pattern also occurs in
scripts/hospitable-write-probe.js, lines 3-4 and 13-19:js const token = process.env.HOSPITABLE_TOKEN; const base = process.env.HOSPITABLE_BASE_URL || 'https://public.api.hospitable.com/v2/';js const url = new URL(pathname, base); const req = https.request(url, { method, headers: { Authorization: `Bearer ${token}`, Accept: 'application/json', ...(body ? { 'Content-Type': 'application/json' } : {}) }Technical Analysis
Both scripts allow the API base URL to be overridden through
HOSPITABLE_BASE_URL, but neither verifies that the resulting URL belongs to the official Hospitable API origin. The scripts then unconditionally attachHOSPITABLE_TOKENas an HTTP bearer credential.Because Node.js
https.request()accepts any HTTPS destination, an attacker who can influence the process environment can redirect authenticated requests to an attacker-controlled server. HTTPS only protects the connection in transit; it does not establish that the destination is authorized to receive the credential.Attack Path
- An attacker gains influence over the environment used to invoke either script, such as through a poisoned environment file, CI configuration, process launcher, or manipulated automation configuration.
- The attacke ...[truncated 985 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the configurable base URL from production operation when it is unnecessary.
- If an override is required for testing, parse and validate it before constructing any request:
- Require the
https:protocol. - Require the exact origin
https://public.api.hospitable.com. - Reject embedded credentials, unexpected ports, lookalike hostnames, and subdomains.
- Require the
- Validate the final resolved URL immediately before attaching the authorization header.
- Never forward the bearer token following a cross-origin redirect; preferably disable redirects entirely.
- Separate production and testing credentials, and ensure test endpoints can only receive restricted test tokens.
- Rotate the bearer token if either script has previously run with an untrusted
HOSPITABLE_BASE_URL. - Apply the same correction to both
hospitable-read.jsandhospitable-write-probe.js.
Example origin enforcement:
js const OFFICIAL_ORIGIN = 'https://public.api.hospitable.com'; const baseUrl = new URL( process.env.HOSPITABLE_BASE_URL || `${OFFICIAL_ORIGIN}/v2/` ); if (baseUrl.protocol !== 'https:' || baseUrl.origin !== OFFICIAL_ORIGIN) { throw new Error('Untrusted Hospitable API origin'); } const url = new URL(path, baseUrl); if (url.origin !== OFFICIAL_ORIGIN) { throw new Error('Refusing to forward credentials to another origin'); }
