tcell_agent 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tcell_agent +10 -2
  3. data/lib/tcell_agent.rb +3 -3
  4. data/lib/tcell_agent/agent.rb +42 -52
  5. data/lib/tcell_agent/agent/event_processor.rb +129 -162
  6. data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
  7. data/lib/tcell_agent/agent/policy_manager.rb +83 -104
  8. data/lib/tcell_agent/agent/policy_types.rb +24 -29
  9. data/lib/tcell_agent/agent/route_manager.rb +36 -46
  10. data/lib/tcell_agent/agent/static_agent.rb +19 -21
  11. data/lib/tcell_agent/api.rb +23 -28
  12. data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
  13. data/lib/tcell_agent/authlogic.rb +7 -7
  14. data/lib/tcell_agent/cmdi.rb +22 -23
  15. data/lib/tcell_agent/config/unknown_options.rb +71 -69
  16. data/lib/tcell_agent/configuration.rb +187 -191
  17. data/lib/tcell_agent/devise.rb +13 -15
  18. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  19. data/lib/tcell_agent/instrumentation.rb +120 -124
  20. data/lib/tcell_agent/logger.rb +29 -45
  21. data/lib/tcell_agent/patches.rb +5 -5
  22. data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
  24. data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
  25. data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +24 -29
  28. data/lib/tcell_agent/rails.rb +2 -3
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
  30. data/lib/tcell_agent/rails/auth/devise.rb +2 -2
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
  32. data/lib/tcell_agent/rails/better_ip.rb +12 -16
  33. data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
  34. data/lib/tcell_agent/rails/dlp.rb +208 -107
  35. data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
  36. data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
  40. data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
  41. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
  42. data/lib/tcell_agent/rails/on_start.rb +5 -5
  43. data/lib/tcell_agent/rails/responses.rb +7 -9
  44. data/lib/tcell_agent/rails/routes.rb +62 -81
  45. data/lib/tcell_agent/rails/routes/grape.rb +25 -30
  46. data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
  47. data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
  48. data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
  49. data/lib/tcell_agent/routes/table.rb +31 -33
  50. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
  51. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
  52. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
  53. data/lib/tcell_agent/rust/models.rb +32 -37
  54. data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
  55. data/lib/tcell_agent/rust/whisperer.rb +101 -104
  56. data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
  57. data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
  58. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
  59. data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
  60. data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
  61. data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
  62. data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
  63. data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
  64. data/lib/tcell_agent/sensor_events/patches.rb +10 -12
  65. data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
  66. data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
  67. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
  68. data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
  69. data/lib/tcell_agent/servers/passenger.rb +5 -9
  70. data/lib/tcell_agent/servers/puma.rb +18 -27
  71. data/lib/tcell_agent/servers/rails_server.rb +5 -9
  72. data/lib/tcell_agent/servers/thin.rb +2 -4
  73. data/lib/tcell_agent/servers/unicorn.rb +18 -27
  74. data/lib/tcell_agent/servers/webrick.rb +2 -4
  75. data/lib/tcell_agent/settings_reporter.rb +126 -0
  76. data/lib/tcell_agent/sinatra.rb +24 -26
  77. data/lib/tcell_agent/start_background_thread.rb +21 -142
  78. data/lib/tcell_agent/system_info.rb +4 -3
  79. data/lib/tcell_agent/tcell_context.rb +150 -0
  80. data/lib/tcell_agent/userinfo.rb +3 -3
  81. data/lib/tcell_agent/utils/io.rb +19 -24
  82. data/lib/tcell_agent/utils/params.rb +9 -15
  83. data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
  84. data/lib/tcell_agent/utils/strings.rb +4 -6
  85. data/lib/tcell_agent/version.rb +1 -1
  86. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
  87. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
  88. data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
  89. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
  90. data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
  91. data/spec/lib/tcell_agent/patches_spec.rb +8 -8
  92. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
  93. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
  94. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
  95. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
  96. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
  97. data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
  98. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
  99. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
  100. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
  101. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
  102. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
  103. data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
  104. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
  105. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
  107. data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
  108. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
  109. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
  110. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
  111. data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
  112. data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
  113. data/spec/spec_helper.rb +5 -0
  114. metadata +18 -10
  115. data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
  116. data/lib/tcell_agent/patches/meta_data.rb +0 -59
  117. data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
  118. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
@@ -1,35 +1,30 @@
1
- # encoding: utf-8
2
-
3
- # See the file "LICENSE" for the full license governing this code.
4
-
5
- require "tcell_agent/policies/http_tx_policy"
6
- require "tcell_agent/policies/http_redirect_policy"
7
- require "tcell_agent/policies/login_fraud_policy"
8
- require "tcell_agent/policies/dataloss_policy"
9
- require "tcell_agent/policies/rust_policies"
1
+ require 'tcell_agent/policies/http_tx_policy'
2
+ require 'tcell_agent/policies/http_redirect_policy'
3
+ require 'tcell_agent/policies/login_fraud_policy'
4
+ require 'tcell_agent/policies/dataloss_policy'
5
+ require 'tcell_agent/policies/rust_policies'
10
6
 
11
7
  module TCellAgent
12
8
  class PolicyTypes
13
- CSP = "csp-headers"
14
- Clickjacking = "clickjacking"
15
- SecureHeaders = "secure-headers"
16
- HttpTx = "http-tx"
17
- HttpRedirect = "http-redirect"
18
- LoginFraud = "login"
19
- DataLoss = "dlp"
20
- AppSensor = "appsensor"
21
- Patches = "patches"
22
- CommandInjection = "cmdi"
23
- Regex = "regex"
24
- Rust = "rust"
25
- JSAgentInjection = "jsagentinjection"
26
-
27
- ClassMap = {
28
- HttpTx=>TCellAgent::Policies::HttpTxPolicy,
29
- HttpRedirect=>TCellAgent::Policies::HttpRedirectPolicy,
30
- LoginFraud=>TCellAgent::Policies::LoginFraudPolicy,
31
- DataLoss=>TCellAgent::Policies::DataLossPolicy
32
- }
9
+ CSP = 'csp-headers'.freeze
10
+ CLICKJACKING = 'clickjacking'.freeze
11
+ SECUREHEADERS = 'secure-headers'.freeze
12
+ HTTPTX = 'http-tx'.freeze
13
+ HTTPREDIRECT = 'http-redirect'.freeze
14
+ LOGINFRAUD = 'login'.freeze
15
+ DATALOSS = 'dlp'.freeze
16
+ APPSENSOR = 'appsensor'.freeze
17
+ PATCHES = 'patches'.freeze
18
+ COMMANDINJECTION = 'cmdi'.freeze
19
+ REGEX = 'regex'.freeze
20
+ RUST = 'rust'.freeze
21
+ JSAGENTINJECTION = 'jsagentinjection'.freeze
33
22
 
23
+ CLASS_MAP = {
24
+ HTTPTX => TCellAgent::Policies::HttpTxPolicy,
25
+ HTTPREDIRECT => TCellAgent::Policies::HttpRedirectPolicy,
26
+ LOGINFRAUD => TCellAgent::Policies::LoginFraudPolicy,
27
+ DATALOSS => TCellAgent::Policies::DataLossPolicy
28
+ }.freeze
34
29
  end
35
30
  end
@@ -1,15 +1,13 @@
1
- # encoding: utf-8
2
-
3
1
  # See the file "LICENSE" for the full license governing this code.
4
2
 
5
- require "tcell_agent/logger"
6
- require "tcell_agent/version"
7
- require "tcell_agent/api"
8
- require "tcell_agent/configuration"
3
+ require 'tcell_agent/logger'
4
+ require 'tcell_agent/version'
5
+ require 'tcell_agent/api'
6
+ require 'tcell_agent/configuration'
9
7
 
10
- require "tcell_agent/routes/table"
11
- require "tcell_agent/sensor_events/discovery"
12
- require "tcell_agent"
8
+ require 'tcell_agent/routes/table'
9
+ require 'tcell_agent/sensor_events/discovery'
10
+ require 'tcell_agent'
13
11
 
14
12
  module TCellAgent
15
13
  class Agent
@@ -18,48 +16,40 @@ module TCellAgent
18
16
  database,
19
17
  schema,
20
18
  table,
21
- fields.join(",")
22
- ].join(",").hash
19
+ fields.join(',')
20
+ ].join(',').hash
23
21
  end
24
22
 
25
- def discover_database_field(route_id, database, schema, table, field)
26
- discover_database_fields(route_id, database, schema, table, [field])
27
- end
23
+ def discover_database_fields(route_id, database, schema, table, fields)
24
+ return if route_id.nil? || database.nil? || schema.nil? || table.nil? || fields.nil?
28
25
 
29
- def discover_database_fields(route_id, database, schema, table, fields)
30
- if (route_id == nil ||
31
- database == nil ||
32
- schema == nil ||
33
- table == nil ||
34
- fields == nil)
35
- return
36
- end
37
- if TCellAgent::Agent.is_parent_process? == false
38
- TCellAgent.queue_metric({"_type"=>"discover_database_fields",
39
- "route_id"=>route_id,
40
- "database"=>database,
41
- "schema"=>schema,
42
- "table"=>table,
43
- "fields"=>fields})
26
+ if TCellAgent::Agent.parent_process? == false
27
+ TCellAgent.queue_metric('_type' => 'discover_database_fields',
28
+ 'route_id' => route_id,
29
+ 'database' => database,
30
+ 'schema' => schema,
31
+ 'table' => table,
32
+ 'fields' => fields)
44
33
  return
45
34
  end
35
+
46
36
  query_hash = TCellAgent::Agent.get_database_discovery_identifier(database, schema, table, fields)
47
- if (@route_table.routes[route_id].database_queries_discovered.fetch(query_hash, false) == false)
48
- @route_table.routes[route_id].database_queries_discovered[query_hash] = true
49
- event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
50
- TCellAgent.send_event(event)
51
- end
52
- #discovered_fields = fields.select { |field|
53
- # @route_table.routes[route_id].database_queries_discoverd[database][schema][table][field].discovered != true
54
- #}
55
- #if (discovered_fields.length > 0)
56
- # discovered_fields.each { |field|
57
- # @route_table.routes[route_id].database[database][schema][table][field].discovered = true
58
- # }
59
- # event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
60
- # TCellAgent.send_event(event)
61
- #end
62
- end
63
37
 
38
+ return if @route_table.routes[route_id].database_queries_discovered.fetch(query_hash, false)
39
+
40
+ @route_table.routes[route_id].database_queries_discovered[query_hash] = true
41
+ event = TCellAgent::SensorEvents::DiscoveryEvent.new(route_id).for_database_fields(database, schema, table, fields)
42
+ TCellAgent.send_event(event)
43
+ # discovered_fields = fields.select { |field|
44
+ # @route_table.routes[route_id].database_queries_discoverd[database][schema][table][field].discovered != true
45
+ # }
46
+ # if (discovered_fields.length > 0)
47
+ # discovered_fields.each { |field|
48
+ # @route_table.routes[route_id].database[database][schema][table][field].discovered = true
49
+ # }
50
+ # event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
51
+ # TCellAgent.send_event(event)
52
+ # end
53
+ end
64
54
  end
65
- end
55
+ end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  # See the file "LICENSE" for the full license governing this code.
4
2
  require 'tcell_agent/sensor_events/metrics'
5
3
  require 'monitor'
@@ -9,10 +7,10 @@ module TCellAgent
9
7
  @@my_thread_agent = nil
10
8
 
11
9
  def self.thread_agent
12
- if(self.thread_agent_defined? == false)
10
+ if thread_agent_defined? == false
13
11
  @@instance_lock.synchronize do
14
- if(self.thread_agent_defined? == false)
15
- @@my_thread_agent= TCellAgent::Agent.new(Process.pid)
12
+ if thread_agent_defined? == false
13
+ @@my_thread_agent = TCellAgent::Agent.new(Process.pid)
16
14
  end
17
15
  end
18
16
  end
@@ -23,45 +21,45 @@ module TCellAgent
23
21
  @@my_thread_agent != nil
24
22
  end
25
23
 
26
- # setter
27
24
  def self.thread_agent=(some_agent)
28
25
  @@instance_lock.synchronize do
29
26
  @@my_thread_agent = some_agent
30
27
  end
31
28
  end
32
29
 
33
- #class << self
34
- # attr_accessor :thread_agent
35
- #end
36
30
  def self.send_event(event)
37
- self.thread_agent.queueSensorEvent(event)
31
+ thread_agent.queue_sensor_event(event)
38
32
  end
33
+
39
34
  def self.queue_metric(event)
40
- self.thread_agent._queue_metric(event)
35
+ thread_agent._queue_metric(event)
41
36
  end
37
+
42
38
  def self.policy(policy_type)
43
- self.thread_agent.policies.fetch(policy_type, nil)
39
+ thread_agent.policies.fetch(policy_type, nil)
44
40
  end
41
+
45
42
  def self.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
46
- self.thread_agent.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
43
+ thread_agent.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
47
44
  end
45
+
48
46
  def self.increment_route(route_id, response_time)
49
- self.thread_agent.increment_route(route_id, response_time)
50
- end
51
- def self.discover_database_field(route_id, database, schema, table, field)
52
- self.thread_agent.discover_database_field(route_id, database, schema, table, field)
47
+ thread_agent.increment_route(route_id, response_time)
53
48
  end
49
+
54
50
  def self.discover_database_fields(route_id, database, schema, table, fields)
55
- self.thread_agent.discover_database_fields(route_id, database, schema, table, fields)
51
+ thread_agent.discover_database_fields(route_id, database, schema, table, fields)
56
52
  end
53
+
57
54
  def self.stop_agent
58
- self.thread_agent.stop_agent = true
55
+ thread_agent.stop_agent = true
59
56
  end
57
+
60
58
  def self.ensure_event_processor_running
61
- self.thread_agent.ensure_event_processor_running
59
+ thread_agent.ensure_event_processor_running
62
60
  end
63
61
 
64
62
  def self.safe_to_send_cmdi_events?
65
- self.thread_agent.safe_to_send_cmdi_events?
63
+ thread_agent.safe_to_send_cmdi_events?
66
64
  end
67
65
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # See the file "LICENSE" for the full license governing this code.
3
2
  require 'json'
4
3
  require 'tcell_agent/logger'
@@ -10,63 +9,59 @@ require 'net/http'
10
9
 
11
10
  module TCellAgent
12
11
  class TCellApi
12
+ def initialize; end
13
13
 
14
- def initialize
15
- end
16
-
17
- def poll_api(last_id=nil)
14
+ def poll_api(last_id = nil)
18
15
  if !TCellAgent.configuration || !TCellAgent.configuration.tcell_api_url || !TCellAgent.configuration.app_id
19
- raise TCellAgent::ConfigurationException.new("Config Information Not Found, can't poll for policy updates")
16
+ raise TCellAgent::ConfigurationException, "Config Information Not Found, can't poll for policy updates"
20
17
  end
21
18
 
22
19
  full_url = TCellAgent.configuration.tcell_api_url.sub(
23
20
  '{app_id}',
24
21
  TCellAgent.configuration.app_id
25
22
  )
26
- full_url += "&last_id=#{last_id.to_s}" if last_id
23
+ full_url += "&last_id=#{last_id}" if last_id
27
24
 
28
- TCellAgent.logger.debug "tCell.io API Request: " + full_url
25
+ TCellAgent.logger.debug("tCell.io API Request: #{full_url}")
29
26
 
30
27
  uri = URI(full_url)
31
28
  req = Net::HTTP::Get.new(uri.request_uri)
32
29
  req['Authorization'] = 'Bearer ' + TCellAgent.configuration.api_key
33
30
  begin
34
- req['TCellAgent'] = "RubyAgent " + TCellAgent::VERSION
31
+ req['TCellAgent'] = 'RubyAgent ' + TCellAgent::VERSION
35
32
  rescue StandardError => e
36
- TCellAgent.logger.debug("tCell.io Could not add agent string: " + e.message)
33
+ TCellAgent.logger.debug("tCell.io Could not add agent string: #{e.message}")
37
34
  end
38
35
 
39
36
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
40
37
 
41
38
  if res.is_a?(Net::HTTPSuccess)
42
- TCellAgent.logger.debug("tCell.io API Response: #{res.body}".force_encoding("UTF-8"))
39
+ TCellAgent.logger.debug("tCell.io API Response: #{res.body}".force_encoding('UTF-8'))
43
40
  return JSON.parse(res.body)
44
41
  else
45
42
  TCellAgent.logger.error("Received error response while contacting api: #{res.inspect}")
46
43
  end
47
44
 
48
- return nil
45
+ nil
49
46
  end
50
47
 
51
48
  def send_event_set(events)
52
49
  if !TCellAgent.configuration || !TCellAgent.configuration.tcell_input_url || !TCellAgent.configuration.app_id
53
- raise TCellAgent::ConfigurationException.new("Config Information Not Found, can't send events")
50
+ raise TCellAgent::ConfigurationException, "Config Information Not Found, can't send events"
54
51
  end
55
52
 
56
- if (events == nil)
57
- return false
58
- end
53
+ return false if events.nil?
59
54
 
60
- eventset = {"uuid" => TCellAgent.configuration.uuid,
61
- "hostname" => TCellAgent.configuration.host_identifier,
62
- "events" => events }
55
+ eventset = { 'uuid' => TCellAgent.configuration.uuid,
56
+ 'hostname' => TCellAgent.configuration.host_identifier,
57
+ 'events' => events }
63
58
  TCellAgent.logger.debug("Sending #{JSON.dump(eventset)}")
64
59
  full_url = TCellAgent.configuration.tcell_input_url +
65
- "/app/" +
66
- TCellAgent.configuration.app_id +
67
- "/server_agent"
60
+ '/app/' +
61
+ TCellAgent.configuration.app_id +
62
+ '/server_agent'
68
63
 
69
- TCellAgent.logger.debug("tCell.io SendEvents API Request: " + full_url)
64
+ TCellAgent.logger.debug("tCell.io SendEvents API Request: #{full_url}")
70
65
 
71
66
  uri = URI(full_url)
72
67
  req = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
@@ -76,21 +71,21 @@ module TCellAgent
76
71
  req['Accept'] = 'application/json'
77
72
 
78
73
  begin
79
- req['TCellAgent'] = "RubyAgent " + TCellAgent::VERSION
74
+ req['TCellAgent'] = 'RubyAgent ' + TCellAgent::VERSION
80
75
  rescue StandardError => e
81
- TCellAgent.logger.debug("tCell.io Could not add agent string: " + e.message)
76
+ TCellAgent.logger.debug('tCell.io Could not add agent string: ' + e.message)
82
77
  end
83
78
 
84
79
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
85
80
 
86
81
  TCellAgent.logger.debug("tCell.io SendEvents API Response: #{res.code}")
87
82
 
88
- return res.is_a?(Net::HTTPSuccess)
83
+ res.is_a?(Net::HTTPSuccess)
89
84
  end
90
85
 
91
86
  def valid_header?(str)
92
- return true if (/^[\p{L}\w\d\-_ :\/,;.'\"%?@#=$]*$/).match(str)
93
- return false
87
+ # TODO: test the unescaped backslash
88
+ str =~ %r{^[\p{L}\w\d\-_ :/,;.'\"%?@#=$]*$}
94
89
  end
95
90
  end
96
91
  end
@@ -1,9 +1,7 @@
1
1
  require 'tcell_agent/sensor_events/appsensor_event'
2
2
 
3
-
4
3
  module TCellAgent
5
4
  module AppSensor
6
-
7
5
  module InjectionsReporter
8
6
  def self.report_and_log(events)
9
7
  (events || []).each do |event|
@@ -11,18 +9,16 @@ module TCellAgent
11
9
  TCellAgent::SensorEvents::TCellAppSensorEvent.build_from_native_lib_event(event)
12
10
  )
13
11
 
14
- if event.has_key?("full_payload")
15
- event_to_log = {}.merge(event)
16
- event_to_log["payload"] = event_to_log.delete("full_payload")
12
+ next unless event.key?('full_payload')
13
+ event_to_log = {}.merge(event)
14
+ event_to_log['payload'] = event_to_log.delete('full_payload')
17
15
 
18
- cleaned_event = TCellAgent::SensorEvents::TCellAppSensorEvent.build_from_native_lib_event(
19
- event_to_log
20
- )
21
- TCellAgent.logger.info(JSON.dump(cleaned_event))
22
- end
16
+ cleaned_event = TCellAgent::SensorEvents::TCellAppSensorEvent.build_from_native_lib_event(
17
+ event_to_log
18
+ )
19
+ TCellAgent.logger.info(JSON.dump(cleaned_event))
23
20
  end
24
21
  end
25
22
  end
26
-
27
23
  end
28
24
  end
@@ -8,17 +8,17 @@ module TCellAgent
8
8
  if defined?(Authlogic)
9
9
  TCellAgent::UserInformation.class_eval do
10
10
  class << self
11
- alias_method :original_getUserFromRequest, :getUserFromRequest
12
- def getUserFromRequest(request)
13
- orig_user_id = original_getUserFromRequest(request)
11
+ alias_method :original_get_user_from_request, :get_user_from_request
12
+ def get_user_from_request(request)
13
+ orig_user_id = original_get_user_from_request(request)
14
14
  begin
15
- if request.session && request.session.has_key?("user_credentials_id")
16
- return request.session["user_credentials_id"].to_s
15
+ if request.session && request.session.key?('user_credentials_id')
16
+ return request.session['user_credentials_id'].to_s
17
17
  end
18
- rescue StandardError => e
18
+ rescue StandardError
19
19
  return orig_user_id
20
20
  end
21
- return orig_user_id
21
+ orig_user_id
22
22
  end
23
23
  end
24
24
  end
@@ -1,13 +1,12 @@
1
1
  require 'tcell_agent/agent/policy_types'
2
2
  require 'tcell_agent/utils/strings'
3
3
 
4
-
5
4
  module TCellAgent
6
5
  module Cmdi
7
6
  def self.block_command?(cmd)
8
- TCellAgent::Instrumentation.safe_block("Checking Command Injection Policy") do
7
+ TCellAgent::Instrumentation.safe_block('Checking Command Injection Policy') do
9
8
  if TCellAgent::Utils::Strings.present?(cmd)
10
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::Rust)
9
+ rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
11
10
  if rust_policies && rust_policies.cmdi_enabled
12
11
  request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
13
12
  Thread.current.object_id, {}
@@ -18,14 +17,14 @@ module TCellAgent
18
17
  end
19
18
  end
20
19
 
21
- return false
20
+ false
22
21
  end
23
22
 
24
23
  def self.parse_command(*args)
25
- cmd = ""
24
+ cmd = ''
26
25
 
27
- TCellAgent::Instrumentation.safe_block("CMDI Parsing *args") do
28
- if args.size > 0
26
+ TCellAgent::Instrumentation.safe_block('CMDI Parsing *args') do
27
+ unless args.empty?
29
28
  args_copy = Array.new(args)
30
29
  args_copy.shift if args_copy.first.is_a?(Hash)
31
30
  args_copy.pop if args_copy.last.is_a?(Hash)
@@ -35,7 +34,7 @@ module TCellAgent
35
34
  args_copy.unshift(cmd_n_argv0.first)
36
35
  end
37
36
 
38
- cmd = args_copy.join(" ")
37
+ cmd = args_copy.join(' ')
39
38
  end
40
39
  end
41
40
 
@@ -48,7 +47,7 @@ module Kernel
48
47
  alias_method :tcell_original_backtick, :`
49
48
  def `(cmd)
50
49
  if TCellAgent::Cmdi.block_command?(cmd)
51
- raise Errno::ENOENT.new("tCell.io Agent: Command not allowed by policy: #{cmd}")
50
+ raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
52
51
  end
53
52
 
54
53
  tcell_original_backtick(cmd)
@@ -58,7 +57,7 @@ module Kernel
58
57
  def exec(*args)
59
58
  cmd = TCellAgent::Cmdi.parse_command(*args)
60
59
  if TCellAgent::Cmdi.block_command?(cmd)
61
- raise Errno::ENOENT.new("tCell.io Agent: Command not allowed by policy: #{cmd}")
60
+ raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
62
61
  end
63
62
 
64
63
  tcell_original_exec(*args)
@@ -68,7 +67,7 @@ module Kernel
68
67
  def system(*args)
69
68
  cmd = TCellAgent::Cmdi.parse_command(*args)
70
69
  if TCellAgent::Cmdi.block_command?(cmd)
71
- raise Errno::ENOENT.new("tCell.io Agent: Command not allowed by policy: #{cmd}")
70
+ raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
72
71
  end
73
72
 
74
73
  tcell_original_system(*args)
@@ -78,10 +77,10 @@ module Kernel
78
77
  def spawn(*args)
79
78
  cmd = TCellAgent::Cmdi.parse_command(*args)
80
79
  if TCellAgent::Cmdi.block_command?(cmd)
81
- raise Errno::ENOENT.new("tCell.io Agent: Command not allowed by policy: #{cmd}")
80
+ raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
82
81
  end
83
82
 
84
- return tcell_original_spawn(*args)
83
+ tcell_original_spawn(*args)
85
84
  end
86
85
  end
87
86
 
@@ -89,27 +88,27 @@ class IO
89
88
  class << self
90
89
  alias_method :tcell_original_popen, :popen
91
90
  def popen(*args)
92
- if args.size > 0
93
- cmd = ""
91
+ unless args.empty?
92
+ cmd = ''
94
93
 
95
- TCellAgent::Instrumentation.safe_block("CMDI Parsing popen *args") do
94
+ TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do
96
95
  args_copy = Array.new(args)
97
96
  args_copy.shift if args_copy.first.is_a?(Hash)
98
97
  args_copy.pop if args_copy.last.is_a?(Hash)
99
98
 
100
- if args_copy.first.is_a?(String)
101
- cmd = args_copy.shift
102
- else
103
- cmd = TCellAgent::Cmdi.parse_command(*args_copy.shift)
104
- end
99
+ cmd = if args_copy.first.is_a?(String)
100
+ args_copy.shift
101
+ else
102
+ TCellAgent::Cmdi.parse_command(*args_copy.shift)
103
+ end
105
104
  end
106
105
 
107
106
  if TCellAgent::Cmdi.block_command?(cmd)
108
- raise Errno::ENOENT.new("tCell.io Agent: Command not allowed by policy: #{cmd}")
107
+ raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
109
108
  end
110
109
  end
111
110
 
112
- return tcell_original_popen(*args)
111
+ tcell_original_popen(*args)
113
112
  end
114
113
  end
115
114
  end