Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated.
Without limits on resource allocation, an attacker can consume all available resources, causing denial of service for legitimate users.
この脆弱性の修正方法
3 件の Shoulder 検出ルールに基づく Allocation Without Limits の予防策。
Set size limits on body parser middleware to prevent memory exhaustion
- app.use(express.json()); - app.use(express.urlencoded({ extended: true })); + app.use(express.json({ limit: '100kb' })); + app.use(express.urlencoded({ extended: true, limit: '100kb' }));
Add 'take' limits to all relation includes to prevent unbounded data loading and resource exhaustion
import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); app.get('/api/users/:id', async (req, res) => { const user = await prisma.user.findUnique({ where: { id: req.params.id }, include: { - posts: true, // Could be thousands of posts - comments: true, // Could be tens of thousands + posts: { + take: 20, + orderBy: { createdAt: 'desc' }, + select: { id: true, title: true, createdAt: true }, + }, + comments: { + take: 50, + orderBy: { createdAt: 'desc' }, + }, } }); res.json(user); });
Add rate limiting to authentication and expensive API endpoints
from flask import Flask, request, jsonify - - @app.route('/api/login', methods=['POST']) + from flask_limiter import Limiter + from flask_limiter.util import get_remote_address + + limiter = Limiter(app=app, key_func=get_remote_address) + + @app.route('/api/login', methods=['POST']) + @limiter.limit("5 per minute") def login(): user = authenticate(request.json) return jsonify({'token': generate_token(user)})
コードの脆弱性を見つける
Shoulderを使用してコードのAllocation of Resources Without Limits or Throttlingパターンをスキャンしましょう。 3 ルール.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=770 # Or scan entire project npx @shoulderdev/cli trust .
検出ルール (3)
コードレビューで注目すべき点
これらのパターンはAllocation of Resources Without Limits or Throttlingの潜在的な脆弱性を示しています。コードレビューとセキュリティ監査中に探してください。
コードベースをスキャン: Allocation of Resources Without Limits or Throttling
Shoulder CLI はコードベース全体から脆弱なパターンを見つけます。