web-console-compat 3.5.1

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.markdown +110 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.markdown +5 -0
  5. data/Rakefile +27 -0
  6. data/lib/web-console-compat.rb +1 -0
  7. data/lib/web-console.rb +1 -0
  8. data/lib/web_console.rb +28 -0
  9. data/lib/web_console/context.rb +43 -0
  10. data/lib/web_console/errors.rb +7 -0
  11. data/lib/web_console/evaluator.rb +33 -0
  12. data/lib/web_console/exception_mapper.rb +33 -0
  13. data/lib/web_console/extensions.rb +44 -0
  14. data/lib/web_console/integration.rb +31 -0
  15. data/lib/web_console/integration/cruby.rb +23 -0
  16. data/lib/web_console/integration/rubinius.rb +39 -0
  17. data/lib/web_console/locales/en.yml +15 -0
  18. data/lib/web_console/middleware.rb +140 -0
  19. data/lib/web_console/railtie.rb +71 -0
  20. data/lib/web_console/request.rb +50 -0
  21. data/lib/web_console/response.rb +23 -0
  22. data/lib/web_console/session.rb +76 -0
  23. data/lib/web_console/tasks/extensions.rake +60 -0
  24. data/lib/web_console/tasks/templates.rake +54 -0
  25. data/lib/web_console/template.rb +23 -0
  26. data/lib/web_console/templates/_inner_console_markup.html.erb +8 -0
  27. data/lib/web_console/templates/_markup.html.erb +5 -0
  28. data/lib/web_console/templates/_prompt_box_markup.html.erb +2 -0
  29. data/lib/web_console/templates/console.js.erb +922 -0
  30. data/lib/web_console/templates/error_page.js.erb +70 -0
  31. data/lib/web_console/templates/index.html.erb +8 -0
  32. data/lib/web_console/templates/layouts/inlined_string.erb +1 -0
  33. data/lib/web_console/templates/layouts/javascript.erb +5 -0
  34. data/lib/web_console/templates/main.js.erb +1 -0
  35. data/lib/web_console/templates/style.css.erb +33 -0
  36. data/lib/web_console/testing/erb_precompiler.rb +25 -0
  37. data/lib/web_console/testing/fake_middleware.rb +39 -0
  38. data/lib/web_console/testing/helper.rb +9 -0
  39. data/lib/web_console/version.rb +3 -0
  40. data/lib/web_console/view.rb +50 -0
  41. data/lib/web_console/whiny_request.rb +31 -0
  42. data/lib/web_console/whitelist.rb +44 -0
  43. metadata +147 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7659e792ff45ac1b3fab5f870fa8a6f40365d6be
