site-paths
Stop your site from telling strangers which private routes exist.
If /admin/reports answers "sign in" and a made-up address answers
"not found", anybody can tell that your site has a reports page without
seeing a single report. Asking for a list of names gives the list of
what you have. Scanners do that in the first minutes of an attack, and
what they try next is built on it.
Why hide whether a route exists?
This is the wall for Python: in your server, it answers every path of a private part alike, there or not, for whoever your own code does not let in. It is for ASGI (Starlette, FastAPI), WSGI (Flask) and Django.
No dependencies. Typed. Apache-2.0.
Install
pip install site-paths
Python 3.11 or later.
Quick start
1. Ask your deployment what it gives away. The check is one command for a site written in anything, and needs Node.js where it runs, which is 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 ends with 1. What the check asks and what it takes.
2. If it fails, put a wall before the part, after whatever says who is signed in and before your routes. On FastAPI:
from site_paths.asgi import Wall
app.add_middleware(
Wall,
under="/admin",
allow=lambda scope: scope["session"].get("role") == "staff",
missing="/nothing-here",
)
app.add_middleware(SessionMiddleware, secret_key=...)
allow is your own decision about who is let in. missing is a path
your site does not have: whoever is not let in gets your site's own
answer for it, for every path under /admin, so a route that is there
and one that is not look the same. Staff go on to your routes as before.
FastAPI also lists every route in /openapi.json to whoever asks. Leave
the part's routes out of it, with
APIRouter(prefix="/admin", include_in_schema=False): a wall keeps what
is asked for, and not what the site publishes of itself.
3. Run the check again, and keep it where your tests run. It fails when a later change lets an answer tell again.
The wall
A wall runs before your site looks a route up, and asks your function whether the caller is let in. That order is the point: an answer that is made to look the same after the route was found can still be told apart by how long it took.
FastAPI and Starlette
See Quick start.
-
Add the wall before the middleware that says who is signed in: the session's, or
AuthenticationMiddleware. The middleware that is added last runs first. -
Leave the part's routes out of what FastAPI publishes. FastAPI lists every route in
/openapi.json, and shows them at/docs, to whoever asks. A wall keeps what is asked for, and not what the site says of itself:staff = APIRouter(prefix="/admin", include_in_schema=False)
-
allowis given the connection's scope. A coroutine is awaited, and a caller whose answer does not come in three seconds is kept out. A plain function is called at once and is not cut short: have it read only what the connection carries already, such as the session. -
An application mounted below another keeps its part whether
undernames it from the top of the site or from where the application is mounted.
Flask
from site_paths.wsgi import Wall
def is_staff(environ):
with app.app_context():
session = app.session_interface.open_session(app, app.request_class(environ))
return session is not None and session.get("role") == "staff"
app.wsgi_app = Wall(app.wsgi_app, under="/admin", allow=is_staff, missing="/nothing-here")
The wall stands before the application, and so before Flask has opened
the session: allow is given the request's environment, and opens the
session itself as above. A session that is kept on the server needs the
application's context to open, which is what the with is for.
Django
# walls.py, in your project
from site_paths.django import wall
staff = wall(under="/admin", allow=lambda request: request.user.is_staff)
# settings.py
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"project.walls.staff",
"django.middleware.common.CommonMiddleware",
...,
]
- After the middleware that says who is signed in, and before
CommonMiddlewareandLocaleMiddleware. Those two look at an answer that nothing is there and redirect where the path with a slash, or with a language before it, is a route. Above the wall they would redirect/admin/reportswhen/admin/reports/is a route, and not a name that is no route, which tells the two apart. A wall that finds either above itself does not start, and says why. - Whoever is not let in gets the site's own page for a missing path, as Django makes it.
- Where routes carry a language before them (
i18n_patterns), the part is under each language: keep it with a pattern, such asmatch=r"^/(en|de)/admin(/|$)". - Where Django runs on ASGI, a decision that is not a coroutine is made in a thread.
Options
| Option | |
|---|---|
under |
The start of the part, as a visitor asks for it: the path itself and everything below it |
match |
In place of under: a pattern for the paths to keep, such as r"\.js\.map$" |
allow |
Your decision. Only True lets a caller in: anything else, or an error, keeps the caller out. So does a decision that is awaited and does not come in three seconds |
missing |
What your site answers for a path it does not have. For ASGI and WSGI: a path the site does not have, or an application that answers in its place; left out, a bare 404. For Django: a function that returns the answer; left out, Django's own page for a missing path |
What to know
- A path is read as the most forgiving server would read it, so no
other spelling of it goes round:
/Admin//reports,/%61dmin/reportsand/admin;v=1/reportsare all/admin/reports. - A path that enters the part and leaves it again by dots is kept
too, such as
/admin/../reports: these frameworks find a route by the path as it is written. So is a path of more than 64 segments, wherever it leads. - No cache may keep what a caller who is kept out is answered. The
wall says
cache-control: private, no-storeon it, whatever made the answer. What your staff are answered is yours to mark the same: a cache in between that keeps it gives it to whoever asks next. - A decision that is not awaited is not cut short: on WSGI, and a plain function on ASGI. Give what it asks a time of its own to answer in.
- A websocket in the part is closed before it is accepted, for whoever is not let in.
- A wall does not hide what your site sends every browser. A script that names a route has given it away. The check looks for that.
- It does not stand before anything your platform serves without asking your application, such as static files at a CDN.
- It is no replacement for authorization. It keeps the list of routes from strangers. What a signed-in caller may do is still your code's to decide.
What it was tried on
Python 3.11 to 3.15, on every change. FastAPI on uvicorn, Flask on
gunicorn, and Django on gunicorn and on uvicorn, each asked by the
check as a stranger, a customer and the staff: without the wall the
check fails, with it the check passes. Django with its own
CommonMiddleware and routes that end with a slash; FastAPI with an
application mounted below it, and with nothing of the part in what it
publishes. No cache or CDN was put in front. It reads a path by the same two
lists that the JavaScript package beside it is held to.
License
Apache-2.0: see LICENSE.
Metadata
Release files for site-paths 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| site_paths-0.1.0.tar.gz | 25.0 kB | With provenance | Details for site_paths-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| site_paths-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for site_paths-0.1.0-py3-none-any.whl |
Total release size: 44.4 kB
Release files / site_paths-0.1.0.tar.gz
| Download URL | site_paths-0.1.0.tar.gz |
|---|---|
| Size | 25.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f78e22791cc7bc61c1f117e925b275b6d7da441d496a4d01979440b8fda18fd
|
|
BLAKE2b-256 checksum How to use checksums |
cb7268beee69c36cbfc1cef52b14410d7927b156337790f3b93012bdbf16ed75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logRelease files / site_paths-0.1.0-py3-none-any.whl
| Download URL | site_paths-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85d7af0407624db6e59d3d3ed6d28f608a3bfc367a190bc94cb421b5a1de7942
|
|
BLAKE2b-256 checksum How to use checksums |
00b677f3e0380c4746ef88b7e29c32b53be18fb711a4cc7367a3e4554d784db4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logSecurity for site-paths 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for site_paths-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.