Skip to main content

SKY-A105 · AI-code defects

Contract route guard missing

High

An AI contract (.skylos/ai-contract.yml) is a file where a team writes down rules for code agents. Its security.routes section names the folders that hold web routes and the decorators that guard them, such as login_required. SKY-A105 reports a route in those folders that has none of the named guards.

Languages
Python (Flask, FastAPI and other decorator-routed frameworks)
Turned on by
skylos verify . or skylos verify --diff with a contract in .skylos/ai-contract.yml
Quality gate
not checked (full and diff scans). No skylos . scan reports it. skylos verify reports it and exits 1 (unless --no-fail), and the agent edit hook, which runs the same check, blocks the agent on it.
Needs
A .skylos/ai-contract.yml contract that lists route folders under security.routes.paths and guard decorators under security.routes.require_any_decorator.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A route without its login or permission decorator is open to anyone who can reach the server. Agents often copy a neighbouring route and drop the decorator, and the endpoint still works in every manual test.

What Skylos flags

apps/api/invoices.py · PythonReported on line 16
from flask import Blueprint, jsonifyfrom flask_login import login_required from apps.api.store import load_invoice, refund_invoice bp = Blueprint("invoices", __name__)  @bp.get("/invoices/<int:invoice_id>")@login_requireddef show_invoice(invoice_id):    return jsonify(load_invoice(invoice_id))  @bp.post("/invoices/<int:invoice_id>/refund")def refund(invoice_id):    return jsonify(refund_invoice(invoice_id))
.skylos/ai-contract.yml · YAML
version: 1 security:  routes:    paths:      - "apps/api/**"    require_any_decorator:      - login_required

What Skylos leaves alone

apps/public/status.py · Python
from flask import Blueprint, jsonify bp = Blueprint("status", __name__)  @bp.get("/status")def status():    return jsonify({"ok": True})

.skylos/ai-contract.yml: same as in the flagged example.

Why Skylos leaves it alone

The status route has no guard, but it lives in apps/public/, outside the folders the contract names. The contract decides which routes must be guarded; public health checks are left to it.

More languages

Python

Flagged

apps/api/refunds.py · PythonReported on line 9
from fastapi import APIRouter from apps.api.store import refund_invoice router = APIRouter()  @router.post("/invoices/{invoice_id}/refund")def refund(invoice_id: int):    return refund_invoice(invoice_id)
.skylos/ai-contract.yml · YAML
version: 1 security:  routes:    paths:      - "apps/api/**"    require_any_decorator:      - login_required

Not flagged

apps/api/refunds.py · Python
from fastapi import APIRouter, Depends from apps.api.auth import login_requiredfrom apps.api.store import refund_invoice router = APIRouter()  @router.post(    "/invoices/{invoice_id}/refund",    dependencies=[Depends(login_required)],)def refund(invoice_id: int):    return refund_invoice(invoice_id)

.skylos/ai-contract.yml: same as in the flagged example.

Why Skylos leaves it alone

There is no guard decorator, but the route's dependencies= names login_required. A guard passed through dependencies or dependency_overrides of the route decorator counts.

How Skylos decides

  1. Runs only in skylos verify (and the agent edit hook that uses it), and only when a contract is found: --contract PATH, or .skylos/ai-contract.yml in the target folder or one of its parents. The contract must list both security.routes.paths and security.routes.require_any_decorator.
  2. Reads the .py files that match the contract's paths (a folder name, a glob, or folder/**), or only the changed or chosen file when skylos verify checks one file. Files that cannot be read or parsed are listed as unchecked.
  3. Finds functions with a route decorator: a dotted call such as bp.get, app.post, router.put or router.websocket (route, get, post, put, patch, delete, api_route, websocket), or a bare route or api_route.
  4. A route passes when one of its decorators has a required name (with or without @, call brackets or a module prefix), or when the route decorator's dependencies= or dependency_overrides= mentions one.
  5. Reports each route that has none, at its def line, naming the route path and the decorators the contract accepts. It checks that a decorator is present, not that it really authenticates.

How to fix it

Add the guard the contract asks for. If the route really must be public, move it out of the guarded folders, or narrow the contract's paths, in a change a person reviews.

Fix · Python
@bp.post("/invoices/<int:invoice_id>/refund")@login_requireddef refund(invoice_id):    return jsonify(refund_invoice(invoice_id))

When it can be wrong

  • A route guarded some other way, by a blueprint-wide before_request check, middleware or a guard with a name the contract does not list, is reported. List that guard's name in require_any_decorator.
  • Any decorated function whose decorator ends in .get, .post and so on counts as a route, so a non-web helper decorated with, say, cache.get inside a guarded folder is reported.
  • A decorator with a required name passes even if it does nothing; the rule checks presence, not behaviour.

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

  • Change the contract: narrow security.routes.paths so it leaves out the folder, or add the guard you use to require_any_decorator.

  • skylos verify --no-contract skips every contract check for one run.

  • In Skylos 5.6.0 neither # skylos: ignore[SKY-A105] on the def line nor [tool.skylos] ignore = ["SKY-A105"] silences it: the route check runs after those filters.

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