<commit_before>require 'brakeman/checks/base_check'

#Check for vulnerability in translate() helper that allows cross-site scripting
#http://groups.google.com/group/rubyonrails-security/browse_thread/thread/2b61d70fb73c7cc5
class Brakeman::CheckTranslateBug < Brakeman::BaseCheck
  Brakeman::Checks.add self

  @description = "Report XSS vulnerability in translate helper"

  def run_check
    if (version_between?('2.3.0', '2.3.99') and tracker.config[:escape_html]) or
        version_between?('3.0.0', '3.0.10') or
        version_between?('3.1.0', '3.1.1')

      if uses_translate?
        confidence = CONFIDENCE[:high]
      else
        confidence = CONFIDENCE[:med]
      end

      version = tracker.config[:rails_version]

      if version =~ /^3\.1/
        message = "Versions before 3.1.2 have a vulnerability in the translate helper."
      elsif version =~ /^3\.0/
        message = "Versions before 3.0.11 have a vulnerability in translate helper."
      else
        message = "Rails 2.3.x using the rails_xss plugin have a vulnerability in translate helper."
      end

      warn :warning_type => "Cross Site Scripting",
        :message => message,
        :confidence => confidence,
        :file => gemfile_or_environment
    end
  end

  def uses_translate?
    Brakeman.debug "Finding calls to translate() or t()"

    not tracker.find_call(:target => nil, :methods => [:t, :translate]).empty?
  end
end
<commit_msg>more details on xss warning<commit_after>require 'brakeman/checks/base_check'

#Check for vulnerability in translate() helper that allows cross-site scripting
class Brakeman::CheckTranslateBug < Brakeman::BaseCheck
  Brakeman::Checks.add self

  @description = "Report XSS vulnerability in translate helper"

  def run_check
    if (version_between?('2.3.0', '2.3.99') and tracker.config[:escape_html]) or
        version_between?('3.0.0', '3.0.10') or
        version_between?('3.1.0', '3.1.1')

      confidence = if uses_translate?
        CONFIDENCE[:high]
      else
        CONFIDENCE[:med]
      end

      version = tracker.config[:rails_version]
      description = "have a vulnerability in the translate helper with keys ending in _html"

      message = if version =~ /^3\.1/
        "Versions before 3.1.2 #{description}."
      elsif version =~ /^3\.0/
        "Versions before 3.0.11 #{description}."
      else
        "Rails 2.3.x using the rails_xss plugin #{description}}."
      end

      warn :warning_type => "Cross Site Scripting",
        :message => message,
        :confidence => confidence,
        :file => gemfile_or_environment,
        :link_path => "http://groups.google.com/group/rubyonrails-security/browse_thread/thread/2b61d70fb73c7cc5"
    end
  end

  def uses_translate?
    Brakeman.debug "Finding calls to translate() or t()"

    tracker.find_call(:target => nil, :methods => [:t, :translate]).any?
  end
end

{'fraction_non_alphanumeric': 0.11925337020394054, 'fraction_numerical': 0.029035603180089874, 'mean_word_length': 3.0083102493074794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2878193', 'n_tokens_mistral': 964, 'n_tokens_neox': 890, 'n_words': 238}