console1984 0.1.13 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78f591775f469668e6d50741f421c188e048e42942ce4a9c9c707e9a34328c69
4
- data.tar.gz: 190d0069e0bc4268400e59f1884539403233fd66fb873892d41ecf5e3d888323
3
+ metadata.gz: 58a963520fed8a86952cee9b02443b61d42ac4bf0a80d1abaabfd3ff390f431b
4
+ data.tar.gz: a63a68db2a2e46a129f4f97f79a59b41a88fe98ecb9d6028d67ca0e8d4b1e6fa
5
5
  SHA512:
6
- metadata.gz: d6930e488260091857f8f2196ef88ec3c364391de1b1a9e9385a246153c80a1b5c7cd3cafd76d988d54f3ded5b4b3f66b2ae1d9735cc5ebeacadabd4a3bbe12e
7
- data.tar.gz: 19746bce408667fb06d48e5a98032999e46a44b47f3620d510b5ce4a707a9414c76f57b996d5a707372bf533b5904aa2af19bd0b9c2866fc8d00e4b2e5228f70
6
+ metadata.gz: 2bb93f84dc7e078b4d357739b337b2277fce627408cb619c816a04fc94db7451faf7d2095d0861ca211726ce973481161ae47c4add5e185c8813904462d1c011
7
+ data.tar.gz: d1b623b30f72e49d744934e4623159bfabf5cd7b9a4fab94fc08c26c30fc8bf1115bd70bf4b92b12609874d6ab75dc0d978663079745df2b9b1e238cadaf11ed
data/README.md CHANGED
@@ -155,9 +155,9 @@ These config options are namespaced in `config.console1984`:
155
155
 
156
156
  ## About built-in protection mechanisms
157
157
 
158
- `console1984` uses Ruby to add several protection mechanisms. However, because Ruby is highly dynamic, it's technically possible to circumvent most of these controls if you know what you are doing. We have made an effort to prevent such attempts, but if your organization needs bullet-proof protection against malicious actors using the console, you should consider additional security measures.
158
+ `console1984` adds many protection mechanisms to prevent tampering. This includes attempts to alter data in auditing tables or monkey patching certain classes to change how the system works. If you find a way to circumvent these tampering controls, please [report an issue](https://github.com/basecamp/console1984/issues).
159
159
 
160
- The current version includes protection mechanisms to avoid tampering the tables that store console sessions. A bullet-proof mechanism would be using a read only connection when user commands are evaluated. Implementing such scheme is possible by writing a custom session logger and leveraging Rails' multi-database support. We would like that future versions of `console1984` supported this scheme directly as a configuration option.
160
+ We aim to make these defense mechanisms as robust as possible, but there might always be open doors because Ruby is highly dynamic. If your organization needs bullet-proof protection against malicious actors using the console, you should consider additional security measures. An example would be using a read-only database user for auditing data while in a console. The gem doesn't offer direct support for doing this, but it's on our radar for future improvement.
161
161
 
162
162
  ## Running the test suite
163
163
 
@@ -5,6 +5,7 @@ validations:
5
5
  - PG
6
6
  - Mysql2
7
7
  - IRB
8
+ - Parser
8
9
  forbidden_constant_reference:
9
10
  always:
10
11
  - Console1984
@@ -10,6 +10,7 @@ class Console1984::CommandExecutor
10
10
  include Console1984::Freezeable
11
11
 
12
12
  delegate :username_resolver, :session_logger, :shield, to: Console1984
13
+ attr_reader :last_suspicious_command_error
13
14
 
14
15
  # Logs and validates +commands+, and executes the passed block in a protected environment.
15
16
  #
@@ -19,14 +20,14 @@ class Console1984::CommandExecutor
19
20
  run_as_system { session_logger.before_executing commands }
20
21
  validate_command commands
21
22
  execute_in_protected_mode(&block)
22
- rescue Console1984::Errors::ForbiddenCommandAttempted, FrozenError
23
- flag_suspicious(commands)
24
- rescue Console1984::Errors::SuspiciousCommandAttempted
25
- flag_suspicious(commands)
23
+ rescue Console1984::Errors::ForbiddenCommandAttempted, FrozenError => error
24
+ flag_suspicious(commands, error: error)
25
+ rescue Console1984::Errors::SuspiciousCommandAttempted => error
26
+ flag_suspicious(commands, error: error)
26
27
  execute_in_protected_mode(&block)
27
- rescue Console1984::Errors::ForbiddenCommandExecuted
28
+ rescue Console1984::Errors::ForbiddenCommandExecuted => error
28
29
  # We detected that a forbidden command was executed. We exit IRB right away.
29
- flag_suspicious(commands)
30
+ flag_suspicious(commands, error: error)
30
31
  Console1984.supervisor.exit_irb
31
32
  ensure
32
33
  run_as_system { session_logger.after_executing commands }
@@ -70,11 +71,7 @@ class Console1984::CommandExecutor
70
71
  end
71
72
 
72
73
  def from_irb?(backtrace)
73
- executing_user_command? && backtrace.find do |line|
74
- line_from_irb = line =~ /^[^\/]/
75
- break if !(line =~ /console1984\/lib/ || line_from_irb)
76
- line_from_irb
77
- end
74
+ executing_user_command? && backtrace.first.to_s =~ /^[^\/]/
78
75
  end
79
76
 
80
77
  private
@@ -86,9 +83,10 @@ class Console1984::CommandExecutor
86
83
  Console1984::CommandValidator.from_config(Console1984.protections_config.validations)
87
84
  end
88
85
 
89
- def flag_suspicious(commands)
86
+ def flag_suspicious(commands, error: nil)
90
87
  puts "Forbidden command attempted: #{commands.join("\n")}"
91
88
  run_as_system { session_logger.suspicious_commands_attempted commands }
89
+ @last_suspicious_command_error = error
92
90
  nil
93
91
  end
94
92
 
@@ -6,7 +6,7 @@ module Console1984::Ext::Core::Module
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  def instance_eval(*)
9
- if Console1984.command_executor.executing_user_command?
9
+ if Console1984.command_executor.from_irb?(caller)
10
10
  raise Console1984::Errors::ForbiddenCommandAttempted
11
11
  else
12
12
  super
@@ -16,7 +16,7 @@ module Console1984::Ext::Core::Object
16
16
 
17
17
  class_methods do
18
18
  def const_get(*arguments)
19
- if Console1984.command_executor.executing_user_command?
19
+ if Console1984.command_executor.from_irb?(caller)
20
20
  begin
21
21
  # To validate if it's an invalid constant, we try to declare a class with it.
22
22
  # We essentially leverage Console1984::CommandValidator::ForbiddenReopeningValidation here:
@@ -0,0 +1,24 @@
1
+ # Prevents loading forbidden classes dynamically.
2
+ #
3
+ # See extension to +Console1984::Ext::Core::Object#const_get+.
4
+ module Console1984::Ext::Core::String
5
+ extend ActiveSupport::Concern
6
+
7
+ include Console1984::Freezeable
8
+ self.prevent_instance_data_manipulation_after_freezing = false
9
+
10
+ def constantize
11
+ if Console1984.command_executor.from_irb?(caller)
12
+ begin
13
+ Console1984.command_executor.validate_command("class #{self}; end")
14
+ super
15
+ rescue Console1984::Errors::ForbiddenCommandAttempted
16
+ raise
17
+ rescue StandardError
18
+ super
19
+ end
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
@@ -13,4 +13,13 @@ module Console1984::Ext::Irb::Commands
13
13
  def encrypt!
14
14
  shield.enable_protected_mode
15
15
  end
16
+
17
+ # This returns the last error that prevented a command execution in the console
18
+ # or nil if there isn't any.
19
+ #
20
+ # This is meant for internal usage when debugging legit commands that are wrongly
21
+ # prevented.
22
+ def _console_last_suspicious_command_error
23
+ Console1984.command_executor.last_suspicious_command_error
24
+ end
16
25
  end
@@ -11,6 +11,11 @@ class Console1984::Refrigerator
11
11
  end
12
12
 
13
13
  private
14
+ def eager_load_all_classes
15
+ Rails.application.eager_load! unless Rails.application.config.eager_load
16
+ Console1984.class_loader.eager_load
17
+ end
18
+
14
19
  def freeze_internal_instances
15
20
  Console1984.config.freeze unless Console1984.config.test_mode
16
21
  end
@@ -23,9 +28,4 @@ class Console1984::Refrigerator
23
28
  # Not using a constant because we want this to run lazily (console-dependant dependencies might not be loaded).
24
29
  [Parser::CurrentRuby]
25
30
  end
26
-
27
- def eager_load_all_classes
28
- Rails.application.eager_load! unless Rails.application.config.eager_load
29
- Console1984.class_loader.eager_load
30
- end
31
31
  end
@@ -40,6 +40,7 @@ class Console1984::Shield
40
40
  def extend_core_ruby
41
41
  Object.prepend Console1984::Ext::Core::Object
42
42
  Module.prepend Console1984::Ext::Core::Module
43
+ String.prepend Console1984::Ext::Core::String
43
44
  end
44
45
 
45
46
  def extend_sockets
@@ -1,3 +1,3 @@
1
1
  module Console1984
2
- VERSION = '0.1.13'
2
+ VERSION = '0.1.17'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console1984
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Manrubia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-10 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activeresource
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: benchmark-ips
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +225,7 @@ files:
211
225
  - lib/console1984/ext/active_record/protected_auditable_tables.rb
212
226
  - lib/console1984/ext/core/module.rb
213
227
  - lib/console1984/ext/core/object.rb
228
+ - lib/console1984/ext/core/string.rb
214
229
  - lib/console1984/ext/irb/commands.rb
215
230
  - lib/console1984/ext/irb/context.rb
216
231
  - lib/console1984/ext/socket/tcp_socket.rb