SKY-L023 · AI-code defects
Phantom decorator
A decorator is the @name line above a function that wraps it, and security checks such as "admin only" are often written as decorators. SKY-L023 reports a decorator that does not exist where the code says it lives: @permissions.require_admin when the project's permissions module has no require_admin, or a bare @login_required that is never imported.
- Languages
- Python
- Turned on by
skylos . --ai-defects(or-a); reads the code as it is, no diff needed- Quality gate
- counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). Counts toward
max_ai_defects. Every finding is CRITICAL, andblock_ai_defect_severities(under[tool.skylos.gate]) is["CRITICAL"]by default, so one finding fails the gate on its own. The agent hook (skylos verify) also blocks on it. - Finding type
- review
Why it matters
Python looks the decorator up when the module is imported, so the service fails to start, or, if an agent "fixes" the error by deleting the line, the handler runs with no access check at all. Either way the guard the code appears to have is not there.
What Skylos flags
"""Role checks for request handlers.""" import functools def require_role(role): def decorator(view): @functools.wraps(view) def wrapper(request, *args, **kwargs): if role not in request.user.roles: return {"status": 403} return view(request, *args, **kwargs) return wrapper return decoratorfrom app import permissions @permissions.require_admindef delete_user(request, user_id): request.db.users.delete(user_id) return {"status": 204}What Skylos leaves alone
from app import permissions @permissions.require_role("admin")def delete_user(request, user_id): request.db.users.delete(user_id) return {"status": 204}Why Skylos leaves it alone
require_role is defined in app/permissions.py, so the decorator resolves. Skylos checks the name, not the arguments: ("admin") is the project's own business.
More languages
Python
Flagged
"""A tiny router for the admin API.""" ROUTES = {} def route(path, methods=("GET",)): def register(view): for method in methods: ROUTES[(method, path)] = view return view return registerfrom app.routing import route @route("/admin/users/<user_id>", methods=["DELETE"])@login_requireddef delete_user(request, user_id): request.db.users.delete(user_id) return {"status": 204}Not flagged
import functools def login_required(view): @functools.wraps(view) def wrapper(request, *args, **kwargs): if request.user is None: return {"status": 401} return view(request, *args, **kwargs) return wrapperfrom app.routing import routefrom app.security import login_required @route("/admin/users/<user_id>", methods=["DELETE"])@login_requireddef delete_user(request, user_id): request.db.users.delete(user_id) return {"status": 204}Why Skylos leaves it alone
login_required is imported from a module that defines it. A bare decorator is reported only when its name is on Skylos's list of security decorators and the file neither defines nor imports it.
How Skylos decides
- Builds a table of every Python module in the project and the names each one defines at top level, imports or re-exports.
- For each decorator written as
@module.nameor@module.name(...), wheremoduleis one of the project's own modules, reports the decorator when that module has noname. It stays silent when the module has a module-level__getattr__or otherwise writes its own namespace, when the name is bound only in some branches, or when the decorator sits under atry/except AttributeError. - For a bare decorator,
@nameor@name(...), a second check looks the name up in a list of security decorators (login_required,requires_auth,admin_required,rate_limit,csrf_protectand others). It reports the decorator when the file neither defines nor imports that name. Other bare names are left to Python itself. - Decorators from installed packages (
@app.route,@pytest.fixture) are not checked by this rule.
How to fix it
Use the decorator the project really has, or write the missing one in the module the code names. Never delete the decorator line to make the import error go away: that removes the access check.
from app import permissions Removed: @permissions.require_adminAdded: @permissions.require_role("admin")def delete_user(request, user_id): request.db.users.delete(user_id) return {"status": 204}When it can be wrong
- A bare security decorator that reaches the file through a star import (
from app.security import *) or abuiltinspatch is reported, because the file does not import it by name. - A module that adds decorators at run time with a computed name, for example a plugin loader, can make a real decorator look missing.
- To add your own decorator names to the security list, set
extra_phantom_decoratorsunder[tool.skylos.vibe].
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
On the decorator line, with the reason the name exists at run time:
Python @permissions.require_admin # skylos: ignore[SKY-L023] added by plugin loader[tool.skylos] ignore = ["SKY-L023"]turns the rule off for the project.