qs.parse(), qs.stringify()This threat model focuses on the core parsing and stringifying functionality, specifically the handling of nested objects and arrays, option validation, and cycle management in stringification.
Caller Application → qs.parse(input, options) → Parsing Engine → Output Object
│
└→ Options Handling
Caller Application → qs.stringify(obj, options) → Stringifying Engine → Output String
│
└→ Options Handling
└→ Cycle Tracking
Trust Boundaries:
- Input string (parse): May come from untrusted sources (e.g., user input, network requests)
- Input object (stringify): May contain cycles, which can lead to infinite loops during stringification
- Options: Provided by the caller
- Cycle Tracking: Used only during stringification to detect and handle circular references
| Component / API / Interaction | S | T | R | I | D | E |
|---|---|---|---|---|---|---|
Public API Call (parse) |
– | ✓ | – | ✓ | ✓ | ✓ |
Public API Call (stringify) |
– | ✓ | – | ✓ | ✓ | – |
| Options Handling | ✓ | ✓ | – | ✓ | – | ✓ |
| Dependency Interaction | – | – | – | – | ✓ | – |
Key Threats:
- Tampering: Malicious input can, if not prevented, alter parsed output (e.g., prototype pollution via __proto__, modification of builtins/globals)[3][4][8].
- Information Disclosure: Error messages may expose internal details or sensitive data.
- Denial of Service: Large or malformed input can exhaust memory or CPU.
- Elevation of Privilege: Prototype pollution can lead to unintended privilege escalation in the host application[3][4][8].
| Threat Identified | Proposed Mitigation |
|---|---|
| Tampering (malicious input, prototype pollution) | Strict input validation; keep allowPrototypes: false by default; use plainObjects for output; ensure builtins/globals are never modified by parse[4][8]. |
| Information Disclosure (error messages) | Generic error messages without stack traces or internal paths. |
| Denial of Service (memory/CPU exhaustion) | Enforce arrayLimit and parameterLimit with safe defaults; enable throwOnLimitExceeded; limit nesting depth[7]. |
| Elevation of Privilege (prototype pollution) | Keep allowPrototypes: false; validate options against allowlist; use plainObjects to avoid prototype pollution[4][8]. |
allowPrototypes enabled)