<commit_before>module Scanny
  module Checks
    class TempFileOpenCheck < Check
      def pattern
        [
          pattern_file_open,
          pattern_mkdir_p,
          pattern_tempfile
        ].join("|")
      end

      def check(node)
        issue :medium, warning_message, :cwe => 377
      end

      private

      def warning_message
        "Access to the temporary files can lead to" +
        "unauthorized access to data"
      end

      # File.open("/app/path/tmp_file")
      def pattern_file_open
        <<-EOT
          SendWithArguments<
            arguments = ActualArguments<
              array = [
                StringLiteral<string *= "tmp">
              ]
            >,
            receiver = ConstantAccess<name = :File>,
            name = :open
          >
        EOT
      end

      # mkdir_p("long/path/tmp/file")
      def pattern_mkdir_p
        <<-EOT
          SendWithArguments<
            arguments = ActualArguments<
              array = [
                StringLiteral<string *= "tmp">
              ]
            >,
            name = :mkdir_p
          >
        EOT
      end

      # Tempfile.new
      def pattern_tempfile
        <<-EOT
          SendWithArguments<
            name = :new,
            receiver = ConstantAccess<name = :Tempfile>
          >
        EOT
      end
    end
  end
end<commit_msg>Add sub-pattern for "/tmp/" in string<commit_after>module Scanny
  module Checks
    class TempFileOpenCheck < Check
      def pattern
        [
          pattern_temp,
          pattern_file_open,
          pattern_mkdir_p,
          pattern_tempfile
        ].join("|")
      end

      def check(node)
        issue :medium, warning_message, :cwe => 377
      end

      private

      def warning_message
        "Access to the temporary files can lead to" +
        "unauthorized access to data"
      end

      # File.open("/app/path/tmp_file")
      def pattern_file_open
        <<-EOT
          SendWithArguments<
            arguments = ActualArguments<
              array = [
                StringLiteral<string *= "tmp">
              ]
            >,
            receiver = ConstantAccess<name = :File>,
            name = :open
          >
        EOT
      end

      # mkdir_p("long/path/tmp/file")
      def pattern_mkdir_p
        <<-EOT
          SendWithArguments<
            arguments = ActualArguments<
              array = [
                StringLiteral<string *= "tmp">
              ]
            >,
            name = :mkdir_p
          >
        EOT
      end

      # Tempfile.new
      def pattern_tempfile
        <<-EOT
          SendWithArguments<
            name = :new,
            receiver = ConstantAccess<name = :Tempfile>
          >
        EOT
      end

      def pattern_temp
        'StringLiteral<string *= /\/tmp\//>'
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07952563655388908, 'fraction_numerical': 0.0020927799093128706, 'mean_word_length': 1.2458888018794048, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 24, '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': '2966581', 'n_tokens_mistral': 796, 'n_tokens_neox': 766, 'n_words': 178}