SKY-D283 · Security in code
Unauthenticated control, destructive or admin route
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
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
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
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
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
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
- Runs with
--dangeron Python files. Skips files intest,testsorcorpusfolders and files namedtest_*.pyor*_test.py. - 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. - Skips the whole file when module code could authenticate every request: middleware other than CORS, GZip, trusted-host or HTTPS-redirect middleware, a
before_requestormiddlewarehook that reads credentials or rejects callers, or an app or router option such asdependencies=,auth=orpermissions=. - 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, noDepends(),Security(),Header(),Cookie()or API-key parameter, and a handler that does not readrequest.headers, cookies, session or user, does not reject with 401 or 403 and uses no name such asauth,tokenorlogin. - Reports the route only when its function name or path names a privileged action: control (
reboot,shutdown,arm,powerand similar), destructive (delete,drop,purge,wipeand similar, or anyDELETEroute), admin (admin,sudo,impersonate) or command (exec,shell,cmd). Other open mutating routes stay the quality review SKY-F102. - Raises HIGH to CRITICAL when the file starts the server on
0.0.0.0or::(also as the default ofos.environ.get), shows no authentication-named code anywhere, and the handler calls something named for the action or asubprocess,os.system,os.kill,os.removeorshutil.rmtreestyle 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.
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-commandthat only stores a request. - Missed: any authentication-like name in the handler (even an unused
tokenvariable) 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
defline 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--baselineaccept the routes you have and report only new ones.