sqreen 1.17.0-java → 1.17.2.beta1-java

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.
@@ -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.17.0'.freeze
4
+ VERSION = '1.17.2.beta1'.freeze
5
5
  end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ require 'sqreen/log'
5
+ require 'sqreen/web_server/generic'
6
+ require 'sqreen/web_server/unicorn'
7
+ require 'sqreen/web_server/rainbows'
8
+ require 'sqreen/web_server/puma'
9
+ require 'sqreen/web_server/passenger'
10
+ require 'sqreen/web_server/thin'
11
+ require 'sqreen/web_server/webrick'
12
+
13
+ module Sqreen
14
+ module WebServer
15
+ module_function
16
+
17
+ def attach
18
+ extend(detect)
19
+
20
+ Sqreen.log.debug "[#{Process.pid}] #{detect.inspect}"
21
+
22
+ if forking? && preload_app? && master?
23
+ Sqreen.log.debug "[#{Process.pid}] master process #{Process.pid} delegating Sqreen worker boot to forked web worker processes"
24
+ Sqreen.log.debug('Sqreen detected a forking web server with preloading')
25
+ Sqreen.log.debug("master process #{Process.pid} delegating Sqreen worker boot to forked web worker processes")
26
+ after_fork { yield }
27
+ elsif forking? && !master? && !preload_app?
28
+ Sqreen.log.debug "[#{Process.pid}] Booting Sqreen worker in process #{Process.pid}"
29
+ Sqreen.log.debug('Sqreen detected a forked web worker without preloading')
30
+ Sqreen.log.debug("Booting Sqreen worker in process #{Process.pid}")
31
+ yield
32
+ elsif !forking?
33
+ Sqreen.log.debug "[#{Process.pid}] Booting Sqreen worker in process #{Process.pid}"
34
+ Sqreen.log.debug('Sqreen detected a single-process web server')
35
+ Sqreen.log.debug("Booting Sqreen worker in process #{Process.pid}")
36
+ yield
37
+ else
38
+ Sqreen.log.debug "[#{Process.pid}] NOOP"
39
+ end
40
+ end
41
+
42
+ def detect
43
+ [
44
+ Sqreen::WebServer::Puma,
45
+ Sqreen::WebServer::Rainbows,
46
+ Sqreen::WebServer::Unicorn,
47
+ Sqreen::WebServer::Passenger,
48
+ Sqreen::WebServer::Thin,
49
+ Sqreen::WebServer::WEBrick,
50
+ Sqreen::WebServer::Generic,
51
+ ].find(&:active?)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Generic
7
+ def self.active?
8
+ true
9
+ end
10
+
11
+ def forking?
12
+ false
13
+ end
14
+
15
+ def preload_app?
16
+ false
17
+ end
18
+
19
+ def before_fork(&block); end
20
+
21
+ def after_fork(&block); end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Passenger
7
+ def self.active?
8
+ Sqreen::Dependency.const_exist?('PhusionPassenger::App')
9
+ end
10
+
11
+ def forking?
12
+ ::PhusionPassenger::App.options['spawn_method'] == 'smart' # otherwise direct
13
+ end
14
+
15
+ def preload_app?
16
+ forking? # overarching spawn method behavior
17
+ end
18
+
19
+ def master?
20
+ preload_app? # overarching spawn method behavior
21
+ end
22
+
23
+ def before_fork(&block); end
24
+
25
+ def after_fork
26
+ after_fork = lambda do |forked|
27
+ yield if forked # forked == true in child
28
+ end
29
+ ::PhusionPassenger.on_event(:starting_worker_process, &after_fork)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Puma
7
+ def self.active?
8
+ Sqreen::Dependency.const_exist?('Puma::Runner') && ObjectSpace.each_object(::Puma::Runner).count > 0
9
+ end
10
+
11
+ def forking?
12
+ !cluster.nil?
13
+ end
14
+
15
+ def preload_app?
16
+ forking? && (cluster && cluster.preload? || false)
17
+ end
18
+
19
+ def master?
20
+ # HACK: expects outside calling timimg
21
+ # - with preloading, this is hit early in master and records its PID
22
+ # - without preloading but forking, the app will be loaded in the child, so recorded PID stays nil
23
+ # - without forking, master makes no sense, recorded PID stays nil
24
+ master! if preload_app?
25
+
26
+ Sqreen.log.debug "[#{Process.pid}] master? #{@master_pid == Process.pid}"
27
+
28
+ @master_pid == Process.pid
29
+ end
30
+
31
+ def before_fork
32
+ before_fork = lambda do |_ = nil| # 3.x sends an arg but <3.0 doesn't
33
+ yield
34
+ end
35
+ (configuration.options[:before_fork] || []) << before_fork
36
+ end
37
+
38
+ def after_fork
39
+ after_fork = lambda do |_|
40
+ yield
41
+ end
42
+ (configuration.options[:before_worker_boot] ||= []) << after_fork
43
+ end
44
+
45
+ private
46
+
47
+ def master!
48
+ @master_pid ||= Process.pid
49
+ end
50
+
51
+ def cluster
52
+ return unless ::Puma.const_defined?('Cluster')
53
+
54
+ ObjectSpace.each_object(::Puma::Cluster).first
55
+ end
56
+
57
+ def configuration
58
+ ObjectSpace.each_object(::Puma::Configuration).first
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Rainbows
7
+ include Sqreen::WebServer::Unicorn
8
+
9
+ def self.active?
10
+ Sqreen::Dependency.const_exist?('Rainbows::HttpServer') && ObjectSpace.each_object(::Rainbows::HttpServer).count > 0
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Thin
7
+ include Sqreen::WebServer::Generic
8
+
9
+ def self.active?
10
+ Sqreen::Dependency.const_exist?('Thin::Server') && ObjectSpace.each_object(::Thin::Server).count > 0
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module Unicorn
7
+ def self.active?
8
+ Sqreen::Dependency.const_exist?('Unicorn::SocketHelper') && ObjectSpace.each_object(::Unicorn::SocketHelper).count > 0
9
+ end
10
+
11
+ def forking?
12
+ true
13
+ end
14
+
15
+ def master?
16
+ !master.nil?
17
+ end
18
+
19
+ def preload_app?
20
+ ObjectSpace.each_object(::Unicorn::HttpServer).first.preload_app
21
+ end
22
+
23
+ def before_fork
24
+ before_fork = master.before_fork
25
+ before_fork_wrapper = lambda do |a, b|
26
+ before_fork.call(a, b).tap { yield }
27
+ end
28
+ master.before_fork = before_fork_wrapper
29
+ end
30
+
31
+ def after_fork
32
+ after_fork = master.after_fork
33
+ after_fork_wrapper = lambda do |a, b|
34
+ after_fork.call(a, b).tap { yield }
35
+ end
36
+ master.after_fork = after_fork_wrapper
37
+ end
38
+
39
+ private
40
+
41
+ def master
42
+ ObjectSpace.each_object(::Unicorn::HttpServer).select do |s|
43
+ if s.is_a? Struct # unicorn <2.0
44
+ s.master_pid == Process.pid
45
+ else
46
+ s.instance_eval { @master_pid } == Process.pid
47
+ end
48
+ end.first
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ module WebServer
6
+ module WEBrick
7
+ include Sqreen::WebServer::Generic
8
+
9
+ def self.active?
10
+ Sqreen::Dependency.const_exist?('WEBrick::HTTPServer') && ObjectSpace.each_object(::WEBrick::HTTPServer).count > 0
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ require 'thread'
5
+
6
+ module Sqreen
7
+ module Worker
8
+ module_function
9
+
10
+ def start(framework)
11
+ Sqreen.log.debug('Starting Sqreen worker thread')
12
+
13
+ Thread.new do
14
+ begin
15
+ runner = nil
16
+ Sqreen.log.debug("Reading configuration")
17
+ configuration = Sqreen.config_init(framework)
18
+ framework.sqreen_configuration = configuration
19
+ Sqreen.log.debug("Initializing logs")
20
+ Sqreen.log_init
21
+ Sqreen.log.debug("Starting Sqreen #{Sqreen::VERSION}")
22
+ prevent_startup = Sqreen.framework.prevent_startup
23
+ if !prevent_startup
24
+ warn "[#{Process.pid}] Sqreen logging at level #{Sqreen.log.instance_eval { @logger }.level} to #{Sqreen.log.instance_eval { @logger }.instance_eval { @logdev.filename }}"
25
+ runner = Sqreen::Runner.new(configuration, framework)
26
+ runner.run_watcher
27
+ else
28
+ Sqreen.log.debug("#{prevent_startup} prevented Sqreen startup")
29
+ end
30
+ rescue Sqreen::TokenNotFoundException
31
+ Sqreen.log.error "Sorry but we couldn't find your Sqreen token.\nYour application is NOT currently protected by Sqreen.\n\nHave you filled your config/sqreen.yml?\n\n"
32
+ rescue Sqreen::TokenInvalidException
33
+ Sqreen.log.error "Sorry but your Sqreen token appears to be invalid.\nYour application is NOT currently protected by Sqreen.\n\nHave you correctly filled your config/sqreen.yml?\n\n"
34
+ rescue Exception => e # rubocop:disable Lint/RescueException
35
+ Sqreen.log.debug("General exception caught: #{e.inspect}")
36
+ Sqreen.log.debug e.backtrace
37
+ if runner
38
+ unless e.is_a?(Sqreen::Unauthorized)
39
+ Sqreen.log.debug("Immediately posting exception for runner #{runner.inspect}")
40
+ runner.session.post_sqreen_exception(Sqreen::RemoteException.new(e))
41
+ end
42
+ begin
43
+ runner.remove_instrumentation
44
+ rescue StandardError => e
45
+ Sqreen.log.debug("Unexpected exception when removing instrumentation: #{e.inspect}")
46
+ Sqreen.log.debug e.backtrace
47
+ Sqreen.log.error("Terminating Sqreen thread")
48
+ return nil
49
+ end
50
+ begin
51
+ runner.logout(false)
52
+ rescue StandardError => e
53
+ Sqreen.log.debug("Unexpected exception when logging out: #{remove_exception.inspect}")
54
+ Sqreen.log.debug(e.backtrace)
55
+ nil
56
+ end
57
+ end
58
+ # Wait a few seconds before retrying
59
+ delay = rand(120)
60
+ Sqreen.log.debug("Sleeping #{delay} seconds before restarting Sqreen thread")
61
+ sleep(delay)
62
+ retry
63
+ end
64
+ Sqreen.log.debug("Shutting down Sqreen #{Sqreen::VERSION}")
65
+ end
66
+ end
67
+ end
68
+ 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.17.0
4
+ version: 1.17.2.beta1
5
5
  platform: java
