Safeguard
Application Security•

CWE-231 Improper Handling of Extra Values in Input

What does your code do when it gets more values than it expects? CWE-231 explained, with a repeated-parameter example and a fix.

Safeguard Security Team
2 min read

CWE-231, Improper Handling of Extra Values, applies when a product does not handle, or mishandles, receiving more values than it expects.

It affects anything that reads lists of arguments, repeated query parameters, repeated headers or arrays of fields.

How it happens

A function written for one value gets two. Depending on the code, it takes the first, takes the last, joins them, or fails. If two components in the same request path pick differently, a check can be applied to one value while the action uses another.

# Vulnerable: layers disagree about which "amount" counts
amounts = request.args.getlist("amount")   # ["10", "9999"]
validate(amounts[0])      # checks the first
charge(amounts[-1])       # uses the last

MITRE's record lists no observed CVE examples for this entry.

What an attacker gains

MITRE lists integrity: the product ends up in an unexpected state. The consequences depend on what the code then does with the unintended value.

How to find it

MITRE lists no detection methods. For each input, send two or more values where one is expected, and send extra arguments and fields. Compare what each layer, such as proxy, framework and application, sees.

How to fix it

MITRE gives no mitigations. Practical steps:

  1. Decide the maximum count for each input.
  2. Reject requests with more than the allowed number instead of silently choosing one.
  3. Read the value once and pass that same value to both validation and use.
amounts = request.args.getlist("amount")
if len(amounts) != 1:
    abort(400)
amount = amounts[0]
validate(amount)
charge(amount)

Quick check

Why reject instead of using the first value?

Another layer may use the last one. Rejecting removes the disagreement.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.