Safeguard
Application Security•

CWE-232 Improper Handling of Undefined Values

A value your code does not recognize can crash a client or push it into the wrong state. CWE-232 explained with a safe default-case pattern.

Safeguard Security Team
2 min read

CWE-232, Improper Handling of Undefined Values, applies when a product does not handle, or mishandles, a value that is not defined or not supported for a given parameter, field or argument name.

Clients and servers that exchange typed or enumerated values are the usual place: protocol fields, driver types, status codes, feature flags.

How it happens

The code handles the values it knows and assumes those are the only ones. When a new or unexpected value arrives, nothing in the code says what to do. MITRE's observed example is CVE-2000-1003: a client crashes when the server returns an unknown driver type.

// Vulnerable: no branch for unknown values
Driver d;
switch (type) {
    case "mysql": d = new MySqlDriver(); break;
    case "pg":    d = new PgDriver();    break;
}
d.connect();     // NullPointerException if type is anything else

What an attacker gains

MITRE lists integrity: the product ends up in an unexpected state. In the example, the result was a client crash caused by a response from the server.

How to find it

MITRE lists no detection methods. Send values outside each documented set: an unknown enum, an unsupported type, an out-of-range code. Review switch and lookup statements for missing default branches.

How to fix it

MITRE gives no mitigations. A simple rule covers most cases: every decision on a value needs an explicit answer for values you do not recognize, and that answer should be to refuse safely.

switch (type) {
    case "mysql": d = new MySqlDriver(); break;
    case "pg":    d = new PgDriver();    break;
    default: throw new IllegalArgumentException("Unsupported driver type");
}

Catch that error at the boundary, report it cleanly, and keep the rest of the system running.

Quick check

Why not default to the most common value?

Guessing can move the product into a state the sender did not intend. Refusing is safer.

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.