Search by

webodik / site-paths

webik76

Stop your site from telling attackers which private routes and records exist: a wall for Laravel and PSR-15. No dependencies.

Package info

github.com/webodik/site-paths-php

pkg:composer/webodik/site-paths

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.5 2026-11-29 23:23 UTC

This package is auto-updated.

Last update: 2026-11-29 23:55:54 UTC


README

Stop your site from telling attackers which private routes and records exist.

site-paths is Toller's open-source toolkit for the first step of an attack: finding out what a site has. This package is its wall for PHP: middleware for Laravel, and for PSR-15 (Slim, Mezzio). No dependencies. Apache-2.0.

Why

Attacks are now run by AI-driven frameworks. In November 2026 Google's Threat Intelligence Group reported threat actors using such frameworks "to fully automate vulnerability discovery and exploitation without a human in the loop for the first time". One campaign ran "systematic reconnaissance and vulnerability scanning against a wide range of organizations in Asia".

Every attack starts with reconnaissance, and most sites answer it for free. If /admin/reports answers "sign in" and a made-up path answers "not found", anyone can tell that the reports page exists without seeing a single report. Ask for a list of likely names and you get back the list of what is there.

The fix is to answer both the same way. Then the scan learns nothing it can build on. More on why.

What our lab measured

We run AI-driven attack frameworks against test sites in a closed lab and count what they get.

What the frameworks tried Unprotected Protected
Find which of 8 private staff routes exist. 7 runs each way, 2 frameworks, 2 models Right about all 8, in every run Behind the wall: not one route could be told from a made-up name, in any run. The frameworks had the wall's source code
Read other customers' orders by changing the number in the URL 142 and 102 records read, in the 2 runs counted Behind a wall for single records: 0 records, in 20 runs of 20

These numbers are from one test application with flaws we put there, a handful of runs, and two frameworks. The application ran the JavaScript wall. The walls for the other languages read paths by the same test cases and pass the same check from outside. The numbers show what the wall closes. They are not a share of attacks stopped. How we tested.

What you get

What it does What it needs
The wall Middleware that runs before your router. Callers you don't let in get the same "not found" for every path of a private part, whether the route exists or not Laravel, or a PSR-15 framework such as Slim or Mezzio
The check One command that asks a deployment from outside and fails if any answer gives a private route away. It ships in the JavaScript package and works on a site in any language The deployment's address, and Node.js where the check runs
Alerts Tell you who came probing The JavaScript package's hand-off. This package has none

Install

composer require webodik/site-paths

PHP 8.2 or later.

Quick start

1. Ask your deployment what it gives away. The check needs Node.js where you run it, not on your server. Name the private part and one route in it that exists, at the address your visitors use.

npx -p site-paths site-paths-check --url https://staging.shop.example --under /admin --has /admin/reports

It asks as a stranger for that route and for made-up names beside it. If anything tells them apart, it says what and exits with 1.

2. If it fails, add a wall. On Laravel (for Slim and Mezzio, see PSR-15):

// app/Http/Middleware/StaffWall.php
namespace App\Http\Middleware;

use Illuminate\Http\Request;
use SitePaths\Laravel\Wall;

final class StaffWall extends Wall
{
    public function __construct()
    {
        parent::__construct(
            under: '/admin',
            allow: fn (Request $request) => $request->user()?->is_staff === true,
        );
    }
}
// bootstrap/app.php
use App\Http\Middleware\StaffWall;

->withMiddleware(function (Middleware $middleware): void {
    $middleware->append(StaffWall::class);
})

allow is your decision about who is let in. Everyone else now gets Laravel's own 404 page for every path under /admin, and their request never reaches your routes. Staff reach your routes as before.

3. Run the check again, as staff too, and keep it in CI. It fails if a later change starts leaking again. Asked only as a stranger, it also passes when a mistake in allow keeps everyone out, staff included. So give it what a staff member's browser sends:

WALL_STAFF="cookie: laravel_session=..." npx -p site-paths@0.1.12 site-paths-check --url https://staging.shop.example --under /admin --has /admin/reports

The version is pinned so the session goes to a version you chose, not the newest that day. Make the session for the check alone, on a preview deployment and not your live site, and let it expire soon. The output names the routes you asked about, so don't run it where logs are public.

The wall

The wall runs before your framework looks a route up. That order is the point: after the lookup, the framework has already answered by itself, differently for a route that exists and a name that doesn't. A wall that runs after a route was found throws and says why.

