Course · Applications · 10 / 69
File inclusion: when a parameter chooses which code or template runs
Local and remote file inclusion in PHP-style apps and modern template loaders, why it is worse than reading a file, how to recognize it in code and responses, and the allow-list fix.
Diagram
A page parameter that loads code
A parameter selects a page or language file.
GET /index.php?page=about
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
A short map of the pieces. Each piece says what fails, who is affected, what you would notice, and what you change.
Inclusion executes
- What fails
- Unlike a download bug, an include runs the file as code or renders it as a template.
- Who is affected
- The whole server and its secrets, not just one file.
- What you would notice
- include, require, render, or loader calls with request data in the path.
- What you change
- Replace with an allow-list map from names to fixed files.
Remote inclusion
- What fails
- Some runtimes can include a URL, which pulls code from another server.
- Who is affected
- Everything the application can reach.
- What you would notice
- allow_url_include enabled in PHP configuration.
- What you change
- Disable remote includes and block outbound traffic the app does not need.
Uploads make it worse
- What fails
- An upload folder plus an include bug lets someone include their own file.
- Who is affected
- All users of the application.
- What you would notice
- User uploads stored inside the application directory.
- What you change
- Store uploads outside the code tree, on a separate domain or bucket, and never include from them.
Recognizing it
Parameters named page, view, lang, template, or module that change which content appears are candidates. In review, search for include and require with variables in PHP, and for template loaders such as render_template or res.render called with a user-supplied name.
$ rg -n "include\s*\(?\s*\$_(GET|POST|REQUEST)|render_template\(request" .
app/index.php:14: include("pages/" . $_GET["page"] . ".php");
-> finding: page selects an included fileConfirming in a lab
In a lab copy, place a harmless marker template in a folder the include should not reach and request it by name. If the marker renders, the include path is controllable. Report it with the parameter and the marker result; do not attempt to execute code.
Hardening the runtime
Beyond the allow-list, set open_basedir to the application folder, disable allow_url_include and allow_url_fopen where unused, run the web server as a low-privilege user, and keep the code directory read-only.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Why is file inclusion often more severe than path traversal?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
- 01Reading a proxy historyA testing proxy shows the request and the response for an application you are allowed to test.
- 02Cross-site scripting: reflected, stored, and DOM-based, and the defenses that stackHow untrusted text becomes script in another user’s browser, how to tell reflected, stored, and DOM-based XSS apart in a review, and why output encoding, a strict CSP, and HttpOnly cookies work together.
- 03Cross-site request forgery: when the browser’s cookie is the only proofHow another site can make a signed-in browser send a state-changing request, how SameSite cookies changed the picture, where CSRF still appears, and how to verify tokens and Origin checks in a review.
- 04Server-side request forgery: fetchers, internal targets, and allow-lists that holdHow features that fetch a URL — webhooks, previews, importers, PDF renderers — can be pointed at internal services, how testers confirm SSRF safely with a canary host, and how to build an allow-list that survives redirects and DNS tricks.
- 05HTTP headers in security testing: which ones the server trusts and which ones protect usersRequest headers that applications wrongly trust (Host, X-Forwarded-For, X-Original-URL, Referer), response headers that protect users (CSP, HSTS, frame-ancestors), and how to audit both with curl and a proxy.