Skip to main content

SKY-SC001 · Security in code

Route lost an auth guard its security contract requires

HIGH by default. Each contract can set its own severity (LOW, MEDIUM, HIGH or CRITICAL), and the finding uses it.

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/main on a pull request, with [[tool.skylos.security_contracts]] in pyproject.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 toward max_high and max_security; a contract with severity = "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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/admin.py · Python · changed
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
pyproject.toml · TOML
[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

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/admin.py · Python · changed
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

pyproject.toml: same as in the flagged example.

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

  1. Runs with --danger when [[tool.skylos.security_contracts]] entries exist. Each needs framework = "fastapi", a file inside the repository, a handler function name and a non-empty guards list; other entries are ignored.
  2. Runs only for a contract whose file changed. It reads the file at the base (the CI pull-request base, SKYLOS_DIFF_BASE, or HEAD for local changes) and in the working tree.
  3. In both versions it finds the function with that name that has a FastAPI route decorator (.get, .post, .put, .patch, .delete, .head, .options, .websocket on any object), and collects its guards: Depends(x) in the decorator's dependencies=[...] and in parameter defaults. A guard matches by its last name, so auth.require_admin counts as require_admin.
  4. 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.
  5. A gate policy synced from Skylos Cloud can set contracts that pyproject.toml cannot 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.

app/admin.py · Python · the fix, against the flagged file
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"]

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.