Skip to main content

SKY-D215 · Security in code

Path traversal

HighCWE-22

Every language reports HIGH. In shell scripts the severity drops to MEDIUM when only the script's own arguments reach the path behind a root-only check, or when the command runs as a non-root user. A shell finding whose only source is the script's own command-line arguments is a review signal that is not listed by default and does not fail a gate, as is a Rust finding whose only inputs are environment variables, command-line arguments or a function's parameters.

Path traversal happens when outside text chooses a file path and can use ../ or an absolute path to leave the folder the program meant to use. Skylos reports SKY-D215 when request data, or a value that a request can reach through a project caller, becomes the path of a file read, write, delete or download.

Languages
Python, TypeScript/JavaScript, Go, Java, Kotlin, C#, PHP, Rust, Dart, Shell
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Go engine ID
SKY-G215, reported as SKY-D215
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A download link called with name=../../etc/passwd or name=../.env hands out files the server can read, including keys and database passwords. On a write or delete path, the same trick overwrites code or removes data.

What Skylos flags

app/files.py · PythonReported on line 12
import os from flask import Flask, request, send_file app = Flask(__name__)UPLOAD_DIR = "/srv/uploads"  @app.get("/files")def download():    name = request.args.get("name", "")    return send_file(os.path.join(UPLOAD_DIR, name))

What Skylos leaves alone

app/files.py · Python
from flask import Flask, request, send_from_directory app = Flask(__name__)UPLOAD_DIR = "/srv/uploads"  @app.get("/files")def download():    name = request.args.get("name", "")    return send_from_directory(UPLOAD_DIR, name)

Why Skylos leaves it alone

Flask's send_from_directory() joins the name with safe_join(), which refuses any result outside UPLOAD_DIR. Skylos only checks its directory argument, which here is a fixed setting.

More languages

TypeScript

Flagged

src/server.ts · TypeScriptReported on line 9
import express from "express";import path from "path"; const app = express();const UPLOAD_DIR = "/srv/uploads"; app.get("/files", (req, res) => {  const name = String(req.query.name ?? "");  res.sendFile(path.join(UPLOAD_DIR, name));}); app.listen(3000);

Not flagged

src/server.ts · TypeScript
import express from "express"; const app = express();const UPLOAD_DIR = "/srv/uploads"; app.get("/files", (req, res) => {  const name = String(req.query.name ?? "");  res.sendFile(name, { root: UPLOAD_DIR });}); app.listen(3000);

Why Skylos leaves it alone

With the root option, Express resolves the name under UPLOAD_DIR and refuses names that climb out of it with ...

Go

Flagged

main.go · GoReported on line 13
package main import (	"net/http"	"os"	"path/filepath") const uploadDir = "/srv/uploads" func download(w http.ResponseWriter, r *http.Request) {	name := r.URL.Query().Get("name")	data, err := os.ReadFile(filepath.Join(uploadDir, name))	if err != nil {		http.NotFound(w, r)		return	}	w.Header().Set("Content-Type", "application/octet-stream")	w.Write(data)} func main() {	http.HandleFunc("/files", download)	http.ListenAndServe(":8080", nil)}

Not flagged

main.go · Go
package main import (	"net/http"	"os"	"path/filepath") const uploadDir = "/srv/uploads" func download(w http.ResponseWriter, r *http.Request) {	name := r.URL.Query().Get("name")	data, err := os.ReadFile(filepath.Join(uploadDir, filepath.Base(name)))	if err != nil {		http.NotFound(w, r)		return	}	w.Header().Set("Content-Type", "application/octet-stream")	w.Write(data)} func main() {	http.HandleFunc("/files", download)	http.ListenAndServe(":8080", nil)}

Why Skylos leaves it alone

filepath.Base() keeps only the last part of the name, so it cannot contain a folder or ... Skylos treats its result as safe.

