T09 · Insecure Skill Coding Practices
- Location
scripts/stock-monitor.js:12- Finding
WooCommerce API Credentials May Be Transmitted over Plaintext HTTP
- Content
View full analysis
Vulnerability Details
File Location:
scripts/stock-monitor.js, lines 12–13, 19–21, 25–27, and 42–44
Vulnerability Type: Insecure transmission of reusable API credentials
Risk Level: HighVulnerable Code
js const https = require('https'); const http = require('http'); function wooCfg() { const cfg = JSON.parse(fs.readFileSync(WOO_API_PATH, 'utf8')); const auth = Buffer.from(`${cfg.consumer_key}:${cfg.consumer_secret}`).toString('base64'); return { base: cfg.url, auth }; } function httpGet(url, headers = {}) { return new Promise((resolve, reject) => { const mod = url.startsWith('https') ? https : http; mod.get(url, { headers }, (res) => { let data = ''; res.on('data', d => data += d); res.on('end', () => { try { resolve(JSON.parse(data)); } catch(e) { reject(new Error(`Parse error: ${data.slice(0,200)}`)); } }); }).on('error', reject); }); } async function fetchAllProducts(base, auth) { const products = []; let page = 1; while (true) { const url = `${base}/wp-json/wc/v3/products?per_page=100&page=${page}&status=publish`; const batch = await httpGet(url, { 'Authorization': `Basic ${auth}` });Technical Analysis
The store URL comes from
woo-api.jsonand is not validated to require HTTPS. The request helper selects Node.js's plaintexthttpmodule whenever the resulting URL does not start withhttps.At the same time, the WooCommerce consumer key and consumer secret are concatenated and Base64-encoded for an HTTP Basic Authentication header. Base64 provides no confidentiality. If
cfg.urluseshttp://, the reusable credentials are transmitted without transport encryption and can be read by a network-positioned attacker.Configuration tampering can also redirect requests to an attacker-controlled endpoint. Because the authorization header is sent to the configured destinatio ...[truncated 1713 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse the configured store address with
new URL(cfg.url)and reject it unlessprotocol === 'https:'. - Validate the hostname against the expected WooCommerce store hostname or a narrowly defined allowlist before constructing the authorization header.
- Remove plaintext HTTP fallback for authenticated WooCommerce requests and fail closed on invalid or unsupported URL schemes.
- Normalize and validate the base URL before appending API paths.
- Continue using a dedicated read-only WooCommerce API key with only the permissions required to retrieve product stock data.
- Document HTTPS as mandatory rather than merely showing it in the configuration example.
- Protect
woo-api.jsonwith restrictive filesystem permissions and rotate credentials if they may previously have been used over HTTP. - Consider rejecting redirects or validating every redirect destination so credentials cannot be forwarded to an unexpected host.
- Parse the configured store address with
