T09 · Insecure Skill Coding Practices
- Location
lib/api.js:25- Finding
Unrestricted HTTPS Requests and Unvalidated Redirect Destinations
- Content
View full analysis
{ if (redirects > 5) { reject(new Error('Too many redirects')); return; } const parsedUrl = new URL(url); const options = { hostname: parsedUrl.hostname, path: parsedUrl.pathname + parsedUrl.search, method: 'GET', headers: { 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'PMC-Harvest/1.0' } }; https.get(options, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { const location = res.headers.location; const redirectUrl = location.startsWith('http') ? location : new URL(location, parsedUrl.origin).href; return httpGet(redirectUrl, redirects + 1).then(resolve).catch(reject); } let stream = res; const encoding = res.headers['content-encoding']; if (encoding === 'gzip') { stream = res.pipe(zlib.createGunzip()); } else if (encoding === 'deflate') { stream = res.pipe(zlib.createInflate()); } let data = ''; stream.on('data', chunk => data += chunk); stream.on('end', () => { if (res.statusCode >= 200 && res.statusCode < 300) { resolve(data); } else { reject(new Error(`HTTP ${res.statusCode}`)); } }); stream.on('error', reject); }).on('error', reject); }); } ``` The unrestricted helper is also exposed as part of the public module API: ```javascript module.exports = { searchPMC, getSummaries, fetchFullText, fetchAbstract, parseJATS, harvestJournals, httpGet }; ``` ### Technical Analysis Th ...[truncated 2821 chars]- Remediation
View remediation
