sqreen 1.14.0.beta3 → 1.14.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1a88f697fb1155fa5e354c753604e97c9446944d2c8b7c75ed8aebbb586845a
4
- data.tar.gz: c7440ae2799d091d33a75c5b29c8d583a041335ab5b0597820388349368bf0a2
3
+ metadata.gz: f6b572a1d9fe1440b268e4edcdcaab29a177edb3d7d6f915b100d57f77219ad5
4
+ data.tar.gz: b05840f3d4cbc358d089b50299ccfdc7da0947a52f2603e34d572a97acb1c946
5
5
  SHA512:
6
- metadata.gz: 64b3110988d5e5360640fb189b947320f58eb7a075cc70d39e37abc8df2802444063dc573755a1a50b47d3c9952ca4ccdf9b2272f11d82fbf689fc8e5bd6a971
7
- data.tar.gz: 62d4e5e3f8b07b6d0aaa502decc9ff5a62fdbd1dd4a1709d37614bc70b776ddd31436587bb38200d101b9b5728e792993737d066092b3ae4a7df4c44d9b9ca33
6
+ metadata.gz: be7806a0578560be5926fa04bb3201440072237ce377f4aba73fe4a3b763b2bcf75d585fff195238e8acad6986ef1112635837d1d40d800ad4a6a5df002edb13
7
+ data.tar.gz: b5d2cf720663a12d7add7b1f5f3ccf23bea712403898b97e10c45e741a1883fd9025b605f3ed2d02fd08f172ef2948b86f15e3e4defc2df6c2f3140e76d1d8da
@@ -177,7 +177,8 @@ module Sqreen
177
177
 
178
178
  def do_run(client_ip)
179
179
  return nil unless matches_ip? client_ip
180
- e = Sqreen::AttackBlocked.new("Blocked client's IP (action: #{id}). No action is required")
180
+ e = Sqreen::AttackBlocked.new("Blocked client's IP #{client_ip} " \
181
+ "(action: #{id} covering range(s) #{ranges}). No action is required")
181
182
  { :status => :raise, :exception => e }
182
183
  end
183
184
 
@@ -203,7 +204,8 @@ module Sqreen
203
204
 
204
205
  def do_run(client_ip)
205
206
  return nil unless matches_ip? client_ip
206
- Sqreen.log.info "Will request redirect for client with IP #{client_ip} (action: #{id}). "
207
+ Sqreen.log.info "Will request redirect for client with IP #{client_ip} " \
208
+ "(action: #{id} covering range(s) #{ranges})."
207
209
  {
208
210
  :status => :skip,
209
211
  :new_return_value => [303, { 'Location' => @redirect_url }, ['']],
@@ -8,7 +8,11 @@ module Sqreen
8
8
  class Exception < ::StandardError
9
9
  def initialize(msg = nil, *args)
10
10
  super(msg, *args)
11
- Sqreen.log.error msg if msg
11
+ log_message msg if msg
12
+ end
13
+
14
+ def log_message(msg)
15
+ Sqreen.log.error(msg)
12
16
  end
13
17
  end
14
18
 
@@ -24,6 +28,9 @@ module Sqreen
24
28
  # Sqreen users when watching their logs. It should not raise any concern to
25
29
  # them.
26
30
  class AttackBlocked < Exception
31
+ def log_message(msg)
32
+ Sqreen.log.warn(msg)
33
+ end
27
34
  end
28
35
 
29
36
  class NotImplementedYet < Exception
@@ -519,6 +519,18 @@ module Sqreen
519
519
  Sqreen.log.warn "Failed ignoring AttackBlocked on NewRelic: #{e.inspect}"
520
520
  end
521
521
 
522
+ def worker_fork_detection
523
+ # only Puma currently supported
524
+ return unless defined?(Puma::Cluster) && Puma::Cluster.instance_methods.include?(:worker)
525
+ cur_worker_meth = Puma::Cluster.instance_method(:worker)
526
+ Puma::Cluster.class_eval do
527
+ define_method(:worker) do |*args|
528
+ Sqreen.on_forked_worker = true
529
+ cur_worker_meth.bind(self)[*args]
530
+ end
531
+ end
532
+ end
533
+
522
534
  private
523
535
 
524
536
  def split_ip_addresses(ip_addresses)
@@ -89,6 +89,7 @@ module Sqreen
89
89
  def on_start(&block)
90
90
  @calling_pid = Process.pid
91
91
  Init.startup do |app|
92
+ worker_fork_detection
92
93
  sentry_ignore_exceptions
93
94
  newrelic_ignore_errors
94
95
  hook_rack_request(app.class, &block)
@@ -16,6 +16,7 @@ module Sqreen
16
16
  end
17
17
 
18
18
  def on_start(&block)
19
+ worker_fork_detection
19
20
  sentry_ignore_exceptions
20
21
  newrelic_ignore_errors
21
22
  hook_app_build(Sinatra::Base)
@@ -34,9 +34,9 @@ module Sqreen
34
34
  @module = vendored ? Sqreen::MiniRacer : MiniRacer
35
35
  @source = source
36
36
  @recycle_runtime_every = GC_MINI_RACER
37
- @snapshot = @module::Snapshot.new(source)
38
37
  @runtimes = []
39
38
  @tl_key = "SQREEN_MINI_RACER_CONTEXT_#{object_id}".freeze
39
+ snapshot if Sqreen.on_forked_worker? # called to eagerly initialize snapshot
40
40
  unless @@ctx_defined
41
41
  self.class.define_sqreen_context(@module)
42
42
  @@ctx_defined = true
@@ -52,7 +52,7 @@ module Sqreen
52
52
  dead_runtime = true
53
53
  end
54
54
  if dead_runtime
55
- new_runtime = SqreenContext.new(:snapshot => @snapshot)
55
+ new_runtime = SqreenContext.new(:snapshot => snapshot)
56
56
  push_runtime new_runtime
57
57
  mini_racer_context = {
58
58
  :c => 0,
@@ -72,6 +72,10 @@ module Sqreen
72
72
 
73
73
  private
74
74
 
75
+ def snapshot
76
+ @snapshot ||= @module::Snapshot.new(@source)
77
+ end
78
+
75
79
  def push_runtime(runtime)
76
80
  @runtimes.delete_if do |th, runt, _thid|
77
81
  del = th.nil? || !th.weakref_alive? || !th.alive?
@@ -60,6 +60,9 @@ module Sqreen
60
60
  attr_accessor :logged_in
61
61
  alias logged_in? logged_in
62
62
 
63
+ attr_accessor :on_forked_worker
64
+ alias on_forked_worker? on_forked_worker
65
+
63
66
  attr_reader :whitelisted_paths
64
67
  def update_whitelisted_paths(paths)
65
68
  @whitelisted_paths = paths.freeze
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
2
  # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
3
  module Sqreen
4
- VERSION = '1.14.0.beta3'.freeze
4
+ VERSION = '1.14.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqreen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0.beta3
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sqreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-06 00:00:00.000000000 Z
11
+ date: 2018-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sq_mini_racer
@@ -132,9 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ">"
135
+ - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 1.3.1
137
+ version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
140
  rubygems_version: 2.7.7