safer_rails_console 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.overcommit.yml +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +29 -0
- data/Appraisals +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/4.1.gemfile +7 -0
- data/gemfiles/4.2.gemfile +7 -0
- data/gemfiles/5.0.gemfile +7 -0
- data/gemfiles/5.1.gemfile +7 -0
- data/lib/safer_rails_console/colors.rb +17 -0
- data/lib/safer_rails_console/console.rb +21 -0
- data/lib/safer_rails_console/consoles/irb.rb +18 -0
- data/lib/safer_rails_console/patches/boot/sandbox_flag.rb +85 -0
- data/lib/safer_rails_console/patches/boot.rb +1 -0
- data/lib/safer_rails_console/patches/railtie/console.rb +7 -0
- data/lib/safer_rails_console/patches/railtie/sandbox.rb +32 -0
- data/lib/safer_rails_console/patches/railtie.rb +1 -0
- data/lib/safer_rails_console/patches/sandbox/auto_rollback.rb +24 -0
- data/lib/safer_rails_console/patches/sandbox.rb +1 -0
- data/lib/safer_rails_console/rails_version.rb +33 -0
- data/lib/safer_rails_console/railtie.rb +18 -0
- data/lib/safer_rails_console/version.rb +3 -0
- data/lib/safer_rails_console.rb +61 -0
- data/safer_rails_console.gemspec +43 -0
- metadata +224 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa6dfe54a684681be959fb96f6e22373e0776945
|
4
|
+
data.tar.gz: ac0286cc4a62e5d99e7b10b8332a75a76e6eabbb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b15d749d96006900aaeef79633164e7ddc340da7eeb6e4bf91fa208479e30064fc50595c8cf598e00c44030b468435840880941635efb3225b7bb4686ae934ed
|
7
|
+
data.tar.gz: 06b467a28054545c9b22426b6c5a1161651f87b87f9cc8caefd2c0bff40ba4eeca981489edda5c2a2133735b3f3ff1a506bc044ff179d99f013c4b97c26a92c3
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
|
4
|
+
bundler_args: --without test --jobs 3 --retry 3
|
5
|
+
before_install:
|
6
|
+
- gem install bundler
|
7
|
+
|
8
|
+
script:
|
9
|
+
- bundle exec rubocop
|
10
|
+
- bundle exec rspec
|
11
|
+
|
12
|
+
rvm:
|
13
|
+
- 2.2.7
|
14
|
+
- 2.3.4
|
15
|
+
- 2.4.1
|
16
|
+
|
17
|
+
gemfile:
|
18
|
+
- gemfiles/4.1.gemfile
|
19
|
+
- gemfiles/4.2.gemfile
|
20
|
+
- gemfiles/5.0.gemfile
|
21
|
+
- gemfiles/5.1.gemfile
|
22
|
+
|
23
|
+
matrix:
|
24
|
+
allow_failures:
|
25
|
+
- gemfile: gemfiles/4.1.gemfile
|
26
|
+
rvm: 2.4.1
|
27
|
+
- gemfile: gemfiles/5.1.gemfile
|
28
|
+
|
29
|
+
fast_finish: true
|
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Salsify, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# SaferRailsConsole [![Build Status](https://travis-ci.org/salsify/safer_rails_console.svg?branch=master)](https://travis-ci.org/salsify/safer_rails_console)
|
2
|
+
|
3
|
+
This gem makes Rails console sessions less dangerous in specified environments by warning, color-coding, auto-sandboxing, and allowing read-only external connections (disables job queueing, non-GET requests, etc.)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'safer_rails_console'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install safer_rails_console
|
20
|
+
|
21
|
+
Add the following line to the end of 'config/boot.rb' in your Rails application.
|
22
|
+
```ruby
|
23
|
+
require 'safer_rails_console/patches/boot'
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
The quickest way to demo this gem is to run `bundle exec rails console --sandbox`.
|
29
|
+
|
30
|
+
A way to explicitly enable or disable the sandbox is added to Rails console as a flag with the last install step.
|
31
|
+
```ruby
|
32
|
+
bundle exec rails console --help
|
33
|
+
|
34
|
+
-s, --[no-]sandbox Explicitly enable/disable sandbox mode.
|
35
|
+
-e, --environment=name Specifies the environment to run this console under (test/development/production).
|
36
|
+
Default: development
|
37
|
+
--debugger Enable the debugger.
|
38
|
+
```
|
39
|
+
|
40
|
+
This gem is autoloaded via Railties. The following defaults can be configured from 'environments' or 'application.rb':
|
41
|
+
```ruby
|
42
|
+
# Set what console is used. Currently, only 'irb' is supported. 'pry' and other consoles are to be added.
|
43
|
+
config.safer_rails_console.console = 'irb'
|
44
|
+
|
45
|
+
# Mapping environments to shortened names. `false` to disable.
|
46
|
+
config.safer_rails_console.environment_names = {
|
47
|
+
'development' => 'dev',
|
48
|
+
'staging' => 'staging',
|
49
|
+
'production' => 'prod'
|
50
|
+
}
|
51
|
+
# Mapping environments to console prompt colors. See colors.rb for colors. `false` to disable.
|
52
|
+
config.safer_rails_console.environment_prompt_colors = {
|
53
|
+
'development' => SaferRailsConsole::Colors::GREEN,
|
54
|
+
'staging' => SaferRailsConsole::Colors::YELLOW,
|
55
|
+
'production' => SaferRailsConsole::Colors::RED
|
56
|
+
}
|
57
|
+
|
58
|
+
# Set environments which should default to sandbox. `false` to disable.
|
59
|
+
config.safer_rails_console.sandbox_environments = %w{production}
|
60
|
+
|
61
|
+
# Set 'true' to have a prompt that asks the user if sandbox should be enabled/disabled if it was not explicitly specified (via. --[no-]sandbox)
|
62
|
+
config.safer_rails_console.sandbox_prompt = false
|
63
|
+
|
64
|
+
# Set environments that should have a warning. `false` to disable.
|
65
|
+
config.safer_rails_console.warn_environments = %w{production}
|
66
|
+
|
67
|
+
# Set warning message that should appear in the specified environments.
|
68
|
+
config.safer_rails_console.warn_text = "WARNING: YOU ARE USING RAILS CONSOLE IN PRODUCTION!\n" \
|
69
|
+
'Changing data can cause serious data loss. ' \
|
70
|
+
'Make sure you know what you\'re doing.'
|
71
|
+
```
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `wwtd` to simulate the entire build matrix (ruby version / rails version) or `appraisal` to test against each supported rails version with your active ruby version. Run `rubocop` to check for style.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/salsify/safer_rails_console. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "safer_rails_console"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module SaferRailsConsole
|
2
|
+
module Colors
|
3
|
+
NONE = 0
|
4
|
+
BLACK = 30
|
5
|
+
RED = 31
|
6
|
+
GREEN = 32
|
7
|
+
YELLOW = 33
|
8
|
+
BLUE = 34
|
9
|
+
PINK = 35
|
10
|
+
CYAN = 36
|
11
|
+
WHITE = 37
|
12
|
+
|
13
|
+
def color_text(text, color_code)
|
14
|
+
"\e[#{color_code}m#{text}\e[0m"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SaferRailsConsole
|
2
|
+
module Console
|
3
|
+
class << self
|
4
|
+
include SaferRailsConsole::Colors
|
5
|
+
|
6
|
+
def initialize_sandbox
|
7
|
+
require 'safer_rails_console/patches/sandbox'
|
8
|
+
end
|
9
|
+
|
10
|
+
def print_warning
|
11
|
+
puts color_text(SaferRailsConsole.config.warn_text, SaferRailsConsole.prompt_color) # rubocop:disable Rails/Output
|
12
|
+
end
|
13
|
+
|
14
|
+
def sandbox_prompt_user_input
|
15
|
+
puts "Defaulting the console into sandbox mode.\nType 'disable' to disable. Anything else will begin a sandboxed session:" # rubocop:disable Rails/Output
|
16
|
+
input = gets.strip
|
17
|
+
input != 'disable'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
include SaferRailsConsole::Colors
|
2
|
+
|
3
|
+
app_name = ::Rails.application.class.parent.to_s.downcase
|
4
|
+
env_name = SaferRailsConsole.environment_name
|
5
|
+
status = ::Rails.application.sandbox ? 'sandboxed' : 'unsandboxed'
|
6
|
+
color = SaferRailsConsole.prompt_color
|
7
|
+
|
8
|
+
prompt = "#{app_name}(#{env_name})(#{status}):%03n:%i"
|
9
|
+
|
10
|
+
IRB.conf[:PROMPT][:RAILS_ENV] = {
|
11
|
+
PROMPT_I: color_text("#{prompt}> ", color),
|
12
|
+
PROMPT_N: color_text("#{prompt}> ", color),
|
13
|
+
PROMPT_S: color_text("#{prompt}%l ", color),
|
14
|
+
PROMPT_C: color_text("#{prompt}* ", color),
|
15
|
+
RETURN: color_text('=> ', color).concat("%s\n")
|
16
|
+
}
|
17
|
+
|
18
|
+
IRB.conf[:PROMPT_MODE] = :RAILS_ENV
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'safer_rails_console/rails_version'
|
2
|
+
|
3
|
+
module SaferRailsConsole
|
4
|
+
module Patches
|
5
|
+
module Boot
|
6
|
+
module SandboxFlag
|
7
|
+
module Rails
|
8
|
+
module CommandsTasks4
|
9
|
+
def console
|
10
|
+
require_command!('console')
|
11
|
+
::Rails::Console.singleton_class.prepend(::SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::Console4)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Console4
|
17
|
+
def parse_arguments(arguments)
|
18
|
+
options = {}
|
19
|
+
|
20
|
+
OptionParser.new do |opt|
|
21
|
+
opt.banner = 'Usage: rails console [environment] [options]'
|
22
|
+
opt.on('-s', '--[no-]sandbox', 'Explicitly enable/disable sandbox mode.') { |v| options[:sandbox] = v }
|
23
|
+
opt.on('-e', '--environment=name', String,
|
24
|
+
'Specifies the environment to run this console under (test/development/production).',
|
25
|
+
'Default: development') { |v| options[:environment] = v.strip }
|
26
|
+
opt.on('--debugger', 'Enable the debugger.') { |v| options[:debugger] = v }
|
27
|
+
opt.parse!(arguments)
|
28
|
+
end
|
29
|
+
|
30
|
+
if arguments.first && arguments.first[0] != '-'
|
31
|
+
env = arguments.first
|
32
|
+
options[:environment] = if available_environments.include? env
|
33
|
+
env
|
34
|
+
else
|
35
|
+
%w(production development test).detect { |e| e =~ /^#{env}/ } || env
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module CommandsTasks50
|
44
|
+
def console
|
45
|
+
require_command!('console')
|
46
|
+
::Rails::Console.singleton_class.prepend(::SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::Console50)
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Console50
|
52
|
+
def parse_arguments(arguments)
|
53
|
+
options = {}
|
54
|
+
|
55
|
+
OptionParser.new do |opt|
|
56
|
+
opt.banner = 'Usage: rails console [environment] [options]'
|
57
|
+
opt.on('-s', '--[no-]sandbox', 'Explicitly enable/disable sandbox mode.') { |v| options[:sandbox] = v }
|
58
|
+
opt.on('-e', '--environment=name', String,
|
59
|
+
'Specifies the environment to run this console under (test/development/production).',
|
60
|
+
'Default: development') { |v| options[:environment] = v.strip }
|
61
|
+
opt.parse!(arguments)
|
62
|
+
end
|
63
|
+
|
64
|
+
set_options_env(arguments, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if SaferRailsConsole::RailsVersion.four_one? || SaferRailsConsole::RailsVersion.four_two?
|
74
|
+
require 'rails/commands/commands_tasks'
|
75
|
+
::Rails::CommandsTasks.prepend(SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::CommandsTasks4)
|
76
|
+
elsif SaferRailsConsole::RailsVersion.five_zero?
|
77
|
+
require 'rails/commands/commands_tasks'
|
78
|
+
::Rails::CommandsTasks.prepend(SaferRailsConsole::Patches::Boot::SandboxFlag::Rails::CommandsTasks50)
|
79
|
+
else
|
80
|
+
unless SaferRailsConsole::RailsVersion.supported?
|
81
|
+
raise "No boot/sandbox_flag patch for rails version '#{::Rails.version}' exists. "\
|
82
|
+
'Please disable safer_rails_console, use a supported version of rails, '\
|
83
|
+
"or remove \"require 'safer_rails_console/patches/boot'\" from your application's 'config/boot.rb'."
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(__dir__, 'boot', '*.rb')].each { |file| require file }
|
@@ -0,0 +1,7 @@
|
|
1
|
+
::Rails::Application.class_eval do
|
2
|
+
console do
|
3
|
+
gem = Gem::Specification.find_by_name('safer_rails_console') # rubocop:disable Rails/DynamicFindBy
|
4
|
+
gem_root = gem.gem_dir
|
5
|
+
ARGV.push '-r', File.join(gem_root, 'lib', 'safer_rails_console', 'consoles', "#{SaferRailsConsole.config.console}.rb")
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SaferRailsConsole
|
2
|
+
module Patches
|
3
|
+
module Sandbox
|
4
|
+
module Rails
|
5
|
+
module Console
|
6
|
+
def start(*args)
|
7
|
+
if SaferRailsConsole::RailsVersion.five_one? && SaferRailsConsole.sandbox_environment?
|
8
|
+
# TODO: Fix Rails 5.1 support
|
9
|
+
end
|
10
|
+
|
11
|
+
options = args.last
|
12
|
+
|
13
|
+
options[:sandbox] = SaferRailsConsole.sandbox_environment? if options[:sandbox].nil?
|
14
|
+
options[:sandbox] = SaferRailsConsole::Console.sandbox_prompt_user_input if SaferRailsConsole.sandbox_environment? && SaferRailsConsole.config.sandbox_prompt
|
15
|
+
|
16
|
+
SaferRailsConsole::Console.initialize_sandbox if options[:sandbox]
|
17
|
+
SaferRailsConsole::Console.print_warning if SaferRailsConsole.warn_environment?
|
18
|
+
|
19
|
+
super *args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if SaferRailsConsole::RailsVersion.supported?
|
28
|
+
::Rails::Console.singleton_class.prepend(SaferRailsConsole::Patches::Sandbox::Rails::Console)
|
29
|
+
else
|
30
|
+
raise "No sandbox patch for rails version '#{::Rails.version}' exists. "\
|
31
|
+
'Please disable safer_rails_console, use a supported version of rails, or disable SaferRailsConsole.config.sandbox_environments.'
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(__dir__, 'railtie', '*.rb')].each { |file| require file }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SaferRailsConsole
|
2
|
+
module Patches
|
3
|
+
module Sandbox
|
4
|
+
module AutoRollback
|
5
|
+
module ActiveRecord
|
6
|
+
module ConnectionAdapters
|
7
|
+
module AbstractAdapter
|
8
|
+
def log(sql, name = 'SQL', binds = [], statement_name = nil)
|
9
|
+
super(sql, name, binds, statement_name) { yield }
|
10
|
+
rescue => e
|
11
|
+
connection = ::ActiveRecord::Base.connection
|
12
|
+
connection.rollback_db_transaction
|
13
|
+
connection.begin_db_transaction
|
14
|
+
raise e
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::AbstractAdapter)
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(__dir__, 'sandbox', '*.rb')].each { |file| require file }
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module SaferRailsConsole
|
4
|
+
module RailsVersion
|
5
|
+
RAILS_VERSION = Gem::Version.new(::Rails.version)
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def supported?
|
9
|
+
four_one? || four_two? || five_zero? || five_one?
|
10
|
+
end
|
11
|
+
|
12
|
+
def four_one?
|
13
|
+
@is_four_one = Gem::Requirement.new('~> 4.1.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_four_one.nil?
|
14
|
+
@is_four_one
|
15
|
+
end
|
16
|
+
|
17
|
+
def four_two?
|
18
|
+
@is_four_two = Gem::Requirement.new('~> 4.2.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_four_two.nil?
|
19
|
+
@is_four_two
|
20
|
+
end
|
21
|
+
|
22
|
+
def five_zero?
|
23
|
+
@is_five_zero = Gem::Requirement.new('~> 5.0.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_five_zero.nil?
|
24
|
+
@is_five_zero
|
25
|
+
end
|
26
|
+
|
27
|
+
def five_one?
|
28
|
+
@is_five_one = Gem::Requirement.new('~> 5.1.0').satisfied_by?(SaferRailsConsole::RailsVersion::RAILS_VERSION) if @is_five_one.nil?
|
29
|
+
@is_five_one
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'safer_rails_console'
|
3
|
+
|
4
|
+
module SaferRailsConsole
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
railtie_name :safer_rails_console
|
7
|
+
|
8
|
+
config.safer_rails_console = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
initializer 'safer_rails_console.configure' do |app|
|
11
|
+
SaferRailsConsole.config.set(app.config.safer_rails_console)
|
12
|
+
end
|
13
|
+
|
14
|
+
config.after_initialize do
|
15
|
+
require 'safer_rails_console/patches/railtie' if defined?(::Rails::Console)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'safer_rails_console/version'
|
2
|
+
require 'safer_rails_console/railtie'
|
3
|
+
require 'safer_rails_console/colors'
|
4
|
+
require 'safer_rails_console/rails_version'
|
5
|
+
require 'safer_rails_console/console'
|
6
|
+
|
7
|
+
module SaferRailsConsole
|
8
|
+
class << self
|
9
|
+
def environment_name
|
10
|
+
config.environment_names.key?(::Rails.env.downcase) ? config.environment_names[::Rails.env.downcase] : 'unknown env'
|
11
|
+
end
|
12
|
+
|
13
|
+
def prompt_color
|
14
|
+
config.environment_prompt_colors.key?(::Rails.env.downcase) ? config.environment_prompt_colors[::Rails.env.downcase] : SaferRailsConsole::Colors::NONE
|
15
|
+
end
|
16
|
+
|
17
|
+
def sandbox_environment?
|
18
|
+
config.sandbox_environments.include?(::Rails.env.downcase)
|
19
|
+
end
|
20
|
+
|
21
|
+
def warn_environment?
|
22
|
+
config.warn_environments.include?(::Rails.env.downcase)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config
|
26
|
+
@config ||= Configuration.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Configuration
|
31
|
+
include ActiveSupport::Configurable
|
32
|
+
|
33
|
+
CONFIG_DEFAULTS = {
|
34
|
+
console: 'irb',
|
35
|
+
environment_names: {
|
36
|
+
'development' => 'dev',
|
37
|
+
'staging' => 'staging',
|
38
|
+
'production' => 'prod'
|
39
|
+
},
|
40
|
+
environment_prompt_colors: {
|
41
|
+
'development' => SaferRailsConsole::Colors::GREEN,
|
42
|
+
'staging' => SaferRailsConsole::Colors::YELLOW,
|
43
|
+
'production' => SaferRailsConsole::Colors::RED
|
44
|
+
},
|
45
|
+
sandbox_environments: %w{production},
|
46
|
+
sandbox_prompt: false,
|
47
|
+
warn_environments: %w{production},
|
48
|
+
warn_text: "WARNING: YOU ARE USING RAILS CONSOLE IN PRODUCTION!\n" \
|
49
|
+
'Changing data can cause serious data loss. ' \
|
50
|
+
'Make sure you know what you\'re doing.'
|
51
|
+
}.freeze
|
52
|
+
|
53
|
+
CONFIG_DEFAULTS.each do |name, value|
|
54
|
+
config_accessor(name) { value }
|
55
|
+
end
|
56
|
+
|
57
|
+
def set(**new_config)
|
58
|
+
config.merge!(new_config.select { |k, _v| CONFIG_DEFAULTS.key?(k) })
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'safer_rails_console/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'safer_rails_console'
|
9
|
+
spec.version = SaferRailsConsole::VERSION
|
10
|
+
spec.authors = ['Salsify, Inc']
|
11
|
+
spec.email = ['engineering@salsify.com']
|
12
|
+
|
13
|
+
spec.summary = 'Make rails console less dangerous!'
|
14
|
+
spec.description = 'This gem makes Rails console sessions less dangerous in specified environments by warning, color-coding, auto-sandboxing, and allowing read-only external connections (disables job queueing, non-GET requests, etc.)'
|
15
|
+
spec.homepage = 'https://github.com/salsify/safer_rails_console'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
spec.add_development_dependency 'appraisal', '~> 2.2'
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
35
|
+
spec.add_development_dependency 'mixlib-shellout', '~> 2.2'
|
36
|
+
spec.add_development_dependency 'overcommit', '~> 0.39.0'
|
37
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
39
|
+
spec.add_development_dependency 'salsify_rubocop', '~> 0.48.0'
|
40
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.13'
|
41
|
+
spec.add_development_dependency 'wwtd', '~> 1.3'
|
42
|
+
spec.add_runtime_dependency 'rails', '>= 4.1', '< 5.2'
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safer_rails_console
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Salsify, Inc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mixlib-shellout
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: overcommit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.39.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.39.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '12.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: salsify_rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.48.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.48.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.13
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.13
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: wwtd
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.3'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.1'
|
146
|
+
- - "<"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '5.2'
|
149
|
+
type: :runtime
|
150
|
+
prerelease: false
|
151
|
+
version_requirements: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '4.1'
|
156
|
+
- - "<"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '5.2'
|
159
|
+
description: This gem makes Rails console sessions less dangerous in specified environments
|
160
|
+
by warning, color-coding, auto-sandboxing, and allowing read-only external connections
|
161
|
+
(disables job queueing, non-GET requests, etc.)
|
162
|
+
email:
|
163
|
+
- engineering@salsify.com
|
164
|
+
executables: []
|
165
|
+
extensions: []
|
166
|
+
extra_rdoc_files: []
|
167
|
+
files:
|
168
|
+
- ".gitignore"
|
169
|
+
- ".overcommit.yml"
|
170
|
+
- ".rspec"
|
171
|
+
- ".rubocop.yml"
|
172
|
+
- ".travis.yml"
|
173
|
+
- Appraisals
|
174
|
+
- Gemfile
|
175
|
+
- LICENSE.txt
|
176
|
+
- README.md
|
177
|
+
- Rakefile
|
178
|
+
- bin/console
|
179
|
+
- bin/setup
|
180
|
+
- gemfiles/4.1.gemfile
|
181
|
+
- gemfiles/4.2.gemfile
|
182
|
+
- gemfiles/5.0.gemfile
|
183
|
+
- gemfiles/5.1.gemfile
|
184
|
+
- lib/safer_rails_console.rb
|
185
|
+
- lib/safer_rails_console/colors.rb
|
186
|
+
- lib/safer_rails_console/console.rb
|
187
|
+
- lib/safer_rails_console/consoles/irb.rb
|
188
|
+
- lib/safer_rails_console/patches/boot.rb
|
189
|
+
- lib/safer_rails_console/patches/boot/sandbox_flag.rb
|
190
|
+
- lib/safer_rails_console/patches/railtie.rb
|
191
|
+
- lib/safer_rails_console/patches/railtie/console.rb
|
192
|
+
- lib/safer_rails_console/patches/railtie/sandbox.rb
|
193
|
+
- lib/safer_rails_console/patches/sandbox.rb
|
194
|
+
- lib/safer_rails_console/patches/sandbox/auto_rollback.rb
|
195
|
+
- lib/safer_rails_console/rails_version.rb
|
196
|
+
- lib/safer_rails_console/railtie.rb
|
197
|
+
- lib/safer_rails_console/version.rb
|
198
|
+
- safer_rails_console.gemspec
|
199
|
+
homepage: https://github.com/salsify/safer_rails_console
|
200
|
+
licenses:
|
201
|
+
- MIT
|
202
|
+
metadata:
|
203
|
+
allowed_push_host: https://rubygems.org
|
204
|
+
post_install_message:
|
205
|
+
rdoc_options: []
|
206
|
+
require_paths:
|
207
|
+
- lib
|
208
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: '0'
|
218
|
+
requirements: []
|
219
|
+
rubyforge_project:
|
220
|
+
rubygems_version: 2.6.12
|
221
|
+
signing_key:
|
222
|
+
specification_version: 4
|
223
|
+
summary: Make rails console less dangerous!
|
224
|
+
test_files: []
|