datadog 2.9.0 → 2.11.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 +4 -4
- data/CHANGELOG.md +72 -1
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +2 -2
- data/ext/datadog_profiling_native_extension/collectors_stack.c +3 -3
- data/ext/datadog_profiling_native_extension/collectors_stack.h +2 -2
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +46 -6
- data/ext/datadog_profiling_native_extension/extconf.rb +4 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.c +2 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.h +0 -8
- data/ext/datadog_profiling_native_extension/heap_recorder.c +51 -93
- data/ext/datadog_profiling_native_extension/heap_recorder.h +1 -1
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +56 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +7 -0
- data/ext/datadog_profiling_native_extension/profiling.c +7 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +9 -22
- data/ext/datadog_profiling_native_extension/stack_recorder.h +1 -1
- data/ext/libdatadog_api/crashtracker.c +4 -4
- data/ext/libdatadog_extconf_helpers.rb +1 -1
- data/lib/datadog/appsec/actions_handler.rb +27 -0
- data/lib/datadog/appsec/component.rb +14 -8
- data/lib/datadog/appsec/configuration/settings.rb +73 -11
- data/lib/datadog/appsec/context.rb +28 -8
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +6 -2
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/devise/configuration.rb +76 -0
- data/lib/datadog/appsec/contrib/devise/event.rb +4 -7
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +16 -21
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +8 -15
- data/lib/datadog/appsec/contrib/devise/patcher/rememberable_patch.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/devise/tracking.rb +1 -1
- data/lib/datadog/appsec/contrib/excon/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/excon/patcher.rb +28 -0
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +43 -0
- data/lib/datadog/appsec/contrib/faraday/connection_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/faraday/patcher.rb +53 -0
- data/lib/datadog/appsec/contrib/faraday/rack_builder_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +42 -0
- data/lib/datadog/appsec/contrib/graphql/appsec_trace.rb +1 -7
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +11 -14
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +65 -70
- data/lib/datadog/appsec/contrib/rack/patcher.rb +0 -3
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -3
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +11 -22
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +20 -24
- data/lib/datadog/appsec/contrib/rails/patcher.rb +3 -16
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +38 -47
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +3 -29
- data/lib/datadog/appsec/ext.rb +6 -1
- data/lib/datadog/appsec/metrics/collector.rb +38 -0
- data/lib/datadog/appsec/metrics/exporter.rb +35 -0
- data/lib/datadog/appsec/metrics/telemetry.rb +23 -0
- data/lib/datadog/appsec/metrics.rb +13 -0
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +19 -24
- data/lib/datadog/appsec/processor.rb +4 -3
- data/lib/datadog/appsec/remote.rb +4 -0
- data/lib/datadog/appsec/response.rb +18 -80
- data/lib/datadog/appsec/security_engine/result.rb +67 -0
- data/lib/datadog/appsec/security_engine/runner.rb +88 -0
- data/lib/datadog/appsec/security_engine.rb +9 -0
- data/lib/datadog/appsec.rb +16 -5
- data/lib/datadog/core/configuration/components.rb +7 -1
- data/lib/datadog/core/configuration/ext.rb +1 -1
- data/lib/datadog/core/configuration/option_definition.rb +2 -0
- data/lib/datadog/core/configuration/settings.rb +22 -6
- data/lib/datadog/core/encoding.rb +16 -0
- data/lib/datadog/core/environment/agent_info.rb +77 -0
- data/lib/datadog/core/remote/transport/http/api.rb +13 -18
- data/lib/datadog/core/remote/transport/http/config.rb +0 -18
- data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -18
- data/lib/datadog/core/remote/transport/http.rb +7 -12
- data/lib/datadog/core/remote/transport/negotiation.rb +13 -1
- data/lib/datadog/core/telemetry/event.rb +5 -0
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/api/instance.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/api/spec.rb +1 -1
- data/lib/datadog/{tracing → core}/transport/http/builder.rb +37 -17
- data/lib/datadog/core/transport/response.rb +4 -0
- data/lib/datadog/di/code_tracker.rb +15 -8
- data/lib/datadog/di/component.rb +3 -0
- data/lib/datadog/di/configuration/settings.rb +14 -0
- data/lib/datadog/di/contrib.rb +2 -0
- data/lib/datadog/di/logger.rb +30 -0
- data/lib/datadog/di/probe.rb +3 -6
- data/lib/datadog/di/probe_manager.rb +5 -2
- data/lib/datadog/di/probe_notification_builder.rb +6 -0
- data/lib/datadog/di/probe_notifier_worker.rb +15 -4
- data/lib/datadog/di/redactor.rb +0 -1
- data/lib/datadog/di/remote.rb +29 -8
- data/lib/datadog/di/utils.rb +91 -0
- data/lib/datadog/di.rb +3 -0
- data/lib/datadog/profiling/component.rb +2 -8
- data/lib/datadog/profiling/load_native_extension.rb +1 -33
- data/lib/datadog/tracing/configuration/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/aws/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/extensions.rb +29 -3
- data/lib/datadog/tracing/contrib/graphql/configuration/error_extension_env_parser.rb +21 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +11 -0
- data/lib/datadog/tracing/contrib/graphql/ext.rb +5 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +102 -11
- data/lib/datadog/tracing/contrib/http/integration.rb +3 -0
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +11 -1
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +1 -1
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +6 -1
- data/lib/datadog/tracing/transport/http/api.rb +11 -2
- data/lib/datadog/tracing/transport/http/traces.rb +0 -3
- data/lib/datadog/tracing/transport/http.rb +12 -7
- data/lib/datadog/tracing/transport/serializable_trace.rb +8 -4
- data/lib/datadog/tracing/transport/traces.rb +25 -8
- data/lib/datadog/version.rb +1 -1
- metadata +51 -42
- data/ext/datadog_profiling_loader/datadog_profiling_loader.c +0 -142
- data/ext/datadog_profiling_loader/extconf.rb +0 -60
- data/lib/datadog/appsec/contrib/graphql/reactive/multiplex.rb +0 -46
- data/lib/datadog/appsec/contrib/patcher.rb +0 -12
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +0 -69
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +0 -47
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +0 -53
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +0 -53
- data/lib/datadog/appsec/contrib/sinatra/ext.rb +0 -14
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +0 -48
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +0 -45
- data/lib/datadog/appsec/processor/context.rb +0 -107
- data/lib/datadog/appsec/reactive/address_hash.rb +0 -22
- data/lib/datadog/appsec/reactive/engine.rb +0 -47
- data/lib/datadog/appsec/reactive/subscriber.rb +0 -19
- data/lib/datadog/core/remote/transport/http/api/instance.rb +0 -39
- data/lib/datadog/core/remote/transport/http/api/spec.rb +0 -21
- data/lib/datadog/core/remote/transport/http/builder.rb +0 -219
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module GraphQL
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a GraphQL resolve query to the WAF context
|
9
|
-
module Multiplex
|
10
|
-
ADDRESSES = [
|
11
|
-
'graphql.server.all_resolvers'
|
12
|
-
].freeze
|
13
|
-
private_constant :ADDRESSES
|
14
|
-
|
15
|
-
def self.publish(engine, gateway_multiplex)
|
16
|
-
catch(:block) do
|
17
|
-
engine.publish('graphql.server.all_resolvers', gateway_multiplex.arguments)
|
18
|
-
|
19
|
-
nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.subscribe(engine, context)
|
24
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
25
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
26
|
-
arguments = values[0]
|
27
|
-
|
28
|
-
persistent_data = {
|
29
|
-
'graphql.server.all_resolvers' => arguments
|
30
|
-
}
|
31
|
-
|
32
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
33
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
34
|
-
|
35
|
-
next if result.status != :match
|
36
|
-
|
37
|
-
yield result
|
38
|
-
throw(:block, true) unless result.actions.empty?
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module Rack
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a Rack request to the WAF context
|
9
|
-
module Request
|
10
|
-
ADDRESSES = [
|
11
|
-
'request.headers',
|
12
|
-
'request.uri.raw',
|
13
|
-
'request.query',
|
14
|
-
'request.cookies',
|
15
|
-
'request.client_ip',
|
16
|
-
'server.request.method'
|
17
|
-
].freeze
|
18
|
-
private_constant :ADDRESSES
|
19
|
-
|
20
|
-
def self.publish(engine, gateway_request)
|
21
|
-
catch(:block) do
|
22
|
-
engine.publish('request.query', gateway_request.query)
|
23
|
-
engine.publish('request.headers', gateway_request.headers)
|
24
|
-
engine.publish('request.uri.raw', gateway_request.fullpath)
|
25
|
-
engine.publish('request.cookies', gateway_request.cookies)
|
26
|
-
engine.publish('request.client_ip', gateway_request.client_ip)
|
27
|
-
engine.publish('server.request.method', gateway_request.method)
|
28
|
-
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.subscribe(engine, context)
|
34
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
35
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
36
|
-
|
37
|
-
headers = values[0]
|
38
|
-
headers_no_cookies = headers.dup.tap { |h| h.delete('cookie') }
|
39
|
-
uri_raw = values[1]
|
40
|
-
query = values[2]
|
41
|
-
cookies = values[3]
|
42
|
-
client_ip = values[4]
|
43
|
-
request_method = values[5]
|
44
|
-
|
45
|
-
persistent_data = {
|
46
|
-
'server.request.cookies' => cookies,
|
47
|
-
'server.request.query' => query,
|
48
|
-
'server.request.uri.raw' => uri_raw,
|
49
|
-
'server.request.headers' => headers,
|
50
|
-
'server.request.headers.no_cookies' => headers_no_cookies,
|
51
|
-
'http.client_ip' => client_ip,
|
52
|
-
'server.request.method' => request_method,
|
53
|
-
}
|
54
|
-
|
55
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
56
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
57
|
-
|
58
|
-
next if result.status != :match
|
59
|
-
|
60
|
-
yield result
|
61
|
-
throw(:block, true) unless result.actions.empty?
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module Rack
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a Rack request to the WAF context
|
9
|
-
module RequestBody
|
10
|
-
ADDRESSES = [
|
11
|
-
'request.body',
|
12
|
-
].freeze
|
13
|
-
private_constant :ADDRESSES
|
14
|
-
|
15
|
-
def self.publish(engine, gateway_request)
|
16
|
-
catch(:block) do
|
17
|
-
# params have been parsed from the request body
|
18
|
-
engine.publish('request.body', gateway_request.form_hash)
|
19
|
-
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.subscribe(engine, context)
|
25
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
26
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
27
|
-
body = values[0]
|
28
|
-
|
29
|
-
persistent_data = {
|
30
|
-
'server.request.body' => body,
|
31
|
-
}
|
32
|
-
|
33
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
34
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
35
|
-
|
36
|
-
next if result.status != :match
|
37
|
-
|
38
|
-
yield result
|
39
|
-
throw(:block, true) unless result.actions.empty?
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module Rack
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a Rack response to the WAF context
|
9
|
-
module Response
|
10
|
-
ADDRESSES = [
|
11
|
-
'response.status',
|
12
|
-
'response.headers',
|
13
|
-
].freeze
|
14
|
-
private_constant :ADDRESSES
|
15
|
-
|
16
|
-
def self.publish(engine, gateway_response)
|
17
|
-
catch(:block) do
|
18
|
-
engine.publish('response.status', gateway_response.status)
|
19
|
-
engine.publish('response.headers', gateway_response.headers)
|
20
|
-
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.subscribe(engine, context)
|
26
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
27
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
28
|
-
|
29
|
-
response_status = values[0]
|
30
|
-
response_headers = values[1]
|
31
|
-
response_headers_no_cookies = response_headers.dup.tap { |h| h.delete('set-cookie') }
|
32
|
-
|
33
|
-
persistent_data = {
|
34
|
-
'server.response.status' => response_status.to_s,
|
35
|
-
'server.response.headers' => response_headers,
|
36
|
-
'server.response.headers.no_cookies' => response_headers_no_cookies,
|
37
|
-
}
|
38
|
-
|
39
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
40
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
41
|
-
|
42
|
-
next if result.status != :match
|
43
|
-
|
44
|
-
yield result
|
45
|
-
throw(:block, true) unless result.actions.empty?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../request'
|
4
|
-
|
5
|
-
module Datadog
|
6
|
-
module AppSec
|
7
|
-
module Contrib
|
8
|
-
module Rails
|
9
|
-
module Reactive
|
10
|
-
# Dispatch data from a Rails request to the WAF context
|
11
|
-
module Action
|
12
|
-
ADDRESSES = [
|
13
|
-
'rails.request.body',
|
14
|
-
'rails.request.route_params',
|
15
|
-
].freeze
|
16
|
-
private_constant :ADDRESSES
|
17
|
-
|
18
|
-
def self.publish(engine, gateway_request)
|
19
|
-
catch(:block) do
|
20
|
-
# params have been parsed from the request body
|
21
|
-
engine.publish('rails.request.body', gateway_request.parsed_body)
|
22
|
-
engine.publish('rails.request.route_params', gateway_request.route_params)
|
23
|
-
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.subscribe(engine, context)
|
29
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
30
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
31
|
-
body = values[0]
|
32
|
-
path_params = values[1]
|
33
|
-
|
34
|
-
persistent_data = {
|
35
|
-
'server.request.body' => body,
|
36
|
-
'server.request.path_params' => path_params,
|
37
|
-
}
|
38
|
-
|
39
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
40
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
41
|
-
|
42
|
-
next if result.status != :match
|
43
|
-
|
44
|
-
yield result
|
45
|
-
throw(:block, true) unless result.actions.empty?
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Contrib
|
6
|
-
module Sinatra
|
7
|
-
module Reactive
|
8
|
-
# Dispatch data from a Sinatra request to the WAF context
|
9
|
-
module Routed
|
10
|
-
ADDRESSES = [
|
11
|
-
'sinatra.request.route_params',
|
12
|
-
].freeze
|
13
|
-
private_constant :ADDRESSES
|
14
|
-
|
15
|
-
def self.publish(engine, data)
|
16
|
-
_request, route_params = data
|
17
|
-
|
18
|
-
catch(:block) do
|
19
|
-
engine.publish('sinatra.request.route_params', route_params.params)
|
20
|
-
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.subscribe(engine, context)
|
26
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
27
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
28
|
-
path_params = values[0]
|
29
|
-
|
30
|
-
persistent_data = {
|
31
|
-
'server.request.path_params' => path_params,
|
32
|
-
}
|
33
|
-
|
34
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
35
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
36
|
-
|
37
|
-
next if result.status != :match
|
38
|
-
|
39
|
-
yield result
|
40
|
-
throw(:block, true) unless result.actions.empty?
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Monitor
|
6
|
-
module Reactive
|
7
|
-
# Dispatch data from Datadog::Kit::Identity.set_user to the WAF context
|
8
|
-
module SetUser
|
9
|
-
ADDRESSES = [
|
10
|
-
'usr.id',
|
11
|
-
].freeze
|
12
|
-
private_constant :ADDRESSES
|
13
|
-
|
14
|
-
def self.publish(engine, user)
|
15
|
-
catch(:block) do
|
16
|
-
engine.publish('usr.id', user.id)
|
17
|
-
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.subscribe(engine, context)
|
23
|
-
engine.subscribe(*ADDRESSES) do |*values|
|
24
|
-
Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
|
25
|
-
|
26
|
-
user_id = values[0]
|
27
|
-
|
28
|
-
persistent_data = {
|
29
|
-
'usr.id' => user_id,
|
30
|
-
}
|
31
|
-
|
32
|
-
waf_timeout = Datadog.configuration.appsec.waf_timeout
|
33
|
-
result = context.run_waf(persistent_data, {}, waf_timeout)
|
34
|
-
|
35
|
-
next if result.status != :match
|
36
|
-
|
37
|
-
yield result
|
38
|
-
throw(:block, true) unless result.actions.empty?
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
class Processor
|
6
|
-
# Context manages a sequence of runs
|
7
|
-
class Context
|
8
|
-
LIBDDWAF_SUCCESSFUL_EXECUTION_CODES = [:ok, :match].freeze
|
9
|
-
|
10
|
-
attr_reader :time_ns, :time_ext_ns, :timeouts, :events
|
11
|
-
|
12
|
-
def initialize(handle, telemetry:)
|
13
|
-
@context = WAF::Context.new(handle)
|
14
|
-
@telemetry = telemetry
|
15
|
-
|
16
|
-
@time_ns = 0.0
|
17
|
-
@time_ext_ns = 0.0
|
18
|
-
@timeouts = 0
|
19
|
-
@events = []
|
20
|
-
@run_mutex = Mutex.new
|
21
|
-
|
22
|
-
@libddwaf_debug_tag = "libddwaf:#{WAF::VERSION::STRING} method:ddwaf_run"
|
23
|
-
end
|
24
|
-
|
25
|
-
def run(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
|
26
|
-
@run_mutex.lock
|
27
|
-
|
28
|
-
start_ns = Core::Utils::Time.get_time(:nanosecond)
|
29
|
-
|
30
|
-
persistent_data.reject! do |_, v|
|
31
|
-
next false if v.is_a?(TrueClass) || v.is_a?(FalseClass)
|
32
|
-
|
33
|
-
v.nil? ? true : v.empty?
|
34
|
-
end
|
35
|
-
|
36
|
-
ephemeral_data.reject! do |_, v|
|
37
|
-
next false if v.is_a?(TrueClass) || v.is_a?(FalseClass)
|
38
|
-
|
39
|
-
v.nil? ? true : v.empty?
|
40
|
-
end
|
41
|
-
|
42
|
-
_code, result = try_run(persistent_data, ephemeral_data, timeout)
|
43
|
-
|
44
|
-
stop_ns = Core::Utils::Time.get_time(:nanosecond)
|
45
|
-
|
46
|
-
# these updates are not thread safe and should be protected
|
47
|
-
@time_ns += result.total_runtime
|
48
|
-
@time_ext_ns += (stop_ns - start_ns)
|
49
|
-
@timeouts += 1 if result.timeout
|
50
|
-
|
51
|
-
report_execution(result)
|
52
|
-
result
|
53
|
-
ensure
|
54
|
-
@run_mutex.unlock
|
55
|
-
end
|
56
|
-
|
57
|
-
def extract_schema
|
58
|
-
return unless extract_schema?
|
59
|
-
|
60
|
-
input = {
|
61
|
-
'waf.context.processor' => {
|
62
|
-
'extract-schema' => true
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
_code, result = try_run(input, {}, WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
|
67
|
-
|
68
|
-
report_execution(result)
|
69
|
-
result
|
70
|
-
end
|
71
|
-
|
72
|
-
def finalize
|
73
|
-
@context.finalize
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def try_run(persistent_data, ephemeral_data, timeout)
|
79
|
-
@context.run(persistent_data, ephemeral_data, timeout)
|
80
|
-
rescue WAF::LibDDWAF::Error => e
|
81
|
-
Datadog.logger.debug { "#{@libddwaf_debug_tag} execution error: #{e} backtrace: #{e.backtrace&.first(3)}" }
|
82
|
-
@telemetry.report(e, description: 'libddwaf-rb internal low-level error')
|
83
|
-
|
84
|
-
[:err_internal, WAF::Result.new(:err_internal, [], 0.0, false, [], [])]
|
85
|
-
end
|
86
|
-
|
87
|
-
def report_execution(result)
|
88
|
-
Datadog.logger.debug { "#{@libddwaf_debug_tag} execution timed out: #{result.inspect}" } if result.timeout
|
89
|
-
|
90
|
-
if LIBDDWAF_SUCCESSFUL_EXECUTION_CODES.include?(result.status)
|
91
|
-
Datadog.logger.debug { "#{@libddwaf_debug_tag} execution result: #{result.inspect}" }
|
92
|
-
else
|
93
|
-
message = "#{@libddwaf_debug_tag} execution error: #{result.status.inspect}"
|
94
|
-
|
95
|
-
Datadog.logger.debug { message }
|
96
|
-
@telemetry.error(message)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def extract_schema?
|
101
|
-
Datadog.configuration.appsec.api_security.enabled &&
|
102
|
-
Datadog.configuration.appsec.api_security.sample_rate.sample?
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Reactive
|
6
|
-
# AddressHash for Reactive Engine
|
7
|
-
class AddressHash < Hash
|
8
|
-
def self.new(*arguments, &block)
|
9
|
-
super { |h, k| h[k] = [] }
|
10
|
-
end
|
11
|
-
|
12
|
-
def addresses
|
13
|
-
keys.flatten
|
14
|
-
end
|
15
|
-
|
16
|
-
def with(address)
|
17
|
-
keys.select { |k| k.include?(address) }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'address_hash'
|
4
|
-
require_relative 'subscriber'
|
5
|
-
|
6
|
-
module Datadog
|
7
|
-
module AppSec
|
8
|
-
module Reactive
|
9
|
-
# Reactive Engine
|
10
|
-
class Engine
|
11
|
-
def initialize
|
12
|
-
@data = {}
|
13
|
-
@subscribers = AddressHash.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def subscribe(*addresses, &block)
|
17
|
-
@subscribers[addresses.freeze] << Subscriber.new(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
def publish(address, value)
|
21
|
-
# check if someone has address subscribed
|
22
|
-
if @subscribers.addresses.include?(address)
|
23
|
-
|
24
|
-
# someone will be interested, set value
|
25
|
-
@data[address] = value
|
26
|
-
|
27
|
-
# find candidates i.e address groups that contain the just posted address
|
28
|
-
@subscribers.with(address).each do |addresses|
|
29
|
-
# find targets to the address group containing the posted address
|
30
|
-
subscribers = @subscribers[addresses]
|
31
|
-
|
32
|
-
# is all data for the targets available?
|
33
|
-
if (addresses - @data.keys).empty?
|
34
|
-
hash = addresses.each_with_object({}) { |a, h| h[a] = @data[a] }
|
35
|
-
subscribers.each { |s| s.call(*hash.values) }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
attr_reader :subscribers, :data
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module AppSec
|
5
|
-
module Reactive
|
6
|
-
# Reactive Engine subscriber
|
7
|
-
class Subscriber
|
8
|
-
def initialize(&block)
|
9
|
-
@block = block
|
10
|
-
freeze
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(*args)
|
14
|
-
@block.call(*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Core
|
5
|
-
module Remote
|
6
|
-
module Transport
|
7
|
-
module HTTP
|
8
|
-
module API
|
9
|
-
# An API configured with adapter and routes
|
10
|
-
class Instance
|
11
|
-
attr_reader \
|
12
|
-
:adapter,
|
13
|
-
:headers,
|
14
|
-
:spec
|
15
|
-
|
16
|
-
def initialize(spec, adapter, options = {})
|
17
|
-
@spec = spec
|
18
|
-
@adapter = adapter
|
19
|
-
@headers = options.fetch(:headers, {})
|
20
|
-
end
|
21
|
-
|
22
|
-
def encoder
|
23
|
-
spec.encoder
|
24
|
-
end
|
25
|
-
|
26
|
-
def call(env)
|
27
|
-
# Add headers to request env, unless empty.
|
28
|
-
env.headers.merge!(headers) unless headers.empty?
|
29
|
-
|
30
|
-
# Send request env to the adapter.
|
31
|
-
adapter.call(env)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Core
|
5
|
-
module Remote
|
6
|
-
module Transport
|
7
|
-
module HTTP
|
8
|
-
module API
|
9
|
-
# Specification for an HTTP API
|
10
|
-
# Defines behaviors without specific configuration details.
|
11
|
-
class Spec
|
12
|
-
def initialize
|
13
|
-
yield(self) if block_given?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|