Mitigation Strategy: Limit Request Body Size
- Description:
- Determine the maximum acceptable size for request bodies for your application.
- For each
body-parser
middleware instance (bodyParser.json()
,bodyParser.urlencoded()
,bodyParser.raw()
,bodyParser.text()
), configure thelimit
option. - Set the
limit
value to the determined maximum size (e.g., '100kb', '1mb'). - Apply this configuration to all relevant routes or middleware stacks.
- Test to ensure requests exceeding the limit are rejected with a 413 error.
- Threats Mitigated:
- Denial of Service (DoS) - High Severity: Prevents resource exhaustion from excessively large request bodies.
- Impact:
- DoS Mitigation - High Impact: Significantly reduces DoS risk from oversized payloads.
- Currently Implemented: No - Project Specific - Needs Assessment.
- Missing Implementation: Project Wide - Needs Assessment.
Mitigation Strategy: Control Parameter Count and Depth
- Description:
- Analyze expected data structures for URL-encoded and JSON requests to determine reasonable limits for parameter count and nesting depth.
- For
bodyParser.urlencoded()
andbodyParser.json()
, configure theparameterLimit
anddepth
options. - Set
parameterLimit
to restrict the number of parameters. - Set
depth
to limit the nesting level of objects. - Apply these configurations where these parsers are used.
- Test to confirm requests exceeding these limits are handled appropriately (e.g., 400 error).
- Threats Mitigated:
- Denial of Service (DoS) - Medium to High Severity: Prevents CPU exhaustion from parsing overly complex request bodies with many parameters or deep nesting.
- Impact:
- DoS Mitigation - Medium to High Impact: Reduces DoS risk from complex data structures.
- Currently Implemented: No - Project Specific - Needs Assessment.
- Missing Implementation: Project Wide - Needs Assessment.
Mitigation Strategy: Use extended: false
for urlencoded
Parsing when possible
- Description:
- Evaluate if extended
urlencoded
parsing (usingqs
library) is necessary for your application. - If not, configure
bodyParser.urlencoded({ extended: false })
to use the built-inquerystring
library. - If extended parsing is needed, ensure other mitigations (like parameter and depth limits) are robust.
- Test application functionality after switching to
extended: false
.
- Evaluate if extended
- Threats Mitigated:
- Denial of Service (DoS) - Low to Medium Severity: Reduces potential attack surface and performance issues associated with the more complex
qs
library. - Parameter Pollution - Low Severity: Slightly reduces risk related to complex parsing edge cases.
- Denial of Service (DoS) - Low to Medium Severity: Reduces potential attack surface and performance issues associated with the more complex
- Impact:
- DoS Mitigation - Low to Medium Impact: Marginally reduces DoS risk by using a simpler parser.
- Parameter Pollution Mitigation - Low Impact: Slightly reduces parameter pollution risks.
- Currently Implemented: No - Project Specific - Needs Assessment.
- Missing Implementation: Project Wide - Needs Assessment.
Mitigation Strategy: Explicitly Configure body-parser
Settings
- Description:
- Review all
body-parser
middleware instances in the application. - Ensure options like
limit
,parameterLimit
, anddepth
are explicitly set with appropriate values. - Avoid using
body-parser
without any configuration, as defaults may be insecure. - Document chosen configurations and their rationale.
- Review all
- Threats Mitigated:
- Security Misconfiguration - Medium Severity: Prevents unintentionally permissive settings due to reliance on defaults.
- Impact:
- Security Misconfiguration Mitigation - Medium Impact: Reduces risk of misconfiguration by enforcing explicit settings.
- Currently Implemented: No - Project Specific - Needs Assessment.
- Missing Implementation: Project Wide - Needs Assessment.
Mitigation Strategy: Use Strict JSON Parsing (strict: true
)
- Description:
- For
bodyParser.json()
, configure thestrict: true
option. - This enforces stricter JSON parsing according to RFC 7159, rejecting invalid JSON syntax.
- Test application functionality with strict parsing enabled.
- Handle potential parsing errors (e.g., 400 error) gracefully.
- For
- Threats Mitigated:
- Data Integrity - Low Severity: Ensures only valid JSON is processed, improving data integrity.
- Security Misconfiguration - Very Low Severity: Reduces potential for unexpected behavior from lenient parsing.
- Impact:
- Data Integrity Improvement - Low Impact: Slightly improves data integrity by enforcing JSON validity.
- Security Misconfiguration Mitigation - Very Low Impact: Marginally reduces risks from lenient parsing.
- Currently Implemented: No - Project Specific - Needs Assessment.
- Missing Implementation: Project Wide - Needs Assessment.