A file is opened, written or removed at a path taken from an HTTP request without a check

tx0/go:request-path-in-file-accessrecommendedwarningsecurity, cwe-22

What it finds

os.ReadFile(filepath.Join(root, r.URL.Query().Get("name"))): a name from the request can contain ../, or be an absolute path, and so reach any file the process may read or write, not only those under root. Joining and cleaning do not stop that; filepath.Base, filepath.IsLocal, or os.Root (Go 1.24) keep the name inside.

A request value is a query or form value, a header, the path or the referrer of an *http.Request parameter, or a local variable built from one, as described for the request values of the pack. It must reach the path of os.Open, os.OpenFile, os.Create, os.ReadFile, os.WriteFile, os.Remove, os.RemoveAll, os.Mkdir, os.MkdirAll, os.ReadDir, os.Stat, ioutil.ReadFile, ioutil.WriteFile or the file argument of http.ServeFile. A variable that the function checks in a condition is taken as validated.

From the rule's source, request_path_in_file_access.rs.

Example from the rule's tests
package p import (	"net/http"	"os"	"path/filepath") func serve(w http.ResponseWriter, r *http.Request) {	name := r.URL.Query().Get("name")	data, _ := os.ReadFile(filepath.Join("/srv/files", name))tx0 reports: os.ReadFile is given a path taken from the request	w.Write(data)	http.ServeFile(w, r, r.FormValue("file"))tx0 reports: http.ServeFile is given a path taken from the request	checked := r.FormValue("doc")	if !filepath.IsLocal(checked) {		return	}	os.Remove(filepath.Join("/srv", checked))	os.Remove(filepath.Join("/srv", filepath.Base(r.FormValue("x"))))}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:request-path-in-file-access" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:request-path-in-file-access] reason="..."

tx0 explain tx0/go:request-path-in-file-access shows the same in the terminal. Found a false positive? Report it.