sqreen 1.20.4 → 1.21.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -25
- data/lib/sqreen/actions/block_user.rb +1 -1
- data/lib/sqreen/actions/redirect_ip.rb +1 -1
- data/lib/sqreen/actions/redirect_user.rb +1 -1
- data/lib/sqreen/condition_evaluator.rb +2 -8
- data/lib/sqreen/configuration.rb +1 -1
- data/lib/sqreen/deferred_logger.rb +14 -50
- data/lib/sqreen/deliveries/batch.rb +8 -1
- data/lib/sqreen/ecosystem.rb +80 -0
- data/lib/sqreen/ecosystem/dispatch_table.rb +43 -0
- data/lib/sqreen/ecosystem/http/net_http.rb +51 -0
- data/lib/sqreen/ecosystem/http/rack_request.rb +38 -0
- data/lib/sqreen/ecosystem/loggable.rb +13 -0
- data/lib/sqreen/ecosystem/module_api.rb +30 -0
- data/lib/sqreen/ecosystem/module_api/event_listener.rb +18 -0
- data/lib/sqreen/ecosystem/module_api/instrumentation.rb +23 -0
- data/lib/sqreen/ecosystem/module_api/signal_producer.rb +26 -0
- data/lib/sqreen/ecosystem/module_api/tracing_push_down.rb +34 -0
- data/lib/sqreen/ecosystem/module_api/transaction_storage.rb +71 -0
- data/lib/sqreen/ecosystem/module_registry.rb +39 -0
- data/lib/sqreen/ecosystem/redis/redis_connection.rb +35 -0
- data/lib/sqreen/ecosystem/tracing/sampler.rb +160 -0
- data/lib/sqreen/ecosystem/tracing/sampling_configuration.rb +150 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_client.rb +53 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_server.rb +53 -0
- data/lib/sqreen/ecosystem/tracing_id_setup.rb +34 -0
- data/lib/sqreen/ecosystem/transaction_storage.rb +64 -0
- data/lib/sqreen/ecosystem_integration.rb +70 -0
- data/lib/sqreen/ecosystem_integration/around_callbacks.rb +89 -0
- data/lib/sqreen/ecosystem_integration/instrumentation_service.rb +38 -0
- data/lib/sqreen/ecosystem_integration/request_lifecycle_tracking.rb +56 -0
- data/lib/sqreen/ecosystem_integration/signal_consumption.rb +35 -0
- data/lib/sqreen/encoding_sanitizer.rb +27 -0
- data/lib/sqreen/events/request_record.rb +1 -0
- data/lib/sqreen/frameworks/generic.rb +15 -10
- data/lib/sqreen/frameworks/rails.rb +7 -0
- data/lib/sqreen/frameworks/request_recorder.rb +0 -2
- data/lib/sqreen/graft/call.rb +23 -72
- data/lib/sqreen/graft/callback.rb +1 -1
- data/lib/sqreen/graft/hook.rb +85 -187
- data/lib/sqreen/graft/hook_point.rb +1 -1
- data/lib/sqreen/legacy/instrumentation.rb +10 -22
- data/lib/sqreen/legacy/old_event_submission_strategy.rb +8 -3
- data/lib/sqreen/log.rb +2 -3
- data/lib/sqreen/log/loggable.rb +0 -1
- data/lib/sqreen/logger.rb +0 -24
- data/lib/sqreen/metrics_store.rb +0 -11
- data/lib/sqreen/null_logger.rb +0 -22
- data/lib/sqreen/remote_command.rb +3 -1
- data/lib/sqreen/rules.rb +4 -8
- data/lib/sqreen/rules/blacklist_ips_cb.rb +2 -2
- data/lib/sqreen/rules/custom_error_cb.rb +3 -3
- data/lib/sqreen/rules/rule_cb.rb +0 -2
- data/lib/sqreen/rules/waf_cb.rb +3 -3
- data/lib/sqreen/runner.rb +21 -33
- data/lib/sqreen/session.rb +2 -0
- data/lib/sqreen/signals/conversions.rb +6 -1
- data/lib/sqreen/version.rb +1 -1
- data/lib/sqreen/weave/legacy/instrumentation.rb +103 -194
- data/lib/sqreen/worker.rb +2 -6
- metadata +35 -10
- data/lib/sqreen/deprecation.rb +0 -38
- data/lib/sqreen/weave/budget.rb +0 -46
data/lib/sqreen/session.rb
CHANGED
@@ -249,8 +249,10 @@ module Sqreen
|
|
249
249
|
end
|
250
250
|
Sqreen.log.info 'Login success.'
|
251
251
|
@session_id = res['session_id']
|
252
|
+
|
252
253
|
Kit::Configuration.session_key = @session_id
|
253
254
|
Kit.reset
|
255
|
+
|
254
256
|
Sqreen.log.debug { "received session_id #{@session_id}" }
|
255
257
|
Sqreen.logged_in = true
|
256
258
|
res
|
@@ -118,6 +118,7 @@ module Sqreen
|
|
118
118
|
signals += req_rec.processed_sdk_calls
|
119
119
|
.select { |h| h[:name] == :track }
|
120
120
|
.map { |h| convert_track(h) }
|
121
|
+
signals += (observed[:signals] || [])
|
121
122
|
|
122
123
|
trace = Kit::Signals::Specialized::HttpTrace.new(
|
123
124
|
actor: Kit::Signals::Actor.new(
|
@@ -137,7 +138,7 @@ module Sqreen
|
|
137
138
|
trace
|
138
139
|
end
|
139
140
|
|
140
|
-
# @
|
141
|
+
# @return [Array<Sqreen::Kit::Signals::Signal|Sqreen::Kit::Signals::Trace>]
|
141
142
|
def convert_batch(batch)
|
142
143
|
batch.map do |evt|
|
143
144
|
case evt
|
@@ -147,6 +148,10 @@ module Sqreen
|
|
147
148
|
convert_metric_sample(evt)
|
148
149
|
when RequestRecord
|
149
150
|
convert_req_record(evt)
|
151
|
+
when Sqreen::Kit::Signals::Signal
|
152
|
+
evt
|
153
|
+
when Sqreen::Kit::Signals::Trace
|
154
|
+
evt
|
150
155
|
else
|
151
156
|
raise NotImplementedError, "Unknown type of event in batch: #{evt}"
|
152
157
|
end
|
data/lib/sqreen/version.rb
CHANGED
@@ -4,13 +4,10 @@
|
|
4
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
5
5
|
|
6
6
|
require 'sqreen/weave/legacy'
|
7
|
-
require 'sqreen/weave/budget'
|
8
|
-
require 'sqreen/graft/hook'
|
9
7
|
require 'sqreen/graft/hook_point'
|
10
8
|
require 'sqreen/call_countable'
|
11
9
|
require 'sqreen/rules'
|
12
10
|
require 'sqreen/rules/record_request_context'
|
13
|
-
require 'sqreen/sqreen_signed_verifier'
|
14
11
|
|
15
12
|
class Sqreen::Weave::Legacy::Instrumentation
|
16
13
|
attr_accessor :metrics_engine
|
@@ -63,27 +60,6 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
63
60
|
'options' => opts[:perf_metric_percent] || { 'base' => 1.3, 'factor' => 1.0 },
|
64
61
|
)
|
65
62
|
|
66
|
-
metrics_engine.create_metric(
|
67
|
-
'name' => 'req.sq.hook.overhead',
|
68
|
-
'period' => 60,
|
69
|
-
'kind' => 'Binning',
|
70
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
71
|
-
)
|
72
|
-
|
73
|
-
metrics_engine.create_metric(
|
74
|
-
'name' => 'sq.hook.overhead',
|
75
|
-
'period' => 60,
|
76
|
-
'kind' => 'Binning',
|
77
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
78
|
-
)
|
79
|
-
|
80
|
-
metrics_engine.create_metric(
|
81
|
-
'name' => 'sq.shrinkwrap',
|
82
|
-
'period' => 60,
|
83
|
-
'kind' => 'Binning',
|
84
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
85
|
-
)
|
86
|
-
|
87
63
|
Sqreen.thread_cpu_time? && metrics_engine.create_metric(
|
88
64
|
'name' => 'sq_thread_cpu_pct',
|
89
65
|
'period' => opts[:period] || 60,
|
@@ -108,15 +84,6 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
108
84
|
|
109
85
|
### set up rule signature verifier
|
110
86
|
verifier = nil
|
111
|
-
if Sqreen.features['rules_signature'] &&
|
112
|
-
Sqreen.config_get(:rules_verify_signature) == true &&
|
113
|
-
!defined?(::JRUBY_VERSION)
|
114
|
-
verifier = Sqreen::SqreenSignedVerifier.new
|
115
|
-
Sqreen::Weave.logger.debug('Rules signature enabled')
|
116
|
-
else
|
117
|
-
Sqreen::Weave.logger.debug('Rules signature disabled')
|
118
|
-
end
|
119
|
-
|
120
87
|
### force clean instrumentation callback list
|
121
88
|
@hooks = []
|
122
89
|
### for each rule description
|
@@ -127,25 +94,6 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
127
94
|
next unless rule_callback
|
128
95
|
### attach framework to callback
|
129
96
|
rule_callback.framework = framework
|
130
|
-
## create metric
|
131
|
-
Sqreen::Weave.logger.debug { "Adding rule metric: #{rule_callback}" }
|
132
|
-
[:pre, :post, :failing].each do |whence|
|
133
|
-
next unless rule_callback.send(:"#{whence}?")
|
134
|
-
metric_name = "sq.#{rule['name']}.#{whence}"
|
135
|
-
metrics_engine.create_metric(
|
136
|
-
'name' => metric_name,
|
137
|
-
'period' => 60,
|
138
|
-
'kind' => 'Binning',
|
139
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
140
|
-
)
|
141
|
-
metric_name = "req.sq.#{rule['name']}.#{whence}"
|
142
|
-
metrics_engine.create_metric(
|
143
|
-
'name' => metric_name,
|
144
|
-
'period' => 60,
|
145
|
-
'kind' => 'Binning',
|
146
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
147
|
-
)
|
148
|
-
end
|
149
97
|
### install callback, observing priority
|
150
98
|
Sqreen::Weave.logger.debug { "Adding rule callback: #{rule_callback}" }
|
151
99
|
@hooks << add_callback("weave,rule=#{rule['name']}", rule_callback, strategy)
|
@@ -159,43 +107,30 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
159
107
|
end
|
160
108
|
|
161
109
|
metrics_engine = self.metrics_engine
|
162
|
-
|
163
110
|
request_hook = Sqreen::Graft::Hook['Sqreen::ShrinkWrap#call', strategy]
|
164
111
|
@hooks << request_hook
|
165
112
|
request_hook.add do
|
166
113
|
before('wave,meta,request', rank: -100000, mandatory: true) do |_call|
|
167
114
|
next unless Sqreen.instrumentation_ready
|
168
115
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
request_timer = Sqreen::Graft::Timer.new("request")
|
173
|
-
request_timer.start
|
174
|
-
sqreen_timer = Sqreen::Graft::Timer.new("sqreen")
|
175
|
-
budget = Sqreen::Weave::Budget.current
|
176
|
-
request_budget_threshold = budget.threshold if budget
|
177
|
-
request_budget_ratio = budget.ratio if budget
|
178
|
-
request_budget_is_dynamic = !request_budget_ratio.nil?
|
179
|
-
request_budget = !request_budget_threshold.nil?
|
180
|
-
timed_level = (Sqreen.features['perf_level'] || 1).to_i
|
181
|
-
Sqreen::Weave.logger.debug { "request budget: #{budget.to_h} timed.level: #{timed_level}" } if Sqreen::Weave.logger.debug?
|
182
|
-
|
116
|
+
uuid = SecureRandom.uuid
|
117
|
+
now = Sqreen::Graft::Timer.read
|
183
118
|
Thread.current[:sqreen_http_request] = {
|
184
|
-
|
185
|
-
|
119
|
+
uuid: uuid,
|
120
|
+
start_time: now,
|
121
|
+
time_budget: Sqreen.performance_budget,
|
186
122
|
time_budget_expended: false,
|
187
|
-
|
188
|
-
time_budget_dynamic: request_budget_is_dynamic,
|
189
|
-
time_budget_ratio: request_budget_ratio,
|
190
|
-
time_budget: request_budget,
|
123
|
+
timer: Sqreen::Graft::Timer.new("request_#{uuid}"),
|
191
124
|
timed_callbacks: [],
|
192
125
|
timed_hooks: [],
|
193
|
-
|
126
|
+
timed_hooks_before: [],
|
127
|
+
timed_hooks_after: [],
|
128
|
+
timed_hooks_raised: [],
|
129
|
+
timed_hooks_ensured: [],
|
194
130
|
skipped_callbacks: [],
|
195
|
-
# timed_shrinkwrap: shrinkwrap_timer,
|
196
131
|
}
|
197
132
|
|
198
|
-
#
|
133
|
+
Sqreen::Weave.logger.debug { "request.uuid: #{uuid}" }
|
199
134
|
end
|
200
135
|
|
201
136
|
ensured('weave,meta,request', rank: 100000, mandatory: true) do |_call|
|
@@ -203,118 +138,105 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
203
138
|
|
204
139
|
next if request.nil?
|
205
140
|
|
206
|
-
# shrinkwrap_timer = request[:timed_shrinkwrap]
|
207
|
-
# shrinkwrap_timer.start
|
208
|
-
|
209
141
|
Thread.current[:sqreen_http_request] = nil
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
metrics_engine.
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
metrics_engine.update('sq.hook.overhead', now, nil, duration * 1000)
|
235
|
-
# Sqreen.observations_queue.push(['sq.hook.overhead', nil, duration * 1000, utc_now])
|
142
|
+
now = Sqreen::Graft::Timer.read
|
143
|
+
utc_now = Time.now.utc
|
144
|
+
|
145
|
+
request[:timed_callbacks].each do |timer|
|
146
|
+
duration = timer.duration
|
147
|
+
# stop = now
|
148
|
+
# start = now - duration
|
149
|
+
timer.tag =~ /weave,rule=(.*)$/ && rule = $1
|
150
|
+
timer.tag =~ /@before/ && whence = 'pre'
|
151
|
+
timer.tag =~ /@after/ && whence = 'post'
|
152
|
+
timer.tag =~ /@raised/ && whence = 'failing'
|
153
|
+
|
154
|
+
next unless rule && whence
|
155
|
+
|
156
|
+
# Sqreen::PerformanceNotifications.notify(rule, whence, start, stop)
|
157
|
+
# => BinnedMetrics
|
158
|
+
metric_name = "sq.#{rule}.#{whence}"
|
159
|
+
unless metrics_engine.metric?(metric_name)
|
160
|
+
metrics_engine.create_metric(
|
161
|
+
'name' => metric_name,
|
162
|
+
'period' => 60,
|
163
|
+
'kind' => 'Binning',
|
164
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
165
|
+
)
|
236
166
|
end
|
167
|
+
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
237
168
|
end
|
238
169
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
170
|
+
metric_name = 'sq.hooks_pre.pre'
|
171
|
+
duration = request[:timed_hooks_before].sum(&:duration)
|
172
|
+
unless metrics_engine.metric?(metric_name)
|
173
|
+
metrics_engine.create_metric(
|
174
|
+
'name' => metric_name,
|
175
|
+
'period' => 60,
|
176
|
+
'kind' => 'Binning',
|
177
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
178
|
+
)
|
179
|
+
end
|
180
|
+
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
181
|
+
|
182
|
+
metric_name = 'sq.hooks_post.post'
|
183
|
+
duration = request[:timed_hooks_after].sum(&:duration)
|
184
|
+
unless metrics_engine.metric?(metric_name)
|
185
|
+
metrics_engine.create_metric(
|
186
|
+
'name' => metric_name,
|
187
|
+
'period' => 60,
|
188
|
+
'kind' => 'Binning',
|
189
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
190
|
+
)
|
254
191
|
end
|
192
|
+
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
193
|
+
|
194
|
+
metric_name = 'sq.hooks_failing.failing'
|
195
|
+
duration = request[:timed_hooks_raised].sum(&:duration)
|
196
|
+
unless metrics_engine.metric?(metric_name)
|
197
|
+
metrics_engine.create_metric(
|
198
|
+
'name' => metric_name,
|
199
|
+
'period' => 60,
|
200
|
+
'kind' => 'Binning',
|
201
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
202
|
+
)
|
203
|
+
end
|
204
|
+
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
205
|
+
|
206
|
+
skipped = request[:skipped_callbacks].map(&:name)
|
207
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.skipped.size: #{skipped.count} callback.skipped: [#{skipped.join(', ')}]" }
|
208
|
+
timer = request[:timer]
|
209
|
+
total = timer.duration
|
210
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} timer.total: #{'%.03fus' % (total * 1_000_000)} timer.size: #{timer.size}" }
|
211
|
+
timings = request[:timed_callbacks].map(&:to_s)
|
212
|
+
total = request[:timed_callbacks].sum(&:duration)
|
213
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.total: #{'%.03fus' % (total * 1_000_000)} callback.timings: [#{timings.join(', ')}]" }
|
214
|
+
timings = request[:timed_hooks].map(&:to_s)
|
215
|
+
total = request[:timed_hooks].sum(&:duration)
|
216
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} hook.total: #{'%.03fus' % (total * 1_000_000)} hook.timings: [#{timings.join(', ')}]" }
|
255
217
|
|
256
218
|
skipped = request[:skipped_callbacks].map(&:name)
|
257
219
|
skipped_rule_name = skipped.first && skipped.first =~ /weave,rule=(.*)$/ && $1
|
258
|
-
|
259
|
-
# Sqreen.observations_queue.push(['request_overtime', skipped_rule_name, 1, utc_now]) if skipped_rule_name
|
220
|
+
Sqreen.observations_queue.push(['request_overtime', skipped_rule_name, 1, utc_now]) if skipped_rule_name
|
260
221
|
|
261
|
-
sqreen_request_duration =
|
262
|
-
|
263
|
-
# Sqreen.observations_queue.push(['sq', nil, sqreen_request_duration * 1000, utc_now])
|
222
|
+
sqreen_request_duration = total
|
223
|
+
Sqreen.observations_queue.push(['sq', nil, sqreen_request_duration * 1000, utc_now])
|
264
224
|
|
265
|
-
request_duration =
|
266
|
-
|
267
|
-
# Sqreen.observations_queue.push(['req', nil, request_duration * 1000, utc_now])
|
225
|
+
request_duration = now - request[:start_time]
|
226
|
+
Sqreen.observations_queue.push(['req', nil, request_duration * 1000, utc_now])
|
268
227
|
|
269
228
|
sqreen_request_ratio = (sqreen_request_duration * 100.0) / (request_duration - sqreen_request_duration)
|
270
|
-
|
271
|
-
# Sqreen.observations_queue.push(['pct', nil, sqreen_request_ratio, utc_now])
|
272
|
-
Sqreen::Weave.logger.debug { "request sqreen_timer.ratio: #{'%.03f' % (sqreen_request_ratio / 100.0)}" } if Sqreen::Weave.logger.debug?
|
273
|
-
|
274
|
-
if request[:timed_level] >= 2
|
275
|
-
tallies = Hash.new(0.0)
|
276
|
-
request[:timed_callbacks].each do |timer|
|
277
|
-
duration = timer.duration
|
278
|
-
|
279
|
-
timer.tag =~ /weave,rule=(.*)$/ && rule = $1
|
280
|
-
next unless rule
|
281
|
-
|
282
|
-
whence = case timer.tag
|
283
|
-
when /@before/ then 'pre'
|
284
|
-
when /@after/ then 'post'
|
285
|
-
when /@raised/ then 'failing'
|
286
|
-
end
|
287
|
-
next unless whence
|
288
|
-
|
289
|
-
metric_name = "req.sq.#{rule}.#{whence}"
|
290
|
-
tallies[metric_name] += duration
|
291
|
-
end
|
292
|
-
tallies.each do |metric_name, duration|
|
293
|
-
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
294
|
-
# Sqreen.observations_queue.push([metric_name, nil, duration * 1000, utc_now])
|
295
|
-
end
|
296
|
-
|
297
|
-
duration = request[:timed_hooks].sum(&:duration)
|
298
|
-
metrics_engine.update('req.sq.hook.overhead', now, nil, duration * 1000)
|
299
|
-
# Sqreen.observations_queue.push(['req.sq.hook.overhead', nil, duration * 1000, utc_now])
|
300
|
-
end
|
301
|
-
|
302
|
-
# shrinkwrap_timer.stop
|
303
|
-
|
304
|
-
# duration = shrinkwrap_timer.duration
|
305
|
-
# metrics_engine.update('sq.shrinkwrap', now, nil, duration * 1000)
|
229
|
+
Sqreen.observations_queue.push(['pct', nil, sqreen_request_ratio, utc_now])
|
306
230
|
end
|
307
231
|
end.install
|
308
232
|
|
309
233
|
### globally declare instrumentation ready
|
310
234
|
Sqreen.instrumentation_ready = true
|
311
|
-
Sqreen::Weave.logger.info { "Instrumentation activated" }
|
312
235
|
end
|
313
236
|
|
314
237
|
# needed by Sqreen::Runner
|
315
238
|
def remove_all_callbacks
|
316
239
|
Sqreen.instrumentation_ready = false
|
317
|
-
Sqreen::Weave.logger.info { "Instrumentation deactivated" }
|
318
240
|
|
319
241
|
loop do
|
320
242
|
hook = @hooks.pop
|
@@ -331,15 +253,6 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
331
253
|
klass = callback.klass
|
332
254
|
method = callback.method
|
333
255
|
|
334
|
-
if (call_count = ENV['SQREEN_DEBUG_CALL_COUNT'])
|
335
|
-
call_count = JSON.parse(call_count)
|
336
|
-
if callback.respond_to?(:rule_name) && call_count.key?(callback.rule_name)
|
337
|
-
count = call_count[callback.rule_name]
|
338
|
-
Sqreen::Weave.logger.debug { "override rule: #{callback.rule_name} call_count: #{count.inspect}" }
|
339
|
-
callback.instance_eval { @call_count_interval = call_count[callback.rule_name] }
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
256
|
if Sqreen::Graft::HookPoint.new("#{klass}.#{method}").exist?
|
344
257
|
hook_point = "#{klass}.#{method}"
|
345
258
|
elsif Sqreen::Graft::HookPoint.new("#{klass}##{method}").exist?
|
@@ -362,6 +275,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
362
275
|
a = call.args
|
363
276
|
r = call.remaining
|
364
277
|
|
278
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i}" }
|
365
279
|
begin
|
366
280
|
ret = callback.pre(i, a, r)
|
367
281
|
rescue StandardError => e
|
@@ -372,26 +286,17 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
372
286
|
Sqreen::RemoteException.record(e)
|
373
287
|
end
|
374
288
|
end
|
289
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i} => return=#{ret.inspect}" }
|
375
290
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
if ret.key?(:exception)
|
386
|
-
b.raise(ret[:exception])
|
387
|
-
else
|
388
|
-
b.raise(Sqreen::AttackBlocked.new("Sqreen blocked a security threat (type: #{callback.rule_name}). No action is required."))
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
next unless throw_val
|
393
|
-
throw_val.break! if ret[:skip_rem_cbs]
|
394
|
-
throw(b, throw_val)
|
291
|
+
case ret[:status]
|
292
|
+
when :skip, 'skip'
|
293
|
+
throw(b, b.return(ret[:new_return_value]).break!) if ret.key?(:new_return_value)
|
294
|
+
when :modify_args, 'modify_args'
|
295
|
+
throw(b, b.args(ret[:args]))
|
296
|
+
when :raise, 'raise'
|
297
|
+
throw(b, b.raise(ret[:exception])) if ret.key?(:exception)
|
298
|
+
throw(b, b.raise(Sqreen::AttackBlocked.new("Sqreen blocked a security threat (type: #{callback.rule_name}). No action is required.")))
|
299
|
+
end unless ret.nil? || !ret.is_a?(Hash)
|
395
300
|
end
|
396
301
|
end
|
397
302
|
|
@@ -404,6 +309,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
404
309
|
a = call.args
|
405
310
|
r = call.remaining
|
406
311
|
|
312
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i}" }
|
407
313
|
begin
|
408
314
|
ret = callback.post(v, i, a, r)
|
409
315
|
rescue StandardError => e
|
@@ -414,6 +320,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
414
320
|
Sqreen::RemoteException.record(e)
|
415
321
|
end
|
416
322
|
end
|
323
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i} => return=#{ret.inspect}" }
|
417
324
|
|
418
325
|
case ret[:status]
|
419
326
|
when :override, 'override'
|
@@ -434,6 +341,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
434
341
|
a = call.args
|
435
342
|
r = call.remaining
|
436
343
|
|
344
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i}" }
|
437
345
|
begin
|
438
346
|
ret = callback.failing(e, i, a, r)
|
439
347
|
rescue StandardError => e
|
@@ -444,6 +352,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
444
352
|
Sqreen::RemoteException.record(e)
|
445
353
|
end
|
446
354
|
end
|
355
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i} => return=#{ret.inspect}" }
|
447
356
|
|
448
357
|
throw(b, b.raise(e)) if ret.nil? || !ret.is_a?(Hash)
|
449
358
|
|