SKY-SC001 · Security in code
Route lost an auth guard its security contract requires
A security contract is a promise you write down in pyproject.toml: this FastAPI route must always depend on these guard functions, such as require_admin. SKY-SC001 reports a change that removes one of those guards from the route, or deletes the guarded route.
- Languages
- Python (FastAPI)
- Turned on by
skylos . --danger --diff origin/mainon a pull request, with[[tool.skylos.security_contracts]]inpyproject.toml- Quality gate
- counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). Reported under security (
danger) and counted towardmax_highandmax_security; a contract withseverity = "CRITICAL"fails the gate on its own. It compares the working tree with the base, so it only reports while the guarded file has changes. - Finding type
- review
- Catalog name
- Smart contract security issue
Why it matters
Auth checks are often removed by accident: during a refactor, when a route is copied, or by a coding agent "fixing" a failing test. The diff looks small and the endpoint keeps working, now for anyone. A contract makes that removal fail review instead of reaching production.
What Skylos flags
from fastapi import APIRouter, Depends from app.auth import require_admin router = APIRouter(prefix="/admin") @router.post("/orders/{order_id}/refund")Removed: def refund_order(order_id: int, user=Depends(require_admin)):Added: def refund_order(order_id: int): return {"refunded": order_id}1 committed file the change leaves alone
[project]name = "shop"version = "1.0.0" [[tool.skylos.security_contracts]]id = "admin-refunds"framework = "fastapi"file = "app/admin.py"handler = "refund_order"guards = ["require_admin"]What Skylos leaves alone
from fastapi import APIRouter, Depends from app.auth import require_admin router = APIRouter(prefix="/admin") Removed: @router.post("/orders/{order_id}/refund")Removed: def refund_order(order_id: int, user=Depends(require_admin)):Added: @router.post(Added: "/orders/{order_id}/refund", dependencies=[Depends(require_admin)]Added: )Added: def refund_order(order_id: int): return {"refunded": order_id}1 committed file the change leaves alone
Why Skylos leaves it alone
The user parameter is gone, as in the flagged change, but the guard moved into the decorator's dependencies list. The route still depends on require_admin, so the contract holds.
How Skylos decides
- Runs with
--dangerwhen[[tool.skylos.security_contracts]]entries exist. Each needsframework = "fastapi", afileinside the repository, ahandlerfunction name and a non-emptyguardslist; other entries are ignored. - Runs only for a contract whose file changed. It reads the file at the base (the CI pull-request base,
SKYLOS_DIFF_BASE, orHEADfor local changes) and in the working tree. - In both versions it finds the function with that name that has a FastAPI route decorator (
.get,.post,.put,.patch,.delete,.head,.options,.websocketon any object), and collects its guards:Depends(x)in the decorator'sdependencies=[...]and in parameter defaults. A guard matches by its last name, soauth.require_admincounts asrequire_admin. - Reports each contracted guard the base version had and the new version lacks, on the route's line. If the guarded route was deleted, it reports the old line. A guard the base never had is not reported.
- A gate policy synced from Skylos Cloud can set contracts that
pyproject.tomlcannot remove or ignore.
How to fix it
Put the guard back, either as a Depends parameter or in the route's dependencies list. If the route really should change owner, change the contract in its own reviewed pull request.
from fastapi import APIRouter, Depends from app.auth import require_admin router = APIRouter(prefix="/admin") @router.post("/orders/{order_id}/refund")Removed: def refund_order(order_id: int):Added: def refund_order(order_id: int, user=Depends(require_admin)): return {"refunded": order_id}When it can be wrong
- Only FastAPI is supported, and only guards written as
Depends(...). A guard applied by the router (APIRouter(dependencies=[...])), by middleware or inside the function body is not seen, so a contract on such a route never reports. - Renaming the handler function looks like deleting the route.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
The rule reads no inline marker:
# skylos: ignore[SKY-SC001]on the reported line does not hide the finding. Retire the contract instead, in a reviewed change.[tool.skylos] ignore = ["SKY-SC001"]turns the check off, unless a Skylos Cloud policy sets the contracts. Removing the contract entry is the cleaner way to retire one.TOML [tool.skylos]ignore = ["SKY-SC001"]