Fix Unrestricted Resource Consumption in LoopBack
LoopBack's flexibility is a double-edged sword. Default finders without strict schema enforcement or request throttling are an invitation for attackers to dump entire tables or crash the Node.js event loop via memory exhaustion. If you allow raw 'filter' objects from the client, you are one 'limit=999999' query away from an OOM (Out Of Memory) kill. Real security requires hard-capping result sets and throttling the request pipeline.
The Vulnerable Pattern
@get('/orders')
async find(
@param.filter(Order) filter?: Filter,
): Promise {
// VULNERABLE: The attacker controls the 'limit' and 'include' filters.
// Payload: /orders?filter[limit]=1000000&filter[include][0][relation]=customer
return this.orderRepository.find(filter);
}
The Secure Implementation
To mitigate Unrestricted Resource Consumption, you must implement 'Defense in Depth'. First, sanitize the 'filter' object by overwriting the 'limit' property with a server-side maximum. This prevents massive database cursors from bloating the heap. Second, restrict 'include' relations to prevent complex JOIN attacks that spike CPU. Finally, always wrap your API sequence in a rate-limiting middleware (like express-rate-limit or loopback4-ratelimiter) to prevent automated scripts from exhausting the thread pool through high-frequency requests.
const MAX_LIMIT = 50;@get(‘/orders’) async find( @param.filter(Order) filter?: Filter
, ): Promise<Order[]> { // SECURE: Enforce a hard limit regardless of user input const safeFilter: Filter = { …filter, limit: Math.min(filter?.limit ?? MAX_LIMIT, MAX_LIMIT), // Avoid deep recursive includes unless explicitly needed include: filter?.include?.filter(inc => [‘customer’].includes(inc.relation)) }; return this.orderRepository.find(safeFilter); }
// In sequence.ts, integrate ‘loopback4-ratelimiter’ to prevent DoS // this.mountComponent(RateLimiterComponent);
Your LoopBack API
might be exposed to Unrestricted Resource Consumption
74% of LoopBack apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.
Free Tier • No Credit Card • Instant Report
Verified by Ghost Labs Security Team
This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.