---
title: "CWE-795: Only Filtering Special Elements at a Specified Location"
url: https://radicalnotion.ai/cwe/cwe-795
type: cwe
description: "The product receives data from an upstream component, but only accounts for special elements at a specified location, thereby missing remaining special elements that may exist before sending it to a downstream component."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-795: Only Filtering Special Elements at a Specified Location

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Incomplete
- **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 receives data from an upstream component, but only accounts for special elements at a specified location, thereby missing remaining special elements that may exist before sending it to a downstream component.

A filter might only account for instances of special elements when they occur:

relative to a marker (e.g., "at the beginning/end of string; the second argument"), or

at an absolute position (e.g., "byte number 10").

This may leave special elements in the data that did not match the filter position, but still may be dangerous.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Unexpected State | - |

## Demonstrative examples

### Example 1

The following code takes untrusted input and uses a regular expression to filter a "../" element located at the beginning of the input string. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.

Bad code:

```perl
my $Username = GetUntrustedInput();
$Username =~ s/^\.\.\///;
my $filename = "/home/user/" . $Username;
ReadAndSendFile($filename);
```

Attack code:

```
../../../etc/passwd
```

Result code:

```
../../etc/passwd
```

Result code:

```
/home/user/../../etc/passwd
```

### Example 2

The following code takes untrusted input and uses a substring function to filter a 3-character "../" element located at the 0-index position of the input string. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.

Bad code:

```perl
my $Username = GetUntrustedInput();
if (substr($Username, 0, 3) eq '../') {
    $Username = substr($Username, 3);
}
my $filename = "/home/user/" . $Username;
ReadAndSendFile($filename);
```

Attack code:

```
../../../etc/passwd
```

Result code:

```
../../etc/passwd
```

Result code:

```
/home/user/../../etc/passwd
```

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-791](https://radicalnotion.ai/cwe/cwe-791) | Incomplete Filtering of Special Elements |
| Child | [CWE-796](https://radicalnotion.ai/cwe/cwe-796) | Only Filtering Special Elements Relative to a Marker |
| Child | [CWE-797](https://radicalnotion.ai/cwe/cwe-797) | Only Filtering Special Elements at an Absolute Position |

## Frequently asked questions

### What is CWE-795?

The product receives data from an upstream component, but only accounts for special elements at a specified location, thereby missing remaining special elements that may exist before sending it to a downstream component.

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

Exploiting CWE-795 can lead to: Unexpected State.

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

---

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