web-console 3.6.0 → 3.6.1

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: bb1461a9213387e0c8158f62623d63b0ecff23c0cc6ccd91433ab203eec3eb8b
4
- data.tar.gz: 45336b5c06bff19cd02d1b651d5917934434367d0efcb546ec55afd9b0b66804
3
+ metadata.gz: d439be9277cff602e612a47dd3186aaa0ab3800040f978d2ca68d3dd330b8379
4
+ data.tar.gz: bdf788f4b48c2a615235a180db5b5b3b9d3a8d0d20326c5ed4157875a04503c5
5
5
  SHA512:
6
- metadata.gz: 638a0796f7049de3544b8d342d72545d72c06a56e0ecc82dbc2974fd16b2e81ab91a56ff9615e61ef34bfded1dda8f29187b4792db3d2bd757fed7e27dcf5d27
7
- data.tar.gz: b52c4650487ec31ef5ba20ec4fdf180016f730ddffe2a8bf9909a32db39c362a4ae2ae60a59441fe1c0fc1a177933d4e09e634a5af3b4f51b23b4b51dfe13321
6
+ metadata.gz: 3ae6bec4c77114a1930b367211b2b093b3378e7618f59c27dfa88fb6824179e68c13d4d57a8bf54e92eb4587e7e77b0fe5b625d83623f57a55dbac2066c988d3
7
+ data.tar.gz: e9282ecc93234e6dc296d65583d8028b3274a87ac83d46e8d4c429f06b965e5ba0de39ea4fc1355be0c0a616a99ca97dcbaf7e5f2c27cbd490be24467ab01fdf
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 3.6.1
6
+
7
+ * [#252](https://github.com/rails/web-console/pull/252) Fix improper injection in Rack bodies like ActionDispatch::Response::RackBody ([@gsamokovarov])
8
+
5
9
  ## 3.6.0
6
10
 
7
11
  * [#254](https://github.com/rails/web-console/pull/254) Rescue ActionDispatch::RemoteIp::IpSpoofAttackError ([@wjordan])
@@ -10,7 +10,7 @@ module WebConsole
10
10
  autoload :Evaluator
11
11
  autoload :ExceptionMapper
12
12
  autoload :Session
13
- autoload :Response
13
+ autoload :Injector
14
14
  autoload :Request
15
15
  autoload :WhinyRequest
16
16
  autoload :Whitelist
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebConsole
4
+ # Injects content into a Rack body.
5
+ class Injector
6
+ def initialize(body)
7
+ @body = "".dup
8
+
9
+ body.each { |part| @body << part }
10
+ body.close if body.respond_to?(:close)
11
+ end
12
+
13
+ def inject(content)
14
+ if position = @body.rindex("</body>")
15
+ [ @body.insert(position, content) ]
16
+ else
17
+ [ @body << content ]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -30,16 +30,14 @@ module WebConsole
30
30
  status, headers, body = call_app(env)
31
31
 
32
32
  if (session = Session.from(Thread.current)) && acceptable_content_type?(headers)
33
- response = Response.new(body, status, headers)
34
- template = Template.new(env, session)
33
+ headers["X-Web-Console-Session-Id"] = session.id
34
+ headers["X-Web-Console-Mount-Point"] = mount_point
35
35
 
36
- response.headers["X-Web-Console-Session-Id"] = session.id
37
- response.headers["X-Web-Console-Mount-Point"] = mount_point
38
- response.write(template.render("index"))
39
- response.finish
40
- else
41
- [ status, headers, body ]
36
+ template = Template.new(env, session)
37
+ body = Injector.new(body).inject(template.render("index"))
42
38
  end
39
+
40
+ [ status, headers, body ]
43
41
  end
44
42
  rescue => e
45
43
  WebConsole.logger.error("\n#{e.class}: #{e}\n\tfrom #{e.backtrace.join("\n\tfrom ")}")
@@ -64,7 +62,7 @@ module WebConsole
64
62
  headers = { "Content-Type" => "application/json; charset = utf-8" }
65
63
  body = yield.to_json
66
64
 
67
- Rack::Response.new(body, status, headers).finish
65
+ [ status, headers, [ body ] ]
68
66
  end
69
67
 
70
68
  def json_response_with_session(id, request, opts = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebConsole
4
- VERSION = "3.6.0"
4
+ VERSION = "3.6.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Somerville
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-04-10 00:00:00.000000000 Z
14
+ date: 2018-04-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -90,11 +90,11 @@ files:
90
90
  - lib/web_console/evaluator.rb
91
91
  - lib/web_console/exception_mapper.rb
92
92
  - lib/web_console/extensions.rb
93
+ - lib/web_console/injector.rb
93
94
  - lib/web_console/locales/en.yml
94
95
  - lib/web_console/middleware.rb
95
96
  - lib/web_console/railtie.rb
96
97
  - lib/web_console/request.rb
97
- - lib/web_console/response.rb
98
98
  - lib/web_console/session.rb
99
99
  - lib/web_console/tasks/extensions.rake
100
100
  - lib/web_console/tasks/templates.rake
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WebConsole
4
- # A response object that writes content before the closing </body> tag, if
5
- # possible.
6
- #
7
- # The object quacks like Rack::Response.
8
- class Response < Struct.new(:body, :status, :headers)
9
- def write(content)
10
- raw_body = Array(body).first.to_s
11
-
12
- # We're done with the original body object, so make sure to close it to comply with the Rack SPEC
13
- body.close if body.respond_to?(:close)
14
-
15
- self.body =
16
- if position = raw_body.rindex("</body>")
17
- raw_body.dup.insert(position, content)
18
- else
19
- raw_body.dup << content
20
- end
21
- end
22
-
23
- def finish
24
- Rack::Response.new(body, status, headers).finish
25
- end
26
- end
27
- end