T09 · Insecure Skill Coding Practices
- Location
http-retry-circuit-breaker.js:253- Finding
Request timeout does not cancel the underlying HTTP operation
- Content
View full analysis
setTimeout(() => reject(new Error('Request timeout')), this.config.timeout) ) ]); // Check for HTTP error status codes if (response && response.status >= 400) { if (this.isRetryable(null, response.status)) { throw new Error(`HTTP ${response.status}`); } } // Success this.circuitBreaker.onSuccess(); this.stats.successfulRequests++; return response; } catch (error) { lastError = error; // Check if retryable if (!this.isRetryable(error) || attempt >= this.config.maxRetries) { this.circuitBreaker.onFailure(); this.stats.failedRequests++; if (attempt >= this.config.maxRetries && error.code !== 'CIRCUIT_OPEN') { lastError.code = 'MAX_RETRIES'; } throw lastError; } // Retry this.stats.retriedRequests++; this.emit('retry', { attempt: attempt + 1, maxRetries: this.config.maxRetries, error: error.message, delay: this.calculateDelay(attempt) }); await this.sleep(this.calculateDelay(attempt)); attempt++; } ``` The affected mechanism is also used for state-changing HTTP methods: ```javascript async post(url, data, options = {}) { return this.executeWithRetry(async () => { const response = await fetch(url, { ...options, method: 'POST', headers: { 'Content-Type': 'application/json', ...options.headers }, body: JSON.stringify(data) }); return response; }); } async put(url, data, options = {}) { return this.executeWithRetry(async () => { const response = await fetch(url, { ...options, method: 'PUT', headers: { 'Content-Type': 'application/json', ...options.heade ...[truncated 3223 chars]- Remediation
View remediation
{ controller.abort(new Error('Request timeout')); }, this.config.timeout); return await requestFn(controller.signal); } finally { clearTimeout(timeoutHandle); } } async get(url, options = {}) { return this.executeWithRetry(async (signal) => { return fetch(url, { ...options, method: 'GET', signal }); }); } ``` For non-idempotent requests, require an explicit option and an idempotency key: ```javascript async post(url, data, options = {}) { if (options.allowRetry && !options.idempotencyKey) { throw new Error('An idempotency key is required when retrying POST requests'); } // Add the idempotency key to the request headers and disable retries // unless allowRetry was explicitly selected. } ``` ]]>
