LFI extension bypass (dropping or satisfying an appended suffix)
An LFI extension bypass defeats a control that appends a fixed suffix (such as '.php') or allows only certain extensions. Modern bypasses that do not rely on legacy truncation include treating the suffix as a query string or fragment (?/#), the path-parameter (;) trick on some servers, or routing through a PHP wrapper that ignores the extension entirely.
How it works
If the app does include($_GET['page'] . '.php'), the appended .php normally forces a fixed file type. On modern runtimes the null-byte and truncation tricks are gone, so attackers make the suffix irrelevant instead of removing it.
When the value is fetched over a URL-aware wrapper, a ? turns the appended text into a query string: php://filter/.../resource=/etc/passwd? means the trailing .php is treated as part of the query and ignored by the underlying read. On remote fetches, ? and # similarly strip the suffix from the effective path.
Other routes: the ;/ path-parameter trick on servers that honour it, and simply choosing a target that legitimately ends in the required extension (reading another .php file for source disclosure via php://filter). The right bypass depends on how the value is consumed.
When it works and when it fails
Works when
- The value is consumed by a URL/stream-aware function so ? or # can delimit the suffix.
- A PHP wrapper (php://filter, data://) is reachable, making the on-disk extension irrelevant.
- The server honours path parameters (;), or the required extension matches a file the attacker wants anyway.
Fails when
- A plain local file open that treats the whole string, including ?/#, as the literal filename.
- allow_url_include/wrappers are disabled and only a literal path is used.
- Input is resolved through an allowlist of keys, so the appended suffix is never attacker-reachable.
Representative payloads
Adapt these to your authorized target; they are shown in canonical form. Payloads are never translated.
php://filter/convert.base64-encode/resource=/etc/passwd?Any OSExtensionA trailing ? makes an appended '.php' part of the query string, so the wrapper reads /etc/passwd and the suffix is ignored.
Note: Combine with php://filter to also bypass PHP execution of the target.
../../../../etc/passwd#Any OSExtensionOn URL-based fetches a # fragment delimiter drops everything after it, including an appended extension.
../../../../etc/passwd;.phpAny OSExtensionOn servers that treat ; as a path-parameter delimiter, the real path ends at ; and the appended extension lands in the parameter.
php://filter/convert.base64-encode/resource=configAny OSPHP wrapperWhen the app appends .php, pointing the filter at a page key reads that PHP file's source as base64 instead of executing it.
Detection
In logs
- Filename parameters ending in ? , # , or ;.php where a clean name is expected.
- php:// , data:// or file:// schemes in a parameter that should be a page name.
- Reads of application source files (config, index) returned as base64 in responses.
In code
- Appending a fixed extension to user input as the only restriction on which file is opened.
- User input flowing into include/require or a URL-aware reader where ?/# can delimit the suffix.
- allow_url_include enabled, or wrappers reachable from a file parameter.
Detection rule: Flag file parameters that contain a scheme (php://, data://, file://) or end with ?, #, or ;.<ext>.
Remediation
- Do not treat an appended extension as a security boundary. Validate the request against an allowlist of keys that map to fixed, known files.
- Disable dangerous wrappers and allow_url_include; if includes must be dynamic, restrict the stream wrappers that are permitted.
- Reject input containing URL schemes, ?, #, ; or path separators when a bare filename is expected.
- Canonicalize the final path and verify the prefix and the exact expected extension on the resolved path, not on the raw input.
Vulnerable (php)
include('/var/www/pages/' . $_GET['page'] . '.php');Fixed
$allowed = ['home', 'about', 'contact'];
$page = (string) ($_GET['page'] ?? '');
if (!in_array($page, $allowed, true)) {
http_response_code(404); exit('Not found');
}
include __DIR__ . '/pages/' . $page . '.php';An allowlist of keys removes the appended-extension gamble entirely.
FAQ
- Why does a trailing ? bypass an appended .php?
- When the value is read through a URL/stream-aware function, the ? begins a query string. The effective resource is everything before the ?, so the appended .php becomes part of the ignored query rather than part of the filename.