Skip to content

Avoid Tainted FTP Call

Description

The application was found calling the Net::FTP modules methods with user supplied input. A malicious actor could use this to modify or access files they should not have access to. Directly incorporating user-controlled input from `params`, `cookies`, or `request.env` into FTP commands or connection setups can lead to various security vulnerabilities, including Remote Code Execution (RCE), unauthorized file access, and data exfiltration.

Examples

Insecure Code

ruby
Net::FTP.open('example.com', 'user', 'password') do |ftp| ftp.getbinaryfile(params[:filename], "local_#{params[:filename]}", 1024) end

Secure Code

ruby
filename = params[:filename]; raise "Invalid filename" unless filename =~ /\A[\w]+\.\w+\z/; Net::FTP.open('example.com', 'user', 'password') do |ftp| ftp.getbinaryfile(filename, "local_#{filename}", 1024) end

Remediation

Validate and sanitize user-provided input before being used in FTP operations. Verify the format and content of the input to ensure it meets expected criteria. Use allowlists to restrict the input to known safe values. Employ built-in security features of the programming language or framework to escape or safely handle user input.

Rule Details

FieldValue
IDCODE-0536
CategoryInjection
SeverityMEDIUM
CWECWE-76
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsftp, injection, tainted input
OWASPA1:2017-Injection, A03:2021-Injection

References