Why it matters
A value such as ../../config/master.key walks out of the intended directory.
How to fix it
Reduce the value to a bare file name with File.basename before joining it to a fixed directory, and check the expanded path still starts with that directory.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
class DownloadsController < ApplicationController
def show
send_file Rails.root.join("uploads", params[:name]).to_s
end
endclass DownloadsController < ApplicationController
def show
name = File.basename(params[:name].to_s)
send_file Rails.root.join("uploads", name).to_s
end
endWhat TrustIvan reads
Runs on repository scans of Ruby source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Command injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-command-injection - SSRF from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-ssrf - SQL injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-sql-injection - XSS from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-xss - Deserialization from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-deserialization - Open redirect from request input (Ruby)
RubySeverity: Medium
trustivan-ruby-taint-open-redirect
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation