Safeguard
Application Security•

CWE-792 Incomplete Filtering of One or More Instances

Filters that handle one special element but miss the rest are common. Learn how CWE-792 works and how to make filtering cover every occurrence.

Safeguard Security Team
3 min read

CWE-792 is a variant of incomplete filtering. The product does not filter one or more instances of special elements before passing data downstream.

MITRE describes two shapes: only one instance of a special element is filtered when more exist, or not all instances or all elements are filtered when several kinds are present.

How it happens

The most common cause is a function that acts once. In many languages, a simple replace call with a first-match behavior removes only the first hit.

const cleaned = input.replace("'", "");   // string pattern: first match only

Given a'b'c, the result is ab'c. One quote is still there. The fix looks tiny, but missing it is easy because the code seems to work in a quick test with a single quote.

The second shape is a filter that handles quotes and forgets semicolons, or handles one of several characters the downstream parser cares about.

This entry has two children, which split the problem. CWE-793 covers filtering only one instance. CWE-794 covers not filtering all instances of a special element.

What an attacker gains

The record lists integrity and unexpected state. There are no observed CVEs in it. The impact is determined by the downstream interpreter: a surviving element can change a query, command or document structure.

How to find it

  • Read each filter and ask what happens with two or three of the same element in a row, and with different elements mixed together.
  • Add unit tests that repeat the dangerous input several times.
  • Search for replace or strip calls used as security controls.

How to fix it

  1. Use a replace that covers all matches, and keep in mind that removal can reveal a new match.
  2. Better, do not strip. Reject input that contains disallowed elements, or encode it.
  3. Handle all special elements for the destination, not a subset.
  4. Prefer the destination's own safe interface, such as bound parameters, so there is no filter to be incomplete.
const cleaned = input.replaceAll("'", "''");   // for a SQL string context, as a last resort

Even this is a fallback. Bound parameters are the right answer for SQL.

Quick check

Why did the one-quote test pass?

It had a single special element, so a first-match replace removed everything. Tests need repeated and mixed elements.

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.