4
+ data.tar.gz: fff5836e9b6e8ca3ce19be2dd0d4d18ed44d8f52
5
+ SHA512:
6
+ metadata.gz: f9300eb91aec7e36c9882579027bd6a598c6ced7434ef87aa586aa59579a10291bc18dd63114ca4aa1357bb6e79db647ec01ca7b20470b034a008fdb725a22de
7
+ data.tar.gz: d33b269c3d79e109002b45c704176bb7dd59c20f72db0ccc25517bbb912f121f3a19f977d367bd8d6639989c01a92954a681eab7783ffae84dcb558fe408610f
@@ -0,0 +1,110 @@
1
+ # CHANGELOG
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 3.5.1
6
+
7
+ * [#239](https://github.com/rails/web-console/pull/239) Fix the ActionDispatch::DebugExceptions integration ([@gsamokovarov])
8
+
9
+ ## 3.5.0
10
+
11
+ * [#237](https://github.com/rails/web-console/pull/237) Bindex integration for JRuby 9k support ([@gsamokovarov])
12
+ * [#236](https://github.com/rails/web-console/pull/236) Remove unused Active Support lazy load hook ([@betesh])
13
+ * [#230](https://github.com/rails/web-console/pull/230) Handle invalid remote addresses ([@akirakoyasu])
14
+
15
+ ## 3.4.0
16
+
17
+ * [#205](https://github.com/rails/web-console/pull/205) Introduce autocompletion ([@sh19910711])
18
+
19
+ ## 3.3.1
20
+
21
+ Drop support for Rails `4.2.0`.
22
+
23
+ ## 3.3.0
24
+
25
+ * [#203](https://github.com/rails/web-console/pull/203) Map bindings to traces based on the trace __FILE__ and __LINE__ ([@gsamokovarov])
26
+
27
+ ## 3.2.1
28
+
29
+ * [#202](https://github.com/rails/web-console/pull/202) Use first binding when there is no application binding ([@sh19910711])
30
+
31
+ ## 3.2.0
32
+
33
+ * [#198](https://github.com/rails/web-console/pull/198) Pick the first application trace binding on errors ([@sh19910711])
34
+ * [#189](https://github.com/rails/web-console/pull/189) Silence ActionView rendering information ([@gsamokovarov])
35
+
36
+ ## 3.1.1
37
+
38
+ * [#185](https://github.com/rails/web-console/pull/185) Fix `rails console` startup ([@gsamokovarov])
39
+
40
+ ## 3.1.0
41
+
42
+ * [#182](https://github.com/rails/web-console/pull/182) Let `#console` live in `Kernel` ([@schneems])
43
+ * [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@gsamokovarov])
44
+ * [#180](https://github.com/rails/web-console/pull/180) Autoload Web Console constants for faster Rails boot time ([@herminiotorres])
45
+
46
+ ## 3.0.0
47
+
48
+ * [#173](https://github.com/rails/web-console/pull/173) Revert "Change config.development_only default until 4.2.4 is released" ([@gsamokovarov])
49
+ * [#171](https://github.com/rails/web-console/pull/171) Fixed blocked IP logging ([@gsamokovarov])
50
+ * [#162](https://github.com/rails/web-console/pull/162) Render the console inside the body tag ([@gsamokovarov])
51
+ * [#165](https://github.com/rails/web-console/pull/165) Revamped integrations for CRuby and Rubinius ([@gsamokovarov])
52
+
53
+ ## 2.3.0
54
+
55
+ This is mainly a Rails 5 compatibility release. If you have the chance, please
56
+ go to 3.1.0 instead.
57
+
58
+ * [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors (@schneems)
59
+ * [#150](https://github.com/rails/web-console/pull/150) Revert #150. (@gsamokovarov)
60
+
61
+ ## 2.2.1
62
+
63
+ * [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released ([@gsamokovarov])
64
+
65
+ ## 2.2.0
66
+
67
+ * [#140](https://github.com/rails/web-console/pull/140) Add the ability to close the console on each page ([@sh19910711])
68
+ * [#135](https://github.com/rails/web-console/pull/135) Run the console only in development mode and raise warning in tests ([@frenesim])
69
+ * [#134](https://github.com/rails/web-conscle/pull/134) Force development only web console by default ([@gsamokovarov])
70
+ * [#123](https://github.com/rails/web-console/pull/123) Replace deprecated `alias_method_chain` with `alias_method` ([@jonatack])
71
+
72
+ ## 2.1.3
73
+
74
+ * Fix remote code execution vulnerability in Web Console. CVE-2015-3224.
75
+
76
+ ## 2.1.2
77
+
78
+ * [#115](https://github.com/rails/web-console/pull/115) Show proper binding when raising an error in a template ([@gsamokovarov])
79
+ * [#114](https://github.com/rails/web-console/pull/114) Fix templates non rendering, because of missing template suffix ([@gsamokovarov])
80
+
81
+ ## 2.1.1
82
+
83
+ * [#112](https://github.com/rails/web-console/pull/112) Always allow application/x-www-form-urlencoded content type ([@gsamokovarov])
84
+
85
+ ## 2.1.0
86
+
87
+ * [#109](https://github.com/rails/web-console/pull/109) Revamp unavailable session response message ([@gsamokovarov])
88
+ * [#107](https://github.com/rails/web-console/pull/107) Fix pasting regression for all browsers ([@parterburn])
89
+ * [#105](https://github.com/rails/web-console/pull/105) Lock scroll bottom on console window resize ([@noahpatterson])
90
+ * [#104](https://github.com/rails/web-console/pull/104) Always whitelist localhost and inform users why no console is displayed ([@gsamokovarov])
91
+ * [#100](https://github.com/rails/web-console/pull/100) Accept text/plain as acceptable content type for Puma ([@gsamokovarov])
92
+ * [#98](https://github.com/rails/web-console/pull/98) Add arbitrary big z-index to the console ([@bglbruno])
93
+ * [#88](https://github.com/rails/web-console/pull/88) Spelling fixes ([@jeffnv])
94
+ * [#86](https://github.com/rails/web-console/pull/86) Disable autofocus when initializing the console ([@ryandao])
95
+ * [#84](https://github.com/rails/web-console/pull/84) Allow Rails 5 as dependency in gemspec ([@jonatack])
96
+ * [#69](https://github.com/rails/web-console/pull/69) Introduce middleware for request dispatch and console rendering ([@gsamokovarov])
97
+
98
+ [@jonatack]: https://github.com/jonatack
99
+ [@ryandao]: https://github.com/ryandao
100
+ [@jeffnv]: https://github.com/jeffnv
101
+ [@gsamokovarov]: https://github.com/gsamokovarov
102
+ [@bglbruno]: https://github.com/bglbruno
103
+ [@noahpatterson]: https://github.com/noahpatterson
104
+ [@parterburn]: https://github.com/parterburn
105
+ [@sh19910711]: https://github.com/sh19910711
106
+ [@frenesim]: https://github.com/frenesim
107
+ [@herminiotorres]: https://github.com/herminiotorres
108
+ [@schneems]: https://github.com/schneems
109
+ [@betesh]: https://github.com/betesh
110
+ [@akirakoyasu]: https://github.com/akirakoyasu
@@ -0,0 +1,20 @@
1
+ Copyright 2014-2016 Charlie Somerville, Genadi Samokovarov, Guillermo Iguaran and Ryan Dao
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Web Console Compat
2
+
3
+ A fork of [Web Console] latest features for Rails 4.2 projects.
4
+
5
+ [Web Console]: https://github.com/rails/web-console
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'socket'
8
+ require 'rake/testtask'
9
+ require 'tmpdir'
10
+ require 'securerandom'
11
+ require 'json'
12
+ require 'web_console/testing/erb_precompiler'
13
+
14
+ EXPANDED_CWD = File.expand_path(File.dirname(__FILE__))
15
+
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.libs << 'lib'
18
+ t.libs << 'test'
19
+ t.pattern = 'test/**/*_test.rb'
20
+ t.verbose = false
21
+ end
22
+
23
+ Dir['lib/web_console/tasks/**/*.rake'].each { |task| load task }
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ task default: :test
@@ -0,0 +1 @@
1
+ require 'web_console'
@@ -0,0 +1 @@
1
+ require 'web_console'
@@ -0,0 +1,28 @@
1
+ require 'active_support/dependencies/autoload'
2
+ require 'active_support/logger'
3
+
4
+ module WebConsole
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :View
8
+ autoload :Evaluator
9
+ autoload :ExceptionMapper
10
+ autoload :Session
11
+ autoload :Response
12
+ autoload :Request
13
+ autoload :WhinyRequest
14
+ autoload :Whitelist
15
+ autoload :Template
16
+ autoload :Middleware
17
+ autoload :Context
18
+
19
+ autoload_at 'web_console/errors' do
20
+ autoload :Error
21
+ autoload :DoubleRenderError
22
+ end
23
+
24
+ mattr_accessor :logger
25
+ @@logger = ActiveSupport::Logger.new($stderr)
26
+ end
27
+
28
+ require 'web_console/railtie'
@@ -0,0 +1,43 @@
1
+ module WebConsole
2
+ # A context lets you get object names related to the current session binding.
3
+ class Context
4
+ def initialize(binding)
5
+ @binding = binding
6
+ end
7
+
8
+ # Extracts entire objects which can be called by the current session unless
9
+ # the inputs is present.
10
+ #
11
+ # Otherwise, it extracts methods and constants of the object specified by
12
+ # the input.
13
+ def extract(input = nil)
14
+ input.present? ? local(input) : global
15
+ end
16
+
17
+ private
18
+
19
+ GLOBAL_OBJECTS = [
20
+ 'instance_variables',
21
+ 'local_variables',
22
+ 'methods',
23
+ 'class_variables',
24
+ 'Object.constants',
25
+ 'global_variables'
26
+ ]
27
+
28
+ def global
29
+ GLOBAL_OBJECTS.map { |cmd| eval(cmd) }
30
+ end
31
+
32
+ def local(input)
33
+ [
34
+ eval("#{input}.methods").map { |m| "#{input}.#{m}" },
35
+ eval("#{input}.constants").map { |c| "#{input}::#{c}" },
36
+ ]
37
+ end
38
+
39
+ def eval(cmd)
40
+ @binding.eval(cmd) rescue []
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module WebConsole
2
+ # The base class for every Web Console related error.
3
+ Error = Class.new(StandardError)
4
+
5
+ # Raised when there is an attempt to render a console more than once.
6
+ DoubleRenderError = Class.new(Error)
7
+ end
@@ -0,0 +1,33 @@
1
+ module WebConsole
2
+ # Simple Ruby code evaluator.
3
+ #
4
+ # This class wraps a +Binding+ object and evaluates code inside of it. The
5
+ # difference of a regular +Binding+ eval is that +Evaluator+ will always
6
+ # return a string and will format exception output.
7
+ class Evaluator
8
+ # Cleanses exceptions raised inside #eval.
9
+ cattr_reader :cleaner
10
+ @@cleaner = ActiveSupport::BacktraceCleaner.new
11
+ @@cleaner.add_silencer { |line| line.start_with?(File.expand_path('..', __FILE__)) }
12
+
13
+ def initialize(binding = TOPLEVEL_BINDING)
14
+ @binding = binding
15
+ end
16
+
17
+ def eval(input)
18
+ "=> #{@binding.eval(input).inspect}\n"
19
+ rescue Exception => exc
20
+ format_exception(exc)
21
+ end
22
+
23
+ private
24
+
25
+ def format_exception(exc)
26
+ backtrace = cleaner.clean(Array(exc.backtrace) - caller)
27
+
28
+ format = "#{exc.class.name}: #{exc}\n"
29
+ format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join
30
+ format
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module WebConsole
2
+ class ExceptionMapper
3
+ def initialize(exception)
4
+ @backtrace = exception.backtrace
5
+ @bindings = exception.bindings
6
+ end
7
+
8
+ def first
9
+ guess_the_first_application_binding || @bindings.first
10
+ end
11
+
12
+ def [](index)
13
+ guess_binding_for_index(index) || @bindings[index]
14
+ end
15
+
16
+ private
17
+
18
+ def guess_binding_for_index(index)
19
+ file, line = @backtrace[index].to_s.split(':')
20
+ line = line.to_i
21
+
22
+ @bindings.find do |binding|
23
+ binding.eval('__FILE__') == file && binding.eval('__LINE__') == line
24
+ end
25
+ end
26
+
27
+ def guess_the_first_application_binding
28
+ @bindings.find do |binding|
29
+ binding.eval('__FILE__').to_s.start_with?(Rails.root.to_s)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ module Kernel
2
+ module_function
3
+
4
+ # Instructs Web Console to render a console in the specified binding.
5
+ #
6
+ # If +binding+ isn't explicitly given it will default to the binding of the
7
+ # previous frame. E.g. the one that invoked +console+.
8
+ #
9
+ # Raises DoubleRenderError if a double +console+ invocation per request is
10
+ # detected.
11
+ def console(binding = WebConsole.caller_bindings.first)
12
+ raise WebConsole::DoubleRenderError if Thread.current[:__web_console_binding]
13
+
14
+ Thread.current[:__web_console_binding] = binding
15
+
16
+ # Make sure nothing is rendered from the view helper. Otherwise
17
+ # you're gonna see unexpected #<Binding:0x007fee4302b078> in the
18
+ # templates.
19
+ nil
20
+ end
21
+ end
22
+
23
+ module ActionDispatch
24
+ class DebugExceptions
25
+ def render_exception_with_web_console(env, exception)
26
+ render_exception_without_web_console(env, exception).tap do
27
+ error = ExceptionWrapper.new(env, exception).exception
28
+
29
+ # Get the original exception if ExceptionWrapper decides to follow it.
30
+ Thread.current[:__web_console_exception] = error
31
+
32
+ # ActionView::Template::Error bypass ExceptionWrapper original
33
+ # exception following. The backtrace in the view is generated from
34
+ # reaching out to original_exception in the view.
35
+ if error.is_a?(ActionView::Template::Error)
36
+ Thread.current[:__web_console_exception] = error.original_exception
37
+ end
38
+ end
39
+ end
40
+
41
+ alias_method :render_exception_without_web_console, :render_exception
42
+ alias_method :render_exception, :render_exception_with_web_console
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ module WebConsole
2
+ # Returns the Ruby bindings of Kernel#callers locations.
3
+ #
4
+ # The list of bindings here doesn't map 1 to 1 with Kernel#callers, as we
5
+ # can't build Ruby bindings for C functions or the equivalent native
6
+ # implementations in JRuby and Rubinius.
7
+ #
8
+ # This method needs to be overridden by every integration.
9
+ def self.caller_bindings
10
+ raise NotImplementedError
11
+ end
12
+ end
13
+
14
+ class Exception
15
+ # Returns an array of the exception backtrace locations bindings.
16
+ #
17
+ # The list won't map to the traces in #backtrace 1 to 1, because we can't
18
+ # build bindings for every trace (C functions, for example).
19
+ #
20
+ # Every integration should the instance variable.
21
+ def bindings
22
+ (defined?(@bindings) && @bindings) || []
23
+ end
24
+ end
25
+
26
+ case RUBY_ENGINE
27
+ when 'rbx'
28
+ require 'web_console/integration/rubinius'
29
+ when 'ruby'
30
+ require 'web_console/integration/cruby'
31
+ end
@@ -0,0 +1,23 @@
1
+ require 'debug_inspector'
2
+
3
+ def WebConsole.caller_bindings
4
+ bindings = RubyVM::DebugInspector.open do |context|
5
+ context.backtrace_locations.each_index.map { |i| context.frame_binding(i) }
6
+ end
7
+
8
+ # For C functions, we can't extract a binding. In this case,
9
+ # DebugInspector#frame_binding would have returned us nil. That's why we need
10
+ # to compact the bindings.
11
+ #
12
+ # Dropping two bindings, removes the current Ruby one in this exact method,
13
+ # and the one in the caller method. The caller method binding can be obtained
14
+ # by Kernel#binding, if needed.
15
+ bindings.compact.drop(2)
16
+ end
17
+
18
+ TracePoint.trace(:raise) do |context|
19
+ exc = context.raised_exception
20
+ if exc.bindings.empty?
21
+ exc.instance_variable_set(:@bindings, WebConsole.caller_bindings)
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ def WebConsole.caller_bindings
2
+ locations = ::Rubinius::VM.backtrace(1, true)
3
+
4
+ # Kernel.raise, is implemented in Ruby for Rubinius. We don't wanna have
5
+ # the frame for it to align with the CRuby and JRuby implementations.
6
+ #
7
+ # For internal methods location variables can be nil. We can't create a
8
+ # bindings for them.
9
+ locations.reject! do |location|
10
+ location.file.start_with?('kernel/delta/kernel.rb') || location.variables.nil?
11
+ end
12
+
13
+ bindings = locations.map do |location|
14
+ Binding.setup(
15
+ location.variables,
16
+ location.variables.method,
17
+ location.constant_scope,
18
+ location.variables.self,
19
+ location
20
+ )
21
+ end
22
+
23
+ # Drop the binding of the direct caller. That one can be created by
24
+ # Kernel#binding.
25
+ bindings.drop(1)
26
+ end
27
+
28
+ ::Rubinius.singleton_class.class_eval do
29
+ def raise_exception_with_current_bindings(exc)
30
+ if exc.bindings.empty?
31
+ exc.instance_variable_set(:@bindings, WebConsole.caller_bindings)
32
+ end
33
+
34
+ raise_exception_without_current_bindings(exc)
35
+ end
36
+
37
+ alias_method :raise_exception_without_current_bindings, :raise_exception
38
+ alias_method :raise_exception, :raise_exception_with_current_bindings
39
+ end