Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 4.42 KB

File metadata and controls

54 lines (39 loc) · 4.42 KB

Attack Surface Analysis for ljharb/qs

Attack Surface: Prototype Pollution

  • Description: The ability to inject properties into the Object.prototype or other built-in prototypes in JavaScript, leading to widespread and unexpected application behavior.

  • qs Contribution: Older versions of qs were directly vulnerable to prototype pollution due to its parsing logic for nested objects and arrays in query strings. It could unintentionally modify Object.prototype when parsing specially crafted query parameters using bracket notation and property names like __proto__, constructor, or prototype.

  • Example:

    • Malicious Query String: ?__proto__[isAdmin]=true
    • qs Parsing (Vulnerable Version): Parsing this with a vulnerable qs version could set Object.prototype.isAdmin = true. Subsequently, all JavaScript objects in the application would inherit isAdmin: true, potentially bypassing authorization checks.
  • Impact:

    • Remote Code Execution (RCE) (in certain scenarios)
    • Cross-Site Scripting (XSS)
    • Denial of Service (DoS)
    • Logic Flaws and Application Instability
    • Authentication and Authorization bypass
  • Risk Severity: Critical to High

  • Mitigation Strategies:

    • Upgrade qs Version: Immediately upgrade to the latest version of qs or a patched version that addresses prototype pollution vulnerabilities.
    • Input Validation and Sanitization: Implement server-side validation and sanitization of query string parameters before they are processed by qs. Specifically, reject or escape potentially dangerous property names like __proto__, constructor, and prototype.
    • Object Creation without Prototype: When working with parsed query parameters, consider using Object.create(null) to create objects without a prototype chain, minimizing the risk of prototype pollution exploits.
    • Content Security Policy (CSP): Implement a strong CSP to help mitigate the impact of potential XSS vulnerabilities that could arise from prototype pollution.
  • Description: Making an application unavailable or significantly slower by overwhelming it with requests that consume excessive server resources.

  • qs Contribution: qs's parsing process can become resource-intensive when dealing with extremely complex query strings. Deeply nested structures, a very large number of parameters, or excessively long parameter names in the query string can lead to high CPU and memory usage during parsing within qs.

  • Example:

    • Malicious Query String: ?a[b[c[d[e[f[g[h[i[j[k[l[m[n[o[p[q[r[s[t[u[v[w[x[y[z]]]]]]]]]]]]]]]]]]]]]]]]]]]]=value&... (repeated many times) - A deeply nested query string designed to maximize parsing complexity.
    • Malicious Query String: ?param1=value1&param2=value2&...&paramN=valueN - A query string with a massive number of parameters, forcing qs to process a huge amount of data.
  • Impact:

    • Application Downtime and Unavailability
    • Severe Performance Degradation and Slow Response Times
    • Server Resource Exhaustion (CPU, Memory)
  • Risk Severity: Medium to High (High if application is resource-constrained or handles high traffic)

  • Mitigation Strategies:

    • Request Limits: Implement strict limits on the complexity and size of incoming requests, including:
      • Maximum allowed query string length.
      • Maximum number of query parameters permitted per request.
      • Maximum depth of nesting allowed in query parameters.
    • Rate Limiting: Employ rate limiting to restrict the number of requests from a single IP address or user within a defined time window.
    • Resource Monitoring and Alerting: Continuously monitor server resource utilization (CPU, memory) and set up alerts to detect unusual spikes that could indicate a DoS attack in progress.
    • Request Timeouts: Configure timeouts for request processing to prevent requests from consuming resources indefinitely, especially during parsing.
    • Web Application Firewall (WAF): Consider using a WAF to filter out requests with excessively complex query strings before they reach the application and qs.