Laravel

Add the wall with $middleware->append(), as in Quick start. That makes it global middleware, which Laravel runs before it looks a route up. Middleware on a route or a group, web included, runs after the route was found. By then Laravel has answered by itself: 404 for a path with no route (a route's own middleware would have asked to sign in), 405 with the methods a route takes, and 200 to OPTIONS with the same list.

  • $request->user() and $request->session() work in allow as in a controller. Laravel sets both up only when it reaches a route, so for a request in its part the wall does it first. It reads the session and never writes it: a caller who is kept out leaves no session and gets no cookie. Requests outside the part are not touched, so routes without a session stay without one.

  • "Remember me" alone doesn't let staff in. A caller Laravel only remembers, with no session left, is kept out until a page outside the part has signed them in again: signing in writes a session, and the wall doesn't. To let staff come straight back, open the session for every request yourself, before the wall. The wall then leaves the session to you:

    // bootstrap/app.php
    use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
    use Illuminate\Cookie\Middleware\EncryptCookies;
    use Illuminate\Session\Middleware\StartSession;
    
    $session = [EncryptCookies::class, AddQueuedCookiesToResponse::class, StartSession::class];
    $middleware->append($session);
    $middleware->web(remove: $session);
    $middleware->append(StaffWall::class);

    The cost: every request then creates and saves a session and gets a cookie, requests from machines and scans too. It does not work with blocking sessions ('block' => true).

  • Put the sign-in page outside the part, or have allow let everybody in to it. Nobody can sign in on a page they are kept from.

  • Laravel finds a route by more than one spelling. /admin/users/, /admin/%75sers and /index.php/admin/users all reach the route at /admin/users, and /admin/%2e%2e/users reaches a route with a parameter. The wall keeps each: it reads the path as it was sent and as Laravel reads it, without the script's name.

  • A fallback route (Route::fallback) answers paths with no route outside the part. The wall answers with Laravel's own 404 page. To make the two the same, return your fallback's answer from missing.

  • With APP_DEBUG on, Laravel's error page says where the error was raised, which tells the wall's answer from the router's. That is for your own machine: check a deployment as it is deployed.

  • A wall keeps what is asked for, not what your site publishes. A package that writes your routes into every page, as Ziggy's @routes does, gives the part's routes to anyone who reads the page. Leave them out: Ziggy takes except in config/ziggy.php.

PSR-15: Slim and Mezzio

use Psr\Http\Message\ServerRequestInterface;
use SitePaths\Psr15\Wall;

$app->addRoutingMiddleware();
$app->add(new Wall(
    $app->getResponseFactory(),
    under: '/admin',
    allow: fn (ServerRequestInterface $request) => $request->getAttribute('user')?->isStaff() === true,
));
$app->add($sessions);
$errors = $app->addErrorMiddleware(false, true, true);

In Slim, the middleware added last runs first. Add the wall after the routing middleware, so it runs before a route is looked up, and before the middleware that says who is signed in, so it runs after that. Slim answers 405 by itself where a route takes another method, and the wall comes before that. A wall added before the routing middleware, or to a group of routes, runs after a route was found, and throws.

Callers who are kept out get a plain 404. To answer with Slim's own page for a missing path, pass it as missing:

use Slim\Exception\HttpNotFoundException;

missing: function (ServerRequestInterface $request) use (&$errors) {
    return $errors->handleException($request, new HttpNotFoundException($request));
},

Name the part as a visitor requests it, including any prefix the application is mounted under.

Options

Both walls take the same named arguments. The PSR-15 wall takes a ResponseFactoryInterface before them, which makes its plain 404.

Option
under The start of the private part, as a visitor requests it: that path and everything below it, however a request spells it. / is the whole site
match Instead of under: a pattern for the paths to keep, as preg_match takes one, such as '~^/(en|de)/admin(/|$)~' for a part under each language. Matched case-insensitively, because paths are compared in lower case. A path that preg_match fails on is kept
allow Your decision, given the request. Only true lets a caller in. Anything else, or any error, keeps the caller out, even a mistake such as a class you did not import. It is never cut short: give what it asks a time limit of its own
missing What callers who are kept out get: given the request, it returns a response. Optional: without it, or if it fails or returns no response, they get Laravel's own 404 page, or on PSR-15 a plain 404. It is not the next handler: a request that is kept out is never passed on to your site
undecided Only with match: what to answer when allow threw, such as a "try again" page with 503. Given the request, it returns a response. Optional: without it, or if it fails or returns no response, such callers are kept out like anyone else. With under the wall refuses to be created, because there the answer would reveal that the part is private. See single records

Errors in allow, missing and undecided are reported, so a bug there doesn't lock your staff out unseen: on Laravel as Laravel reports any exception, on PSR-15 to PHP's error log.

A wall refuses to be created with no part or two, with a start or pattern that is empty, with a pattern preg_match does not take, or with no allow. A wall that keeps nothing, or everything because of an unset variable, should fail loudly at startup.

Good to know

  • Paths are normalized as the most forgiving server would read them. Escapes are decoded, a backslash or a doubled slash is one slash, what follows a semicolon in a segment is dropped, and A to Z become lower case. SitePaths\Paths::plain() returns a path as it is read.

  • Paths that leave the part with dots are kept too, such as /admin/../users, because a server that does not resolve dots finds a route by it. A path is read segment by segment and kept if it is in the part at any point, not only where it ends. Every wall also keeps a path deeper than 64 segments.

  • The walls for every language read paths the same way. Two shared lists hold them to it: how a path reads however it is spelled, and which paths a wall keeps (tests/vectors, copies of the lists beside the other walls).

  • Kept-out answers are never cached. The wall sets Cache-Control: private, no-store on them, whether the answer is its own, your missing or your undecided (Laravel writes it as no-store, private). Mark your staff's answers private or no-store too: a cache in front of the site would serve them to the next caller without asking the wall.

  • A wall hides which routes exist, not that a part is private. If your site's own 404 has different cache headers than the wall's answer, a caller can tell the two apart. The check warns about this and does not fail. To close it, give your 404 page the same header. On Laravel:

    // bootstrap/app.php
    use Symfony\Component\HttpFoundation\Response;
    
    ->withExceptions(function (Exceptions $exceptions): void {
        $exceptions->respond(function (Response $response) {
            if ($response->getStatusCode() === 404) {
                $response->headers->set('Cache-Control', 'private, no-store');
            }
    
            return $response;
        });
    })
  • Not covered: what your web server answers without PHP. nginx or Apache serves the files and folders in your public folder before PHP is asked, so the wall never sees those requests. Keep private files out of it, and don't have a folder there with the name of a private part. The check asks the deployment as it is, web server included.

  • It is not authorization. The wall runs your decision and makes none itself. What a signed-in user may do is still your code's job.

Protect single records

/orders/17 should answer its owner. If it answers anyone signed in, every order can be read by counting. If it answers "forbidden" for someone else's order and "not found" for a free number, nobody reads an order but everybody learns which numbers exist.

Put a wall before single records: an order, an invoice, a file. It runs your own ownership rule before the record's route, and answers everyone else exactly as for a record that doesn't exist.

// app/Http/Middleware/OrdersWall.php: single orders, and not the list at /orders
use Illuminate\Http\Request;
use SitePaths\Laravel\Wall;

final class OrdersWall extends Wall
{
    public function __construct()
    {
        parent::__construct(
            match: '~^/orders/[^/]+$~',
            allow: static fn (Request $request): bool =>
                preg_match('~^orders/(\d{1,18})$~D', $request->path(), $order) === 1
                && mayReadOrder($request->user(), $order[1]),
        );
    }
}

mayReadOrder is your application's rule, asked in one place before every route of an order. The wall decides nothing itself: a wrong rule is wrong here too. On Slim and Mezzio the rule reads the path from $request->getUri()->getPath().

  • Use a pattern for single records. under: '/orders' would also keep everyone out of the list at /orders.

  • The rule sees every spelling and everything below a record: /orders/17/, /index.php/orders/17, /orders/17/items. Laravel finds the order by the first two. Read the path as your routes do, with $request->path(), and say yes only to an order's own address, as the inner pattern above does. Anything else is then kept from everybody, the owner too, so if your site has routes below a record, have the rule read those as well. The \d{1,18} limit avoids numbers a database would reject with an error, on every request.

  • Say no when there is no record and when nobody is signed in. A rule that compares a missing record's owner with a missing user compares null with null and says yes. The check finds that: a stranger is then answered by your route at a free number, and by the wall at a real order.

  • Ask your database one question: does this caller have a record with this number? SELECT EXISTS (SELECT 1 FROM orders WHERE customer_id = $1 AND id = $2), over an index on both columns. The rule runs on every request for a record, let in or not. Asking whose the record is takes a different path for someone else's record than for a free number. We measured that difference at 3 millionths of a second in PostgreSQL; asked the first way, nothing showed (measurement).

  • Decide what happens when the rule fails or is slow. By default a rule that throws keeps the caller out, so while your database is down an owner is told their own record doesn't exist. Give undecided to answer "try again" instead:

    // On Laravel. On PSR-15, return your framework's own response with the same.
    undecided: static fn (): Response => new Response('Try again in a moment', 503),

    This is safe only if the rule fails the same way for a record that exists and one that doesn't, as the one-question rule above does. A rule that fails for some records and not others reveals which. If the wall sits inside a part that another wall keeps, have the part's wall run first, so a stranger is kept out before this rule is asked. The wall never cuts a slow rule short: the request waits for it, so give your database query a time limit of its own.

  • Signed-out callers get "not found", not "sign in". A sign-in redirect at an order's address says the order exists.

  • A number in a request body is not in the path. The wall reads paths. Run the same rule where you read the body.

  • Lists are your code's job. What /orders shows to whom is not the wall's decision.

The check

WALL_STAFF="cookie: laravel_session=..." npx -p site-paths@0.1.12 site-paths-check --url https://staging.shop.example --under /admin --has /admin/reports

It asks for each route you name and for made-up names beside it, as a stranger and as each caller you give it, and exits with 1 if anything tells a real route from a made-up one. It can also check:

  • single records: you name a number that no record has, and tell it what the real record says;
  • sign-in and sign-up forms, for answers that reveal who has an account, or a staff password accepted where everybody signs in;
  • routes that take typed input, for text answered with an error.

The check: every option, what fails, and what it cannot see. Public routes: what they give away, and how to stop it: how to fix each of these, a field a form does not declare, and what a public route's database connection may read.

Performance

A wall reads the path of every request. For a request outside its part that is all it does. Measured on PHP 8.5 on an Apple M4 Max, with a site behind it that does nothing, so the time is the wall's own:

A request PSR-15 Laravel
outside the part 1.1 µs 0.9 µs
in the part, from staff, who are let in 1.1 µs 65 µs
in the part, from a caller who is kept out 2.8 µs 138 µs
a path of 8 KB of escapes 13 µs
a path of 64 long segments 12 µs

The last two are the most expensive inputs. Paths are read no deeper than 64 segments, so a longer one costs no more. On Laravel, the time for a request in the part is mostly Laravel's own: for staff the wall reads the session that Laravel then reads again, and a caller who is kept out gets the page Laravel makes for a missing path.

Measure it yourself in a clone of this repository:

composer install && composer install -d sites/laravel
php bench/run.php

Every commit is benchmarked against the last release, on the same machine in the same run. A slower one fails, so it is never tagged (bench/compare.js).

Tested with

  • PHP 8.2 to 8.6, for the package by itself.
  • The wall before Laravel 12 and 13 on PHP 8.2 to 8.6, and before Slim 4 on PHP 8.2 to 8.5, where Slim installs. Each runs behind PHP's own web server and is asked by the check as a stranger, a customer and staff: the check fails without the wall and passes with it. On Laravel, staff sign in with Laravel's own sign-in, to its own session.
  • Laravel Octane's worker, which stays up from one request to the next: staff and a stranger were answered in turn 200 times, each as they should be. That was Octane's own worker with the stand-in for a server that Octane ships, not one of Octane's servers.
  • Not tested: behind nginx, Apache or a CDN, and before Symfony or Mezzio.

Run the tests yourself. The first three lines fetch nothing but the packages Composer names. The last has the check ask each site as well, which needs Node.js:

composer install && composer test                  # the reading, and the wall for PSR-15
composer install -d sites/slim && composer install -d sites/laravel
vendor/bin/phpunit -c sites                        # each small site behind PHP's own server
SITE_PATHS_CHECK="npx --yes --package site-paths@0.1.12 site-paths-check" vendor/bin/phpunit -c sites

Other languages

The walls for JavaScript, Python, Ruby and Rust, and the check, are in toller-web. The wall for Go is site-paths-go.

Help us test it

We would be glad of help from security experts and developers. Try to get past the wall, run the check against a staging deployment, and tell us what you find, above all where we are wrong: issues. If you find a way past a wall, please report it privately first.

Changes

See CHANGELOG.md.

License

Apache-2.0. See LICENSE.