6
6
  authors:
7
7
  - Sqreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-23 00:00:00.000000000 Z
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -45,12 +45,14 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - CHANGELOG.md
48
49
  - CODE_OF_CONDUCT.md
49
50
  - README.md
50
51
  - Rakefile
51
52
  - lib/sqreen-alt.rb
52
53
  - lib/sqreen.rb
53
54
  - lib/sqreen/actions.rb
55
+ - lib/sqreen/agent.rb
54
56
  - lib/sqreen/attack_detected.html
55
57
  - lib/sqreen/binding_accessor.rb
56
58
  - lib/sqreen/ca.crt
@@ -64,6 +66,15 @@ files:
64
66
  - lib/sqreen/context.rb
65
67
  - lib/sqreen/deliveries/batch.rb
66
68
  - lib/sqreen/deliveries/simple.rb
69
+ - lib/sqreen/dependency.rb
70
+ - lib/sqreen/dependency/callback.rb
71
+ - lib/sqreen/dependency/detector.rb
72
+ - lib/sqreen/dependency/hook.rb
73
+ - lib/sqreen/dependency/hook_point.rb
74
+ - lib/sqreen/dependency/new_relic.rb
75
+ - lib/sqreen/dependency/rack.rb
76
+ - lib/sqreen/dependency/rails.rb
77
+ - lib/sqreen/dependency/sentry.rb
67
78
  - lib/sqreen/event.rb
