Why it matters
The caller can supply a pattern that backtracks for minutes on a short input (ReDoS).
How to fix it
Quote the value with Regexp.escape when it is meant literally, and set Regexp.timeout (Ruby 3.2+).
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
class SearchController < ApplicationController
def index
pattern = Regexp.new(params[:q])
render json: Item.all.select { |i| pattern.match?(i.name) }
end
endclass SearchController < ApplicationController
def index
pattern = Regexp.new(Regexp.escape(params[:q].to_s))
render json: Item.all.select { |i| pattern.match?(i.name) }
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
- Template injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-template-injection - LDAP injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-ldap-injection - Unsafe reflection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-unsafe-reflection - XPath injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-xpath-injection - Code injection from request input (Ruby)
RubySeverity: High
trustivan-ruby-taint-code-injection - SQL string interpolation (Ruby)
RubySeverity: Medium
trustivan-ruby-sql-string-interpolation
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