Safeguard
Application Security•

CWE-351 Insufficient Type Distinction: Confusing Two Things

CWE-351 happens when code cannot tell different kinds of elements apart, such as user clicks and scripted ones. Learn the pattern and the review habits that catch it.

Safeguard Security Team
3 min read

CWE-351, Insufficient Type Distinction, means the product does not properly distinguish between different types of elements, and that leads to insecure behavior. Two things that should be treated differently get treated the same.

It affects anything that handles mixed inputs: user interfaces, parsers, access control lists, message handlers. The weakness is language neutral.

How it happens

Code often collapses categories to keep things simple. An event is an event. An entry is an entry. Two objects are equal if their first fields match. The shortcut holds until someone builds an input that sits in the gap.

MITRE gives two real examples. In CVE-2005-2260, a browser user interface did not distinguish between user initiated and synthetic events. A page could fake a click and the browser acted as if a person had done it. In CVE-2005-2801, a product did not compare all required data in two separate elements, decided they were the same, and lost access control entries as a result.

What an attacker gains

The record lists the consequence only as "Other." In practice it follows what the confused element controls. If a fake event can trigger a privileged action, the attacker borrows the user's authority. If two different entries merge, protections attached to one can disappear.

How to find it

The record names no detection methods, so use review and testing.

  • List every place where code branches on the kind of an input, and check the branch cannot be satisfied by a forged one.
  • Look at equality and matching functions. Do they compare every field that matters, or only some?
  • Test with inputs that are almost the same as a trusted element but differ in one attribute.

How to fix it

MITRE lists no mitigations for this entry. Sound practice follows from the definition.

  1. Carry the type with the data. Use explicit tags or distinct classes rather than inferring kind from content.
  2. Compare all security relevant attributes when deciding two elements are the same.
  3. Never let input from an untrusted source claim to be a trusted type. Set the trusted flag on your side of the boundary.

Quick check

What went wrong in the browser case, CVE-2005-2260?

The interface did not tell real user actions apart from synthetic events, so scripted activity could be treated as if a person had done it.

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.