Skip to content

External control of file name or path

Description

The application dynamically constructs file or path information with user input when calling the `send_file` method in Ruby. This practice can lead to a serious security vulnerability known as Local File Inclusion (LFI), allowing attackers to read arbitrary files on the server.

Examples

Insecure Code

ruby
send_file params[:filename], x_sendfile: true

Secure Code

ruby
filename = params[:filename]; filepath = "path/to/secure/directory/#{File.basename(filename)}"; send_file filepath, x_sendfile: true

Remediation

Avoid direct user input, use `File.basename` to normalize input, and implement an allow list of permitted files or directories

Rule Details

FieldValue
IDCODE-0533
CategoryInjection
SeverityMEDIUM
CWECWE-73
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
TagsLFI, Path Traversal
OWASPA5:2017-Broken Access Control, A01:2021-Broken Access Control

References