Resource Exhaustion / Denial of Service
Description
Detects operations that can cause resource exhaustion: unbounded loops on user input, reading entire large files into memory, recursive operations without depth limits, or missing timeouts. These can lead to memory exhaustion or CPU starvation (DoS).
How to fix
Limit file reads, bound loop iterations, and set timeouts for user-controlled operations.
```python
from flask import Flask, request
app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 # 10 MB
MAX_ITERATIONS = 1000
@app.route('/upload', methods=['POST'])
def upload():
content = request.files['file'].read(10 * 1024 * 1024) # Bounded read
return process(content)
@app.route('/process')
def process():
count = min(int(request.args.get('count', 10)), MAX_ITERATIONS)
return [operation(i) for i in range(count)]
```
Learn more: https://shoulder.dev/learn/python/cwe-400/resource-exhaustion
Applies to
Languages
References
Scan for this issue
Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=python-resource-exhaustion .
Real-world examples
Known CVEs in the Resource Exhaustion vulnerability class that this rule helps detect.