SKY-D215 · Security in code
Path traversal
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
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
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
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
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
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
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
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
- In Python, finds file operations:
open(),os.open(),os.remove(),os.unlink(),os.mkdir(),os.makedirs(),os.rmdir(),shutil.copy(),copy2(),copytree(),move()andrmtree(),pathlibmethods such asread_text(),write_bytes(),unlink()andrename()on a path object, and file responses: FastAPI and StarletteFileResponse, Flasksend_file(), and only thedirectoryargument ofsend_from_directory(). - Treats request data, route and MCP tool arguments,
input()and standard input as untrusted;flask.requestread through the module (import flask) counts likefrom 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. - 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.
- Does not report paths whose only source is the person running the program: command-line arguments and environment variables.
- Accepts values that cannot carry
/or..:os.path.basename(),Path(...).name, werkzeugsecure_filename(),safe_join()with a fixed base,hexdigest(), UUIDs,secrets.token_hex()andint(). - Accepts a guard before the call: a path normalised with
resolve(),realpath(),abspath()ornormpath()and checked withis_relative_to(),relative_to(),startswith()orcommonpath(), where the failing branch raises, returns, breaks, continues or callsabort(); anassertof the same; orname in ALLOWEDwhereALLOWEDis a literal collection or an upper-case name. A prefix check on a path that was not normalised does not count. - TypeScript and JavaScript: request data from a route handler reaching
fs,fs/promisesorfs-extrapaths, orres.sendFile()/res.download()without arootoption. Go (reported by the Go engine as SKY-G215 and SKY-G305): request or network input reachingos.Open,os.ReadFile,os.WriteFileand similar calls withoutfilepath.Base,SecureJoinor 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. - Rust:
std::fs,tokio::fsandasync_std::fsreads, writes, copies, renames and removals,File::open/create, andPathBuf::pushare listed only when request data is an actix-web or axum extractor (Path,Query,Json,Form, ...), a RocketJson/Form/Dataguard or text route parameter (#[get("/x/<name>")]withname: &str), or the data methods of anHttpRequest/Request(uri(),query_string(),headers(), ...). A path from an environment variable,std::env::argsor 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 withstarts_withaftercanonicalize, or by a-> boolvalidator 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.
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 callsabort(), 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
# noqadoes 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--baselineso only new ones are listed.[tool.skylos] ignore = ["SKY-D215"]turns the rule off for the whole project.