Skip to main content

SKY-L023 · AI-code defects

Phantom decorator

Critical

The catalog gives no severity for this rule; both detectors behind it report CRITICAL.

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, and block_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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/__init__.py · Python
 
app/permissions.py · Python
"""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 decorator
app/views.py · PythonReported on line 4
from app import permissions  @permissions.require_admindef delete_user(request, user_id):    request.db.users.delete(user_id)    return {"status": 204}

What Skylos leaves alone

app/__init__.py: same as in the flagged example.

app/permissions.py: same as in the flagged example.

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

app/__init__.py · Python
 
app/routing.py · Python
"""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 register
app/admin.py · PythonReported on line 5
from 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

app/__init__.py: same as in the flagged example.

app/routing.py: same as in the flagged example.

app/security.py · Python
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 wrapper
app/admin.py · Python
from 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

  1. Builds a table of every Python module in the project and the names each one defines at top level, imports or re-exports.
  2. For each decorator written as @module.name or @module.name(...), where module is one of the project's own modules, reports the decorator when that module has no name. 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 a try/except AttributeError.
  3. For a bare decorator, @name or @name(...), a second check looks the name up in a list of security decorators (login_required, requires_auth, admin_required, rate_limit, csrf_protect and others). It reports the decorator when the file neither defines nor imports that name. Other bare names are left to Python itself.
  4. 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.

app/views.py · Python · the fix, against the flagged file
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 a builtins patch 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_decorators under [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.

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