68
79
  - lib/sqreen/events/attack.rb
69
80
  - lib/sqreen/events/remote_exception.rb
@@ -133,10 +144,21 @@ files:
133
144
  - lib/sqreen/shared_storage23.rb
134
145
  - lib/sqreen/trie.rb
135
146
  - lib/sqreen/version.rb
147
+ - lib/sqreen/web_server.rb
148
+ - lib/sqreen/web_server/generic.rb
149
+ - lib/sqreen/web_server/passenger.rb
150
+ - lib/sqreen/web_server/puma.rb
151
+ - lib/sqreen/web_server/rainbows.rb
152
+ - lib/sqreen/web_server/thin.rb
153
+ - lib/sqreen/web_server/unicorn.rb
154
+ - lib/sqreen/web_server/webrick.rb
155
+ - lib/sqreen/worker.rb
136
156
  homepage: https://www.sqreen.io/
137
157
  licenses: []
138
158
  metadata: {}
139
- post_install_message:
159
+ post_install_message: |2
160
+ This is a Sqreen beta release and may not work in all situations.
161
+ Make sure to review CHANGELOG.md for important details.
140
162
  rdoc_options: []
141
163
  require_paths:
142
164
  - lib
@@ -144,12 +166,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
166
  requirements:
145
167
  - - ">="
146
168
  - !ruby/object:Gem::Version
147
- version: '0'
169
+ version: '2.2'
148
170
  required_rubygems_version: !ruby/object:Gem::Requirement
149
171
  requirements:
150
- - - ">="
172
+ - - ">"
151
173
  - !ruby/object:Gem::Version
152
- version: '0'
174
+ version: 1.3.1
153
175
  requirements: []
154
176
  rubyforge_project:
155
177
  rubygems_version: 2.7.7