Skip to main content

SKY-D283 · Security in code

Unauthenticated control, destructive or admin route

CRITICAL when the same file also starts the server on every network interface (0.0.0.0 or ::), shows no authentication anywhere, and the handler really performs the action (it calls something named for it, or a process, signal or file-removal function). Otherwise HIGH.

Some web routes do dangerous things: reboot a machine, delete records, grant admin rights or run commands. SKY-D283 reports such a route in a Python web app (Flask, FastAPI, Quart, Starlette, Sanic or APIFlask) when nothing on the route, in its handler or in the same file checks who the caller is.

Languages
Python
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans). HIGH findings count toward the limits; a CRITICAL one fails the gate on its own.
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

Anyone who can reach the server can call the route. On an internal tool or a device that listens on every network interface, one curl -X POST from the same Wi-Fi or office network reboots the machine or deletes the data, with no login and no record of who did it.

What Skylos flags

app/server.py · PythonReported on line 14
import subprocess from flask import Flask, jsonify app = Flask(__name__)  @app.get("/status")def status():    return jsonify(ok=True)  @app.post("/system/reboot")def reboot():    subprocess.run(["systemctl", "reboot"], check=True)    return jsonify(status="rebooting")  if __name__ == "__main__":    app.run(host="0.0.0.0", port=8080)

What Skylos leaves alone

app/server.py · Python
import hmacimport osimport subprocess from flask import Flask, abort, jsonify, request app = Flask(__name__)API_KEY = os.environ["DEVICE_API_KEY"]  @app.before_requestdef require_api_key():    sent = request.headers.get("X-Api-Key", "")    if not hmac.compare_digest(sent, API_KEY):        abort(401)  @app.get("/status")def status():    return jsonify(ok=True)  @app.post("/system/reboot")def reboot():    subprocess.run(["systemctl", "reboot"], check=True)    return jsonify(status="rebooting")  if __name__ == "__main__":    app.run(host="0.0.0.0", port=8080)

Why Skylos leaves it alone

The reboot route and the open bind are unchanged, but a before_request hook reads the request headers and rejects the caller with abort(401). A request hook that may authenticate counts for every route of the app, so no route in this file is reported.

More languages

Python

Flagged

app/api.py · PythonReported on line 9
from fastapi import FastAPI from app.store import projects app = FastAPI()  @app.delete("/projects/{project_id}")def delete_project(project_id: int):    projects.delete(project_id)    return {"deleted": project_id}

Not flagged

app/api.py · Python
from fastapi import Depends, FastAPI from app.auth import require_adminfrom app.store import projects app = FastAPI()  @app.delete("/projects/{project_id}")def delete_project(project_id: int, admin=Depends(require_admin)):    projects.delete(project_id)    return {"deleted": project_id}

Why Skylos leaves it alone

A Depends(...) parameter can authenticate the request, so the route is skipped. The flagged version is a FastAPI DELETE route with no such parameter; it is HIGH because the file never starts a server on every interface.

How Skylos decides

  1. Runs with --danger on Python files. Skips files in test, tests or corpus folders and files named test_*.py or *_test.py.
  2. Needs an app created in the same file (Flask(), FastAPI(), Quart(), Starlette(), Sanic(), APIFlask()) and looks only at routes registered on it. A route registered on an app from another module is not checked.
  3. Skips the whole file when module code could authenticate every request: middleware other than CORS, GZip, trusted-host or HTTPS-redirect middleware, a before_request or middleware hook that reads credentials or rejects callers, or an app or router option such as dependencies=, auth= or permissions=.
  4. Keeps only routes that change state (POST, PUT, PATCH, DELETE) and that have nothing on the route that could authenticate: no other decorator, no decorator option beyond routing data, no Depends(), Security(), Header(), Cookie() or API-key parameter, and a handler that does not read request.headers, cookies, session or user, does not reject with 401 or 403 and uses no name such as auth, token or login.
  5. Reports the route only when its function name or path names a privileged action: control (reboot, shutdown, arm, power and similar), destructive (delete, drop, purge, wipe and similar, or any DELETE route), admin (admin, sudo, impersonate) or command (exec, shell, cmd). Other open mutating routes stay the quality review SKY-F102.
  6. Raises HIGH to CRITICAL when the file starts the server on 0.0.0.0 or :: (also as the default of os.environ.get), shows no authentication-named code anywhere, and the handler calls something named for the action or a subprocess, os.system, os.kill, os.remove or shutil.rmtree style function.

How to fix it

Check the caller before the route runs. Put the check where it covers every route, such as a before_request hook or FastAPI app dependencies=, so a new route cannot forget it. Bind the server to 127.0.0.1 unless other machines really need to reach it.

app/server.py · Python · the fix, against the flagged file
Added: import hmacAdded: import osimport subprocess Removed: from flask import Flask, jsonifyAdded: from flask import Flask, abort, jsonify, request app = Flask(__name__)Added: API_KEY = os.environ["DEVICE_API_KEY"]  Added: @app.before_requestAdded: def require_api_key():Added:     sent = request.headers.get("X-Api-Key", "")Added:     if not hmac.compare_digest(sent, API_KEY):Added:         abort(401)Added:  Added:  @app.get("/status")def status():    return jsonify(ok=True)  @app.post("/system/reboot")def reboot():    subprocess.run(["systemctl", "reboot"], check=True)    return jsonify(status="rebooting")  if __name__ == "__main__":Removed:     app.run(host="0.0.0.0", port=8080)Added:     app.run(host="127.0.0.1", port=8080)

When it can be wrong

  • Authentication done outside the file is not seen: a reverse proxy, an API gateway, or a WSGI wrapper set up in another module. Such an app is still reported.
  • A route whose name only sounds privileged is reported, for example POST /reports/export-command that only stores a request.
  • Missed: any authentication-like name in the handler (even an unused token variable) is taken as a possible check, and routes on an app created in another module are not checked.

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

  • Mark the def line of the route and say what protects it.

    Python
    def reboot():  # skylos: ignore[SKY-D283] only reachable through the VPN gateway
  • [tool.skylos] ignore = ["SKY-D283"] turns the rule off for the whole project.

  • skylos baseline . and then --baseline accept the routes you have and report only new ones.

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