mir-backend-php
Skill15 starsChanged 3 months agoApache-2.0View on GitHub
Make It Right (PHP runtime tier). Zend Engine / PHP 8.4–8.5 runtime reliability footguns that are shared across EVERY PHP backend framework (Laravel, Symfony, WordPress, Slim, Lumen) — distinct from the generic backend gates and from any one framework's mechanics. Covers: shared-nothing request lifecycle under PHP-FPM and why static/global state does not persist, concurrency = pm.max_children (not threads), long-running worker runtimes (FrankenPHP, Swoole, RoadRunner, Laravel Octane) and the state-bleed/memory-leak inversion they introduce, max_execution_time not counting blocked I/O, memory_limit, opcache plus the PHP 8.4 opcache.jit default flip, persistent PDO connection state, SIGTERM handling in queue workers, PHP's error/exception model in production, and runtime-level security settings (register_argc_argv, session.use_strict_mode, unserialize, parse_url/SSRF, Composer supply chain). TRIGGER when the backend runtime is PHP and the concern is the engine, the php.ini, or the process model — sits between mir-backend (generic) and the framework module. SKIP for Node/JVM/Go/Rust/.NET/Python/Ruby/BEAM runtimes (each has its own mir-backend-<runtime> tier). SKIP for Laravel library mechanics (Eloquent N+1, $fillable, Queues, Octane container bindings → mir-backend-php-laravel) and for Symfony/Doctrine library mechanics (Unit of Work, Serializer groups, Messenger, MapRequestPayload → mir-backend-php-symfony).
- Reads credentials
In this repository52 other files it gives its agents.
- AGENTS.mdAGENTS.md
- mir-backend-beam-phoenixSkill
- mir-backend-beamSkill
- mir-backend-bun-honoSkill
- mir-backend-bunSkill
- mir-backend-dotnet-aspnetcoreSkill
- mir-backend-dotnetSkill
- mir-backend-go-echoSkill
- mir-backend-go-fiberSkill
- mir-backend-go-ginSkill
- mir-backend-goSkill
- mir-backend-jvm-micronautSkill
- mir-backend-jvm-quarkusSkill
- mir-backend-jvmSkill
- mir-backend-jvm-springSkill
- mir-backend-node-expressSkill
- mir-backend-node-fastifySkill
- mir-backend-node-nestjsSkill
- mir-backend-nodeSkill
- mir-backend-php-laravelSkill
- mir-backend-php-symfonySkill
- mir-backend-python-djangoSkill
- mir-backend-python-fastapiSkill
- mir-backend-python-flaskSkill
- mir-backend-pythonSkill
- mir-backend-ruby-railsSkill
- mir-backend-rubySkill
- mir-backend-rust-actixSkill
- mir-backend-rust-axumSkill
- mir-backend-rustSkill
- mir-backendSkill
- mir-cloud-awsSkill
- mir-cloud-azureSkill
- mir-cloud-cloudflareSkill
- mir-cloud-gcpSkill
- mir-cloudSkill
- mir-database-mongoSkill
- mir-database-postgresSkill
- mir-databaseSkill
- mir-devsecopsSkill
- mir-frontend-angularSkill
- mir-frontend-react-nextSkill
- mir-frontend-react-remixSkill
- mir-frontend-reactSkill
- mir-frontendSkill
- mir-frontend-vanillaSkill
- mir-frontend-vue-nuxtSkill
- mir-frontend-vueSkill
- mir-initSkill
- mir-mobile-androidSkill
- mir-mobile-iosSkill
- mir-mobileSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Every branch gets 2 years of active support then 2 years of security-only fixes (the cycle was extended from 3 years to 4 in March 2024).
- Very specific: line 160
Use the string forms (disable, off, tracing, function), not the legacy 4-digit CRTO numbers.
- Distinctive: line 170
Fix: default to non-persistent.
- Very specific: line 211
Every PHP framework's queue worker (php artisan queue:work, php bin/console messenger:consume) is a long-running CLI process.
- Very specific: line 237
Do not solve this with disable_functions.
- Very specific: line 282
Template: never compile a user-supplied string as a template (Twig\Environment::createTemplate(), Blade render on user input).
- Very specific: line 303
Never ship phpinfo() — not as a health check, not behind an "internal" path.
- Very specific: line 309
Commit composer.lock. Deploy with composer install --no-dev --prefer-dist, never composer update on a production host.
- Very specific: line 310
Run composer audit --locked in CI.
- Very specific: line 313
Consider --no-scripts for first-time installs of untrusted packages.
- Very specific: line 319
Gate 6 (implementation): no static caches expecting cross-request persistence.
- Distinctive: line 326
Here: only what every PHP backend shares because of the Zend Engine and the FPM/worker process model — shared-nothing lifecycle, worker …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/mir-backend-php · Make It Right (PHP runtime)
The middle tier. mir-backend decides what is correct (any language). The framework module (e.g. mir-backend-php-laravel) knows the library's mechanics. This tier owns what's true for all PHP backends because they run on the Zend Engine — the request lifecycle and process model that Laravel, Symfony, WordPress, and Slim all inherit.
Runtime versions, verified 13 August 2026:
| Branch | Status | Latest | Dates |
| 8.5 | current stable | 8.5.9 (30 Jul 2026) | active support to 31 Dec 2027, EOL 31 Dec 2029 |
| 8.4 | active support | 8.4.24 | JIT INI defaults changed in this branch |
| 8.3 | security fixes only | 8.3.33 | |
| 8.2 | security fixes only | 8.2.33 | security support ends Dec 2026 |
| ≤ 8.1 | end of life | — | no fixes at all; treat as a finding |
Every branch gets 2 years of active support then 2 years of security-only fixes (the cycle was extended from 3 years to 4 in March 2024). PHP 8.6 is in development for late 2026.
Process model assumed: PHP-FPM (still the dominant production model). Long-running worker runtimes — FrankenPHP (adopted by the PHP Foundation in May 2025, source now under the php GitHub org), Swoole, RoadRunner, Laravel Octane, Symfony Runtime — are called out explicitly because they invert several of the default rules. Load order: mir-backend → mir-backend-php → <framework module>.
The PHP/Zend footguns AI walks into (framework-agnostic)
1. Shared-nothing per request — static/global state does NOT persist
The Zend Engine tears down every variable, object, and static property at the end of each request. Nothing in PHP process memory survives to the next request under FPM — there is no "warm" in-process store between requests.
- AI commonly writes
static $cache = []inside a class, expecting it to persist across requests like an application-level cache. Under FPM each worker resets statics on every request — the "cache" is always empty at request start and is thrown away at request end. - Fix: persist data externally — opcache for compiled bytecode, APCu for small in-process per-worker caches (single worker only, not shared across workers), Redis/Memcached for truly shared data, DB for durable data. Treat the PHP process as a pure function: input → output.
- Why AI errs: AI is trained on patterns from runtimes (Node, Python async) where module-level singletons genuinely survive across requests. That pattern is wrong in FPM-PHP.
// WRONG — resets to [] every request under FPM
class UserRepo {
private static array $cache = [];
public static function find(int $id): User {
if (!isset(self::$cache[$id])) {
self::$cache[$id] = DB::find($id); // never warm on next request
}
return self::$cache[$id];
}
}
// RIGHT — APCu for a single-worker hot cache, Redis for cross-worker
$user = apcu_fetch("user:$id", $found) ?: tap(DB::find($id), fn($u) => apcu_store("user:$id", $u, 60));2. FPM worker model — concurrency = pm.max_children, not threads
PHP-FPM processes one request per worker process at a time. There are no threads handling concurrent requests within a worker — concurrency is purely the number of live FPM worker processes.
pm.max_childrensets the ceiling. A slow DB query or a hung third-party API call ties up an entire worker for the full duration. With 20 workers and a downstream that takes 10 seconds, you saturate the pool after 20 simultaneous slow requests.- Fix: size
pm.max_childrentofloor(available_RAM / per_worker_peak_RSS). Typical PHP-FPM workers use 20–100 MB each. Measure withps aux --sort=rss. Also usepm = dynamicwith sensiblepm.min_spare_servers/pm.max_spare_serversto avoid cold-start churn. - A single blocking call (sync HTTP, slow query, filesystem wait) eats a whole worker slot. Set socket/HTTP timeouts aggressively; offload slow/durable work to queues. Never let a web worker sit blocked on a third-party service.
pm.max_requestsrecycles a worker after N requests. It bounds leaks in C extensions; it is not a substitute for fixing them.
; php-fpm.conf — example sizing for a 1 GB container, ~50 MB/worker
[www]
pm = dynamic
pm.max_children = 18
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
request_terminate_timeout = 60s ; wall-clock kill; see footgun 43. Long-running worker runtimes (FrankenPHP / Swoole / RoadRunner / Octane) flip the model
Under FrankenPHP worker mode, Swoole/OpenSwoole, RoadRunner, or Laravel Octane the PHP process is persistent — it handles many requests without dying. The shared-nothing guarantee is gone. Three failure classes emerge that do not exist under FPM.
symfony/runtime is not itself one of these: it is a bootstrap abstraction, and the process only persists when the selected runner loops over requests (FrankenPhpWorkerRunner, a RoadRunner or Swoole bridge). The default runner terminates per request like FPM. Check which runner is configured before deciding which set of rules applies.
State bleed. Static properties, container singletons, and class-level state set during request A are still set during request B. A singleton that holds $request, $user, or $tenant bleeds that data across users.
Under coroutine-enabled Swoole/OpenSwoole it is worse than staleness: requests interleave inside one worker. A coroutine yields at every I/O boundary and another request resumes on the same statics, superglobals, and singletons. Request-scoped state is then a race, not just a leftover — request A can read the tenant request B just wrote, mid-request. Anything request-, user-, tenant-, or session-scoped must live in coroutine-local context (Swoole\Coroutine::getContext()) or be passed as an argument. Never a process global.
// WRONG under any worker runtime — the singleton retains request 1's user
class AuthContext {
private static ?User $user = null;
public static function set(User $u): void { self::$user = $u; }
public static function get(): ?User { return self::$user; }
}
// After request 1 sets AuthContext::set($alice), request 2 sees $aliceReset mechanism per stack (framework specifics live in the framework module):
| Runtime | Reset mechanism |
Symfony, when the runner drives the HttpKernel request loop (FrankenPhpWorkerRunner, the maintained RoadRunner/Swoole bridges) | services implementing Symfony\Contracts\Service\ResetInterface are auto-tagged kernel.reset and reset between requests. The kernel and container object instances themselves survive. A hand-rolled worker loop gets none of this — implementing ResetInterface does nothing unless something calls Kernel::reset(). Verify the bridge does, or the previous user/tenant/token stays live. |
| Symfony 8.1+ escape hatch | FRANKENPHP_RESET_KERNEL=1 makes FrankenPhpWorkerRunner clone the application after each request instead of reusing the kernel. |
| Laravel Octane | Octane resets first-party framework state only. Your bindings are your problem — see mir-backend-php-laravel. |
| Anything | a static property, a function-level static $x, or a class-level cache is never reset by any of the above. |
Superglobals are not all reset. FrankenPHP resets $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, $_REQUEST between requests. $_ENV is not reset — writes during request A are visible in request B on the same thread. Never store request-scoped or sensitive data in $_ENV. $_SESSION has been the subject of two separate cross-request leak advisories — see Security below.
Memory leaks. Objects appended to a static list, or an event dispatcher that is never flushed, grow the process heap without bound. GC cannot collect what a static reference holds. Set a request ceiling as a circuit-breaker and monitor per-worker RSS:
| Runtime | Request ceiling |
| FrankenPHP | max_requests <n> in the frankenphp Caddyfile block (marked experimental; default 0 = unlimited) |
| Laravel Octane | --max-requests on octane:start (default 500) |
| PHP-FPM | pm.max_requests |
FrankenPHP sizing rule from its own docs: num_threads × memory_limit < available_memory. Its default is 2× CPU cores for both threads and workers, which is usually wrong for your app — measure.
- Why AI errs: AI generates normal-looking singleton/static code that is safe under FPM but becomes a correctness bug under a worker runtime. Always ask at Gate 0: "Is this running under FrankenPHP worker mode / Octane / Swoole / RoadRunner?" If yes, audit every static and every container binding.
4. max_execution_time does NOT count blocked I/O — memory_limit is per request
Both limits are in php.ini and both kill the request with a Fatal error when exceeded. The trap is what max_execution_time actually measures.
max_execution_time(default 30) counts script execution only. Time spent insidesystem(), stream operations,sleep(), and database queries is not counted on Unix-like systems. A request blocked for 10 minutes on a hung DB query is never killed bymax_execution_time. Windows is the exception — there it measures wall clock.- The wall-clock kill is
request_terminate_timeoutin the FPM pool config. If you only setmax_execution_time, a hung downstream still holds the worker forever. Set both, and set the client/driver timeout too (PDO::ATTR_TIMEOUT, cURLCURLOPT_TIMEOUT,default_socket_timeout). memory_limit(default 128M) is per request. AI-generated code that loads large result sets into arrays ($all = Model::all()) blows this on tables with millions of rows.- Fix: queue long tasks. Use
set_time_limit(0)only in CLI/worker scripts, never in web-facing code. Stream or chunk large data sets (cursor()/chunk()in Laravel,toIterable()in Doctrine) instead of loading the full result into memory.
// WRONG — loads every row into memory at once
$users = User::all(); // Fatal: allowed memory size exhausted
// RIGHT — cursor yields one hydrated model at a time
User::cursor()->each(function (User $user) {
processUser($user);
});5. opcache in production — and the PHP 8.4 JIT default flip
Without opcache, PHP parses and compiles every .php file from disk on every request. A 100-file framework bootstrap runs 100 file reads and 100 compilations per request. That overhead disappears entirely with a warm opcache.
; php.ini — production
opcache.enable=1
opcache.memory_consumption=256 ; MB — size to fit your codebase's compiled output
opcache.max_accelerated_files=20000 ; must exceed the number of .php files in the project
opcache.validate_timestamps=0 ; prod only — leave at the default 1 in dev
opcache.revalidate_freq=0 ; irrelevant when validate_timestamps=0
; JIT — PHP 8.4 changed how it is turned on. Both lines are now required.
opcache.jit=tracing ; 8.4+ default is `disable`; was `tracing` before 8.4
opcache.jit_buffer_size=128M ; 8.4+ default is 64M; was 0 before 8.4- PHP 8.4 flipped the JIT INI defaults. Before 8.4:
opcache.jit=tracing,opcache.jit_buffer_size=0— you enabled JIT by raising the buffer size. From 8.4:opcache.jit=disable,opcache.jit_buffer_size=64M. JIT is disabled by default in both cases, but any config that enabled it by setting onlyopcache.jit_buffer_sizesilently stops enabling it after an 8.4 upgrade. If you want JIT on 8.4/8.5, setopcache.jit=tracingexplicitly. - Use the string forms (
disable,off,tracing,function), not the legacy 4-digit CRTO numbers. opcache.jit_buffer_sizeis part of OPcache's shared memory, allocated once per FPM master (all pools and all workers under that master share it) and separately per CLI invocation. It is not per-pool, so you cannot budget it per pool — run separate FPM masters if two workloads genuinely need different sizes. A CLI-heavy host multiplies it by concurrent CLI processes.- JIT rarely helps a typical request-response web app. It helps CPU-bound loops. Measure before enabling; do not treat it as free throughput.
validate_timestamps=0removes the per-requeststat()on every file. It also means the opcache still holds old bytecode after a deploy until FPM is reloaded (systemctl reload php8.4-fpm) or the container is replaced. Make the reload an explicit deploy step. Deploy by replacing the container, not by editing files in place.
6. Persistent DB connections — pconnect leaks transaction state
PDO::ATTR_PERSISTENT = true reuses a DB connection across requests in the same FPM worker process. The connection is not reset between requests — any uncommitted transaction, SET SESSION variable, temp table, or advisory lock from request A is still live when request B picks up the connection.
- A request that crashes mid-transaction leaves an open transaction. The next request on the same worker inherits it and may read/write inside it unknowingly.
- Fix: default to non-persistent. The connect cost is small compared to the transaction-state risk, which is why most PHP frameworks default to non-persistent. If you must use persistent connections, roll back and reset session state at request start.
// Risky — a transaction from a previous crashed request survives
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_PERSISTENT => true]);
// Safer — default (non-persistent); or explicitly reset on borrow
if ($pdo->inTransaction()) { $pdo->rollBack(); }7. Error and exception model — PHP has both, and both must be handled
PHP has two error systems: exceptions (Throwable, catchable) and engine diagnostics (E_WARNING, E_NOTICE, E_DEPRECATED). PHP 8 promoted most previously-fatal engine errors to Error/Throwable, but warnings and notices are still not exceptions.
- Catch
Throwable, not justException, to captureTypeError,ValueError,ArithmeticError. - Register
set_error_handler()to convertE_WARNING/E_NOTICEinto exceptions or structured log entries. Registerset_exception_handler()andregister_shutdown_function()+error_get_last()so fatals still produce one structured log line. - AI-generated code that suppresses with
@(@file_get_contents(...)) silently swallows failures.@also suppresses the error inside your custom error handler unless you checkerror_reporting(). - PHP 8.4 deprecated implicit nullable parameters (
function f(Foo $x = null)→ write?Foo $x = null). Undererror_reporting = E_ALLthis floods logs after an 8.4 upgrade. Fix the signatures; do not silenceE_DEPRECATEDand lose real deprecations.
; php.ini — production
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php/error.log
error_reporting = E_ALL// WRONG — @ hides the failure; $contents is false and you never know why
$contents = @file_get_contents('/path/to/file');
// RIGHT — check the return value or throw
$contents = file_get_contents('/path/to/file');
if ($contents === false) {
throw new RuntimeException('Failed to read file: /path/to/file');
}8. Queue workers and SIGTERM — graceful shutdown needs pcntl
Every PHP framework's queue worker (php artisan queue:work, php bin/console messenger:consume) is a long-running CLI process. On deploy, your orchestrator sends SIGTERM and then SIGKILL after a grace period.
- Without ext-pcntl loaded, the worker cannot install a signal handler.
SIGTERMterminates it immediately, mid-job. The job is neither completed nor released back to the queue — it sits invisible until its visibility timeout expires, and only then is it retried.pcntlis missing from several slim container images. Check withphp -m | grep pcntl. - Fix: load
ext-pcntlin the worker image, and set the orchestrator's grace period longer than your longest job (terminationGracePeriodSecondsin Kubernetes,stopwaitsecsin Supervisor). The framework's handler finishes the current job and then exits. - Combine with the at-least-once rule from
mir-backend: aSIGKILLmid-job means the job will be redelivered. Handlers must be idempotent regardless. - Restart workers after every deploy. A worker holds old code in memory exactly like an Octane request worker does.
Security
Runtime-level and process-level only. Framework mechanics (mass assignment, policies, serializer groups) live in the framework module.
php.ini settings that ship insecure or that AI leaves at the default
| Setting | Default | Set to | What breaks otherwise |
display_errors | On in the shipped php.ini-development | Off | Stack traces in HTTP responses leak absolute paths, class names, SQL fragments, and env values |
expose_php | On | Off | X-Powered-By: PHP/8.4.x hands an attacker your exact patch level |
register_argc_argv | On in the official php Docker images | Off | Turns a query string into $_SERVER['argv']. This is the precondition for the Symfony/Laravel environment-override advisories below. Nothing in a web app needs it. |
session.use_strict_mode | 0 | 1 | With 0, PHP accepts a session ID the client invented → session fixation |
session.cookie_httponly | 0 | 1 | Session cookie readable from JavaScript |
session.cookie_secure | 0 | 1 | Session cookie sent over plain HTTP |
session.cookie_samesite | "" (empty) | Lax or Strict | Cookie attached to cross-site requests |
allow_url_fopen | On | Off where possible | include/file_get_contents on a user-controlled string reaches remote hosts |
cgi.fix_pathinfo | 1 | 0 (php-cgi only) | Path-info confusion lets /upload.jpg/x.php be executed as PHP |
security.limit_extensions (FPM pool) | .php | keep explicit | Widening this lets FPM execute uploaded files with other extensions |
Do not solve this with disable_functions; it is a mitigation of last resort, not a control. Use it only alongside the settings above.
Current advisories affecting the default path
| Identifier | What | Affected | Fixed |
| CVE-2026-17543 | SQL injection in ext-pgsql pg_insert(), pg_update(), pg_select(), pg_delete() | any app using those helpers against PostgreSQL | PHP 8.2.33 / 8.3.33 / 8.4.24 / 8.5.9 (30 Jul 2026) |
| CVE-2026-24894 | FrankenPHP worker mode does not reset $_SESSION between requests — request B can read request A's session data before session_start() | FrankenPHP < 1.11.2 | 1.11.2 |
| CVE-2026-24895 | FrankenPHP CGI path splitting computes the .php index on a lowercased copy and applies it to the original path; Go's ToLower can change byte length, so SCRIPT_FILENAME misaligns and a non-PHP file executes | FrankenPHP < 1.11.2 | 1.11.2 |
| GHSA-v3ph-cgqh-r8p5 | FrankenPHP worker mode skips session reset when ext-session is a shared module (#ifdef HAVE_PHP_SESSION is false at build time); PS(id) survives, so session_start() reuses the previous request's session ID | FrankenPHP ≤ 1.12.4 | later 1.12.x — check the release notes for your build |
| GHSA-cj57-c655-p798 | Official FrankenPHP Docker images shipped a placeholder index.php running phpinfo(), disclosing DATABASE_URL, APP_SECRET, API keys, ini directives, and paths | FrankenPHP Docker images ≤ 1.12.4 | rebuild derivative images against the patched base — pulling the base alone does not fix already-built layers |
Two structural lessons, not just version bumps: PHP patch releases carry security fixes that never get a CVE (the 8.5.9 changelog named 4 CVEs; the diff carried more), so track the branch, not the CVE feed. And worker-runtime state resets are a security control, not a performance detail — a missed reset is cross-user data disclosure.
Deserialization
unserialize() on anything a client can influence is remote code execution when a gadget chain exists in your dependency tree. It runs __wakeup, __destruct, and __unserialize on attacker-chosen classes.
// WRONG — any client-supplied string
$data = unserialize($_COOKIE['prefs']);
// RIGHT — use JSON for client-facing data
$data = json_decode($request->cookies->get('prefs') ?? '', true, 512, JSON_THROW_ON_ERROR);
// If you truly must unserialize, forbid object instantiation
$data = unserialize($blob, ['allowed_classes' => false]);The same rule covers phar:// — before PHP 8, stream functions on a phar:// path unserialized its metadata. Never pass a user-controlled path to file_exists, is_file, getimagesize, or file_get_contents.
SSRF — parse_url() is not a validator
parse_url() implements no standard. It does not validate. It disagrees with cURL and with browsers on edge cases, and that disagreement is the bypass: your allow-list check reads one host, the HTTP client connects to another.
- PHP 8.5 ships a core
uriextension with two standards-compliant parsers:Uri\Rfc3986\UriandUri\WhatWg\Url. For anything a browser or a user typed, useUri\WhatWg\Url— it handles IDNA/Unicode hosts and percent-encoding the way browsers do, normalizes dot-segments, and exposesgetOrigin()for origin comparison. On 8.4 and below, use a maintained URI library, notparse_url(). - Correct parsing is necessary, not sufficient. You still need: scheme allow-list (
httpsonly), host allow-list or a deny-list of private/link-local ranges resolved from DNS (127.0.0.0/8,10/8,172.16/12,192.168/16,169.254.0.0/16,::1,fc00::/7), re-validation after every redirect, and a short connect timeout. - The metadata endpoint is the payload that matters.
169.254.169.254(AWS/GCP/Azure IMDS) returns credentials to any process that can make an HTTP request. Block the whole link-local range, and require IMDSv2 on AWS. - With cURL: set
CURLOPT_FOLLOWLOCATION => falseand follow redirects yourself so each hop is re-checked, and pinCURLOPT_PROTOCOLS_STR => 'https'so a redirect cannot switch tofile://orgopher://.
Injection
- SQL: use prepared statements with bound parameters. Set
PDO::ATTR_EMULATE_PREPARES => falseso the driver, not PHP's string interpolation, does the binding — emulated prepares re-introduce injection with some charsets. Identifiers cannot be bound. Any dynamic table name, column name, orORDER BYdirection must come from a hard-coded allow-list, never from the request. - Command:
escapeshellarg()is locale-dependent and does not make a shell string safe in general. Preferproc_open()with an array command (PHP 7.4+), which skips the shell entirely. Never interpolate user input intoexec,shell_exec,system,passthru, or backticks. - Header/CRLF:
header()rejects\r\nsince PHP 5.1.2, but mail headers do not go throughheader(). A\r\nin an address field injects aBcc:— see the Laravel CRLF advisory inmir-backend-php-laravel. Strip\rand\nfrom anything that reaches a mail transport. - Template: never compile a user-supplied string as a template (
Twig\Environment::createTemplate(), Bladerenderon user input). That is server-side template injection and it is remote code execution.
Path traversal in file serving and uploads
// WRONG — basename() does not stop a traversal that survives decoding
$path = $baseDir . '/' . basename($_GET['file']);
// RIGHT — resolve, then verify the resolved path is still inside the base
$real = realpath($baseDir . '/' . $userPath);
$base = realpath($baseDir);
if ($real === false || !str_starts_with($real, $base . DIRECTORY_SEPARATOR)) {
throw new RuntimeException('Path outside allowed directory');
}For uploads: always move_uploaded_file() (it verifies the file came from an upload); never trust $_FILES['x']['type'] — it is client-supplied. Sniff with finfo_file() and check against an allow-list. Generate the stored filename yourself; never derive it from the client name or extension. Store outside the document root and serve through a controller. If the upload directory must be inside the web root, deny PHP execution there in the web server config — security.limit_extensions in the FPM pool does not help if the file has a .php extension.
Secret and PII leakage
.envmust never be reachable over HTTP. Deny it in nginx/Apache and verify with a request. If it was ever served, every secret in it is burned.- Never ship
phpinfo()— not as a health check, not behind an "internal" path. It prints the entire environment. - Log the request ID, not the request body.
Log::info($request->all())writes passwords and tokens into your log pipeline in plaintext. - Error responses in production must carry a correlation ID and nothing else.
display_errors=Offplus a framework exception handler that returns a generic body.
Supply chain (Composer)
- Commit
composer.lock. Deploy withcomposer install --no-dev --prefer-dist, nevercomposer updateon a production host. - Run
composer audit --lockedin CI. It reads the lock file only, so it needs no install step. Data comes from the PHP Security Advisories Database. - Composer 2.9 blocks insecure packages during resolution by default (
audit.block-insecure, defaulttrue) onupdate,require,remove, andinstallwithout a lock file. Do not switch it off;--no-auditdoes not disable it in 2.9.0. Composer 2.10 moves these keys under a newpolicyblock. - Enumerate
config.allow-pluginsexplicitly. Never set it totrue— that lets any transitive dependency register a Composer plugin and run code at install time. - Consider
--no-scriptsfor first-time installs of untrusted packages; post-install scripts execute arbitrary PHP. - Packagist tags are mutable enough to matter. In May 2026 an attacker republished 700+ versions of four
laravel-langlocalization packages under historical tags, then dissociated the tags from the malicious commits. Version numbers alone did not identify affected installs. Pin by lock file, and scan install history rather than trusting a version string.
How this slots into the pipeline
- Gate 0/5 (model choice): confirm the PHP branch (8.4/8.5 vs. an EOL one) and the process model (FPM vs. FrankenPHP worker mode / Octane / Swoole / RoadRunner). If a worker runtime: audit static state and container bindings before writing any framework code. Size FPM workers to available memory. Flag slow/durable work as queue-bound, not inline.
- Gate 6 (implementation): no static caches expecting cross-request persistence; no unbounded
all(); bothmax_execution_timeandrequest_terminate_timeoutset; opcache tuned andopcache.jitset explicitly if JIT is wanted on 8.4+;display_errors=Off; explicit error and exception handlers; no@-suppression;ext-pcntlpresent in worker images. - Gate 7 (review): reliability-reviewer checks items 1–8. security-reviewer walks the Security section: php.ini table, the advisory table against the deployed versions,
unserializeon client input, URL validation, identifier allow-lists, upload handling,composer audit --locked.
Edit boundary (what belongs here vs. above/below)
- Generic, all-language rules (idempotency, invariants, gates, observability principles) → up to
mir-backend. - A specific library's mechanics (Eloquent N+1, Doctrine Unit of Work, Laravel Queues, Symfony Serializer groups) → down to the framework module (
mir-backend-php-<framework>). - Here: only what every PHP backend shares because of the Zend Engine and the FPM/worker process model — shared-nothing lifecycle, worker sizing, state bleed and superglobal resets under worker runtimes, resource limits, opcache/JIT, persistent PDO, signal handling, error model, and php.ini/Composer-level security.
- A different runtime (Node, Go, JVM…) → its own
mir-backend-<runtime>tier. Never widen this one.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

