---
title: "CWE-181: Incorrect Behavior Order: Validate Before Filter"
url: https://radicalnotion.ai/cwe/cwe-181
type: cwe
description: "The product validates data before it has been filtered, which prevents the product from detecting data that becomes invalid after the filtering step."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-181: Incorrect Behavior Order: Validate Before Filter

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 0
- **Of those, in CISA KEV:** 0
- **New in 2026:** 0
- **CWE catalog version:** 4.21

## Description

The product validates data before it has been filtered, which prevents the product from detecting data that becomes invalid after the filtering step.

## Alternate terms

- Validate-before-cleanse

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Access Control | Bypass Protection Mechanism | This prevents the product from detecting data that becomes invalid after the filtering step. An attacker can bypass the validation and launch attacks that expose weaknesses that would otherwise be prevented, such as injection. |

## Potential mitigations

### Implementation, Architecture and Design

Inputs should be decoded and canonicalized to the application's current internal representation before being filtered.

## Demonstrative examples

### Example 1

This script creates a subdirectory within a user directory and sets the user as the owner.

Bad code:

```php
function createDir($userName,$dirName){
    $userDir = '/users/'. $userName;
    if(strpos($dirName,'..') !== false){
        echo 'Directory name contains invalid sequence';
        return;
    }
    //filter out '~' because other scripts identify user directories by this prefix
    $dirName = str_replace('~','',$dirName);
    $newDir = $userDir . $dirName;
    mkdir($newDir, 0700);
    chown($newDir,$userName);
}
```

While the script attempts to screen for '..' sequences, an attacker can submit a directory path including ".~.", which will then become ".." after the filtering step. This allows a Path Traversal (CWE-21) attack to occur.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2002-0934 | Directory traversal vulnerability allows remote attackers to read or modify arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a ".." sequence. |
| CVE-2003-0282 | Directory traversal vulnerability allows attackers to overwrite arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a ".." sequence. |

## Related attack patterns (CAPEC)

- [CAPEC-120](https://radicalnotion.ai/capec/capec-120): Double Encoding
- [CAPEC-267](https://radicalnotion.ai/capec/capec-267): Leverage Alternate Encoding
- [CAPEC-3](https://radicalnotion.ai/capec/capec-3): Using Leading 'Ghost' Character Sequences to Bypass Input Filters
- [CAPEC-43](https://radicalnotion.ai/capec/capec-43): Exploiting Multiple Input Interpretation Layers
- [CAPEC-78](https://radicalnotion.ai/capec/capec-78): Using Escaped Slashes in Alternate Encoding
- [CAPEC-79](https://radicalnotion.ai/capec/capec-79): Using Slashes in Alternate Encoding
- [CAPEC-80](https://radicalnotion.ai/capec/capec-80): Using UTF-8 Encoding to Bypass Validation Logic

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-179](https://radicalnotion.ai/cwe/cwe-179) | Incorrect Behavior Order: Early Validation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Validate-Before-Filter | - | - |
| OWASP Top Ten 2004 | Unvalidated Input | A1 | CWE More Specific |

## Frequently asked questions

### What is CWE-181?

The product validates data before it has been filtered, which prevents the product from detecting data that becomes invalid after the filtering step.

### Is CWE-181 part of the OWASP Top 10?

CWE-181 maps to OWASP Top Ten 2004: Unvalidated Input (A1) in the OWASP security taxonomy.

### How do you prevent CWE-181?

Inputs should be decoded and canonicalized to the application's current internal representation before being filtered.

### What are the consequences of CWE-181?

Exploiting CWE-181 can lead to: Bypass Protection Mechanism.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/181.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-181). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