How Skylos decides

  1. In Python, finds file operations: open(), os.open(), os.remove(), os.unlink(), os.mkdir(), os.makedirs(), os.rmdir(), shutil.copy(), copy2(), copytree(), move() and rmtree(), pathlib methods such as read_text(), write_bytes(), unlink() and rename() on a path object, and file responses: FastAPI and Starlette FileResponse, Flask send_file(), and only the directory argument of send_from_directory().
  2. Treats request data, route and MCP tool arguments, input() and standard input as untrusted; flask.request read through the module (import flask) counts like from flask import request. A path built from a helper's parameter is followed to every caller Skylos can resolve in the project, and is reported when a chain starts at untrusted data.
  3. Moves a helper-parameter finding to the suppressed list when every resolved caller passes literals, operator input or other safe values, and also when a caller cannot be resolved (including a helper nobody calls). A chain cut off by a depth or size limit before it reaches untrusted data stays in the report as a review signal ("callers not visible"): it is not listed by default and does not fail a gate.
  4. Does not report paths whose only source is the person running the program: command-line arguments and environment variables.
  5. Accepts values that cannot carry / or ..: os.path.basename(), Path(...).name, werkzeug secure_filename(), safe_join() with a fixed base, hexdigest(), UUIDs, secrets.token_hex() and int().
  6. Accepts a guard before the call: a path normalised with resolve(), realpath(), abspath() or normpath() and checked with is_relative_to(), relative_to(), startswith() or commonpath(), where the failing branch raises, returns, breaks, continues or calls abort(); an assert of the same; or name in ALLOWED where ALLOWED is a literal collection or an upper-case name. A prefix check on a path that was not normalised does not count.
  7. TypeScript and JavaScript: request data from a route handler reaching fs, fs/promises or fs-extra paths, or res.sendFile() / res.download() without a root option. Go (reported by the Go engine as SKY-G215 and SKY-G305): request or network input reaching os.Open, os.ReadFile, os.WriteFile and similar calls without filepath.Base, SecureJoin or a check on a cleaned path, and archive entry names written to disk without a .. check. Java, Kotlin, C#, PHP, Dart and shell scripts have their own checks with the same idea.
  8. Rust: std::fs, tokio::fs and async_std::fs reads, writes, copies, renames and removals, File::open/create, and PathBuf::push are listed only when request data is an actix-web or axum extractor (Path, Query, Json, Form, ...), a Rocket Json/Form/Data guard or text route parameter (#[get("/x/<name>")] with name: &str), or the data methods of an HttpRequest/Request (uri(), query_string(), headers(), ...). A path from an environment variable, std::env::args or a library function's parameter (Searcher::search_path(path)) is a review item that is not listed and does not fail a gate. A path checked with starts_with after canonicalize, or by a -> bool validator that rejects it with an early return, is not reported.

How to fix it

Resolve the full path and check that it is still inside the base folder before using it. Reject everything else.

app/files.py · Python · the fix, against the flagged file
Removed: import osAdded: from pathlib import Path Removed: from flask import Flask, request, send_fileAdded: from flask import Flask, abort, request, send_file app = Flask(__name__)Removed: UPLOAD_DIR = "/srv/uploads"Added: UPLOAD_DIR = Path("/srv/uploads").resolve()  @app.get("/files")def download():    name = request.args.get("name", "")Removed:     return send_file(os.path.join(UPLOAD_DIR, name))Added:     path = (UPLOAD_DIR / name).resolve()Added:     if not path.is_relative_to(UPLOAD_DIR):Added:         abort(404)Added:     return send_file(path)

When it can be wrong

  • A check made inside another function, such as ensure_inside(path) that calls abort(), is not seen: the path is still reported.
  • An allowlist kept in a lower-case variable (if name not in reports: abort(404)) is not recognised; use a literal set or an upper-case constant.
  • An open() that reads or writes the same path usually also gets SKY-D325 or SKY-D324, which ask about symlinks. They are separate findings.

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

  • Silence one line and say why. A bare # noqa does not hide HIGH security findings.

    Python
    return send_file(path)  # skylos: ignore[SKY-D215] path checked by ensure_inside()
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed.

  • [tool.skylos] ignore = ["SKY-D215"] turns the rule off for the whole project.

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