← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Stream Filter Injection via php:// wrapper

Security PHP 5.0+ Advanced
debt(d5/e5/b5/t9)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5), semgrep rules and phpstan taint analysis can flag user input flowing into include/require, but it requires running these specialist tools rather than default linting.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5), quick_fix requires whitelisting allowed values at every include site, plus php.ini configuration changes, plus auditing all path-accepting functions — multi-file remediation.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5), the rule that user input must never reach include/require with proper whitelisting applies across all web-facing PHP code and shapes how dynamic page routing must be designed.

t9 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'catastrophic trap' (t9), misconception explicitly states devs believe php://filter is read-only and harmless, when filter chains (e.g. base64 + iconv) can synthesize executable PHP from arbitrary files — the 'obvious' mental model is completely wrong.

About DEBT scoring →

TL;DR

PHP stream wrappers (php://filter, php://input) combined with user-controlled filenames enable LFI-to-RCE escalation — never allow user input in file paths.

Explanation

PHP's stream wrappers are accessed via URLs: php://filter/convert.base64-encode/resource=index.php reads and base64-encodes a file. When file functions (include, require, file_get_contents) accept user input, attackers can use php://filter to read source files, chain conversion filters (zlib.deflate|convert.base64-encode) to extract data, or use php://input with allow_url_include to execute POST body as PHP. The filter chain technique (CVE-2022-26134 and similar) uses chained filters to create arbitrary PHP code from non-PHP files. Defence: never pass user input to any file function.

Common Misconception

php://filter is read-only and cannot execute code — filter chains can transform arbitrary files into executable PHP content on vulnerable configurations.

Why It Matters

PHP stream filter injection escalates LFI (local file inclusion) into remote code execution — one of the most critical PHP exploitation chains.

Common Mistakes

  • Allowing user-supplied paths in include/require.
  • Not disabling allow_url_include and allow_url_fopen in production.
  • Not blocking php://, file://, data:// in any path-accepting function.

Code Examples

✗ Vulnerable
// LFI — allows php://filter injection:
$page = $_GET['page'];
include $page; // php://filter/convert.base64-encode/resource=config.php
✓ Fixed
// Whitelist approach:
$allowed = ['home', 'about', 'contact'];
$page = $_GET['page'] ?? 'home';
if (!in_array($page, $allowed, true)) {
    $page = 'home';
}
include __DIR__ . '/pages/' . $page . '.php';

// php.ini:
// allow_url_include = Off
// allow_url_fopen = Off

Added 22 Mar 2026
Views 80
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 2 pings T 0 pings W 0 pings T 2 pings F 0 pings S 1 ping S 0 pings M 0 pings T 3 pings W 0 pings T 0 pings F 2 pings S 0 pings S 0 pings M 2 pings T 1 ping W
Brave Search 1
Bing 1 Google 1
ChatGPT 10 Amazonbot 7 Unknown AI 5 Google 5 Perplexity 4 Ahrefs 4 Scrapy 4 PetalBot 4 Brave Search 3 Meta AI 2 Sogou 2 Bing 2 Twitter/X 1 Applebot 1
crawler 49 crawler_json 3 pre-tracking 2
DEV INTEL Tools & Severity
🔴 Critical ⚙ Fix effort: High
⚡ Quick Fix
Whitelist all allowed page/file values. Set allow_url_include=Off and allow_url_fopen=Off in php.ini. Use realpath() + basename restriction. Never pass user input to include/require.
📦 Applies To
PHP 5.0+ web
🔗 Prerequisites
🔍 Detection Hints
include \$|require \$|file_get_contents\(\$
Auto-detectable: ✓ Yes semgrep phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✗ Manual fix Fix: High Context: Function Tests: Update
CWE-98 CWE-94 CWE-22


✓ schema.org compliant