Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5914. OWASP. Possible unrestricted...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V5914. OWASP. Possible unrestricted file upload. Potentially tainted data can be used to set an extension of an uploaded file.

Dec 01 2026

The analyzer has detected that external data is saved to a file whose extension is specified by the client and is not validated. This could lead to an Unrestricted File Upload vulnerability.

This vulnerability can be categorized under the OWASP Top 10 Application Security Risks 2025: A06:2025 Insecure Design.

The example:

func SaveUpload(w http.ResponseWriter, r *http.Request) {
  file, header, _ := r.FormFile("upload")
  dst, _ := os.Create(filepath.Join("/var/www/uploads", header.Filename))
  io.Copy(dst, file)
  ....
}

The file's contents come from an HTTP request and are saved to a file whose name is specified by the client. The file extension in this name is not checked, so the client manages both the file's content and its type.

For example, an attacker could upload a script to a directory served by the web server and then access it using its known name. If the web server is configured to execute files of this type, the script runs on the server. Even if the server does not execute such files, an uploaded .html or .svg file can run a script in other users' browsers.

The example of such a filename for the code above:

shell.php

To protect against this vulnerability, check the file extension against an allowlist. We also recommend generating the file name on the server and storing uploaded files outside the directory served by the web server:

var allowedExts = map[string]bool{".jpg": true, ".png": true}

func SaveUpload(w http.ResponseWriter, r *http.Request) {
  file, header, _ := r.FormFile("upload")
  ext := strings.ToLower(filepath.Ext(header.Filename))
  if !allowedExts[ext] {
    http.Error(w, "invalid file type", http.StatusBadRequest)
    return
  }
  name := uuid.NewString() + ext
  dst, _ := os.Create(filepath.Join("/var/app/uploads", name))
  io.Copy(dst, file)
  ....
}

In the case, the server generates the file name, and only the extension selected from an allowed list is taken from the client. The OWASP guide on file upload recommends this approach, as well as checking the contents of uploaded files.

This diagnostic rule is classified as: