console1984 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -10
- data/config/protections.yml +30 -0
- data/lib/console1984/command_executor.rb +90 -0
- data/lib/console1984/command_validator/forbidden_constant_reference_validation.rb +31 -0
- data/lib/console1984/command_validator/forbidden_reopening_validation.rb +29 -0
- data/lib/console1984/command_validator/parsed_command.rb +90 -0
- data/lib/console1984/command_validator/suspicious_terms_validation.rb +22 -0
- data/lib/console1984/command_validator.rb +71 -0
- data/lib/console1984/config.rb +21 -9
- data/lib/console1984/engine.rb +6 -8
- data/lib/console1984/errors.rb +10 -1
- data/lib/console1984/ext/active_record/protected_auditable_tables.rb +28 -0
- data/lib/console1984/ext/core/module.rb +15 -0
- data/lib/console1984/ext/core/object.rb +43 -0
- data/lib/console1984/ext/irb/commands.rb +16 -0
- data/lib/console1984/ext/irb/context.rb +20 -0
- data/lib/console1984/{protected_tcp_socket.rb → ext/socket/tcp_socket.rb} +10 -4
- data/lib/console1984/freezeable.rb +70 -0
- data/lib/console1984/{supervisor/input_output.rb → input_output.rb} +9 -3
- data/lib/console1984/messages.rb +0 -10
- data/lib/console1984/protections_config.rb +17 -0
- data/lib/console1984/refrigerator.rb +32 -0
- data/lib/console1984/sessions_logger/database.rb +3 -1
- data/lib/console1984/shield/method_invocation_shell.rb +52 -0
- data/lib/console1984/shield/modes/protected.rb +27 -0
- data/lib/console1984/shield/modes/unprotected.rb +8 -0
- data/lib/console1984/shield/modes.rb +60 -0
- data/lib/console1984/shield.rb +85 -0
- data/lib/console1984/supervisor.rb +27 -22
- data/lib/console1984/username/env_resolver.rb +2 -0
- data/lib/console1984/version.rb +1 -1
- data/lib/console1984.rb +43 -21
- metadata +66 -14
- data/config/routes.rb +0 -9
- data/lib/console1984/commands.rb +0 -16
- data/lib/console1984/frozen_methods.rb +0 -17
- data/lib/console1984/protected_auditable_tables.rb +0 -29
- data/lib/console1984/protected_context.rb +0 -18
- data/lib/console1984/supervisor/accesses/protected.rb +0 -10
- data/lib/console1984/supervisor/accesses/unprotected.rb +0 -5
- data/lib/console1984/supervisor/accesses.rb +0 -41
- data/lib/console1984/supervisor/executor.rb +0 -41
- data/lib/console1984/supervisor/protector.rb +0 -37
data/config/routes.rb
DELETED
data/lib/console1984/commands.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module Console1984::Commands
|
2
|
-
def decrypt!
|
3
|
-
supervisor.enable_access_to_encrypted_content
|
4
|
-
end
|
5
|
-
|
6
|
-
def encrypt!
|
7
|
-
supervisor.disable_access_to_encrypted_content
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
def supervisor
|
12
|
-
Console1984.supervisor
|
13
|
-
end
|
14
|
-
|
15
|
-
include Console1984::FrozenMethods
|
16
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Prevents adding new methods to classes.
|
2
|
-
#
|
3
|
-
# This prevents manipulating certain Console1984 classes
|
4
|
-
# during a console session.
|
5
|
-
module Console1984::FrozenMethods
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def method_added(method_name)
|
10
|
-
raise Console1984::Errors::ForbiddenClassManipulation, "Can't override #{name}##{method_name}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def singleton_method_added(method_name)
|
14
|
-
raise Console1984::Errors::ForbiddenClassManipulation, "Can't override #{name}.#{method_name}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Console1984
|
2
|
-
# Prevents accessing trail model tables when executing console commands.
|
3
|
-
module ProtectedAuditableTables
|
4
|
-
%i[ execute exec_query exec_insert exec_delete exec_update exec_insert_all ].each do |method|
|
5
|
-
define_method method do |*args|
|
6
|
-
sql = args.first
|
7
|
-
if Console1984.supervisor.executing_user_command? && sql =~ auditable_tables_regexp
|
8
|
-
raise Console1984::Errors::ForbiddenCommand, "#{sql}"
|
9
|
-
else
|
10
|
-
super(*args)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
AUDITABLE_MODELS = [ Console1984::User, Console1984::Session, Console1984::Command, Console1984::SensitiveAccess ]
|
17
|
-
|
18
|
-
def auditable_tables_regexp
|
19
|
-
@auditable_tables_regexp ||= Regexp.new("#{auditable_tables.join("|")}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def auditable_tables
|
23
|
-
# TODO: Not using Console1984::Base.descendants during development to make this work without eager loading
|
24
|
-
@auditable_tables ||= AUDITABLE_MODELS.collect(&:table_name)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
include Console1984::FrozenMethods
|
29
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Console1984::ProtectedContext
|
2
|
-
# This method is invoked for showing returned objects in the console
|
3
|
-
# Overridden to make sure their evaluation is supervised.
|
4
|
-
def inspect_last_value
|
5
|
-
Console1984.supervisor.execute do
|
6
|
-
super
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
#
|
11
|
-
def evaluate(line, line_no, exception: nil)
|
12
|
-
Console1984.supervisor.execute_supervised(Array(line)) do
|
13
|
-
super
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
include Console1984::FrozenMethods
|
18
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Console1984::Supervisor::Accesses
|
2
|
-
include Console1984::Messages
|
3
|
-
|
4
|
-
PROTECTED_ACCESS = Protected.new
|
5
|
-
UNPROTECTED_ACCESS = Unprotected.new
|
6
|
-
|
7
|
-
def enable_access_to_encrypted_content(silent: false)
|
8
|
-
run_system_command do
|
9
|
-
show_warning Console1984.enter_unprotected_encryption_mode_warning if !silent && protected_mode?
|
10
|
-
justification = ask_for_value "\nBefore you can access personal information, you need to ask for and get explicit consent from the user(s). #{current_username}, where can we find this consent (a URL would be great)?"
|
11
|
-
session_logger.start_sensitive_access justification
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
ensure
|
15
|
-
@access = UNPROTECTED_ACCESS
|
16
|
-
nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def disable_access_to_encrypted_content(silent: false)
|
20
|
-
run_system_command do
|
21
|
-
show_warning Console1984.enter_protected_mode_warning if !silent && unprotected_mode?
|
22
|
-
session_logger.end_sensitive_access
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
ensure
|
26
|
-
@access = PROTECTED_ACCESS
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def with_encryption_mode(&block)
|
31
|
-
@access.execute(&block)
|
32
|
-
end
|
33
|
-
|
34
|
-
def unprotected_mode?
|
35
|
-
@access.is_a?(Unprotected)
|
36
|
-
end
|
37
|
-
|
38
|
-
def protected_mode?
|
39
|
-
!unprotected_mode?
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Console1984::Supervisor::Executor
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
def execute_supervised(commands, &block)
|
5
|
-
run_system_command { session_logger.before_executing commands }
|
6
|
-
execute(&block)
|
7
|
-
rescue Console1984::Errors::ForbiddenCommand, Console1984::Errors::ForbiddenClassManipulation
|
8
|
-
puts "Forbidden command attempted: #{commands.join("\n")}"
|
9
|
-
run_system_command { session_logger.suspicious_commands_attempted commands }
|
10
|
-
nil
|
11
|
-
ensure
|
12
|
-
run_system_command { session_logger.after_executing commands }
|
13
|
-
end
|
14
|
-
|
15
|
-
def execute(&block)
|
16
|
-
run_user_command do
|
17
|
-
with_encryption_mode(&block)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def executing_user_command?
|
22
|
-
@executing_user_command
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
def run_user_command(&block)
|
27
|
-
run_command true, &block
|
28
|
-
end
|
29
|
-
|
30
|
-
def run_system_command(&block)
|
31
|
-
run_command false, &block
|
32
|
-
end
|
33
|
-
|
34
|
-
def run_command(run_by_user, &block)
|
35
|
-
original_value = @executing_user_command
|
36
|
-
@executing_user_command = run_by_user
|
37
|
-
block.call
|
38
|
-
ensure
|
39
|
-
@executing_user_command = original_value
|
40
|
-
end
|
41
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Console1984::Supervisor::Protector
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
private
|
5
|
-
def extend_protected_systems
|
6
|
-
extend_irb
|
7
|
-
extend_active_record
|
8
|
-
extend_socket_classes
|
9
|
-
end
|
10
|
-
|
11
|
-
def extend_irb
|
12
|
-
IRB::Context.prepend(Console1984::ProtectedContext)
|
13
|
-
Rails::ConsoleMethods.include(Console1984::Commands)
|
14
|
-
end
|
15
|
-
|
16
|
-
ACTIVE_RECORD_CONNECTION_ADAPTERS = %w[ActiveRecord::ConnectionAdapters::Mysql2Adapter ActiveRecord::ConnectionAdapters::PostgreSQLAdapter ActiveRecord::ConnectionAdapters::SQLite3Adapter]
|
17
|
-
|
18
|
-
def extend_active_record
|
19
|
-
ACTIVE_RECORD_CONNECTION_ADAPTERS.each do |class_string|
|
20
|
-
if Object.const_defined?(class_string)
|
21
|
-
klass = class_string.constantize
|
22
|
-
klass.prepend(Console1984::ProtectedAuditableTables)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def extend_socket_classes
|
28
|
-
socket_classes = [TCPSocket, OpenSSL::SSL::SSLSocket]
|
29
|
-
if defined?(Redis::Connection)
|
30
|
-
socket_classes.push(*[Redis::Connection::TCPSocket, Redis::Connection::SSLSocket])
|
31
|
-
end
|
32
|
-
|
33
|
-
socket_classes.compact.each do |socket_klass|
|
34
|
-
socket_klass.prepend Console1984::ProtectedTcpSocket
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|