datadog 2.14.0 → 2.16.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 +67 -1
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +7 -6
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +1 -4
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +10 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.c +69 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.h +7 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.c +8 -1
- data/ext/datadog_profiling_native_extension/http_transport.c +25 -32
- data/ext/datadog_profiling_native_extension/profiling.c +2 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +22 -21
- data/ext/libdatadog_api/crashtracker.c +1 -9
- data/ext/libdatadog_api/crashtracker.h +5 -0
- data/ext/libdatadog_api/datadog_ruby_common.c +1 -4
- data/ext/libdatadog_api/datadog_ruby_common.h +10 -0
- data/ext/libdatadog_api/init.c +15 -0
- data/ext/libdatadog_api/library_config.c +122 -0
- data/ext/libdatadog_api/library_config.h +19 -0
- data/ext/libdatadog_api/process_discovery.c +117 -0
- data/ext/libdatadog_api/process_discovery.h +5 -0
- data/lib/datadog/appsec/actions_handler.rb +3 -2
- data/lib/datadog/appsec/assets/waf_rules/README.md +50 -5
- data/lib/datadog/appsec/assets/waf_rules/processors.json +239 -10
- data/lib/datadog/appsec/assets/waf_rules/scanners.json +926 -17
- data/lib/datadog/appsec/autoload.rb +1 -1
- data/lib/datadog/appsec/component.rb +29 -20
- data/lib/datadog/appsec/compressed_json.rb +40 -0
- data/lib/datadog/appsec/configuration/settings.rb +31 -18
- data/lib/datadog/appsec/context.rb +1 -1
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +10 -12
- data/lib/datadog/appsec/contrib/active_record/integration.rb +2 -2
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +22 -22
- data/lib/datadog/appsec/contrib/devise/data_extractor.rb +2 -3
- data/lib/datadog/appsec/contrib/devise/ext.rb +1 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +17 -4
- data/lib/datadog/appsec/contrib/excon/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +9 -10
- data/lib/datadog/appsec/contrib/faraday/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +8 -9
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +8 -9
- data/lib/datadog/appsec/contrib/graphql/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +22 -32
- data/lib/datadog/appsec/contrib/rack/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +16 -16
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +11 -13
- data/lib/datadog/appsec/contrib/rails/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rails/patcher.rb +21 -21
- data/lib/datadog/appsec/contrib/rest_client/integration.rb +1 -1
- data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +10 -11
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +17 -23
- data/lib/datadog/appsec/contrib/sinatra/integration.rb +1 -1
- data/lib/datadog/appsec/event.rb +95 -134
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +5 -2
- data/lib/datadog/appsec/metrics/telemetry.rb +1 -1
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +42 -12
- data/lib/datadog/appsec/processor/rule_loader.rb +26 -28
- data/lib/datadog/appsec/processor/rule_merger.rb +5 -5
- data/lib/datadog/appsec/processor.rb +1 -1
- data/lib/datadog/appsec/remote.rb +16 -11
- data/lib/datadog/appsec/response.rb +6 -6
- data/lib/datadog/appsec/security_engine/runner.rb +1 -1
- data/lib/datadog/appsec/security_event.rb +39 -0
- data/lib/datadog/appsec.rb +1 -1
- data/lib/datadog/core/configuration/agentless_settings_resolver.rb +176 -0
- data/lib/datadog/core/configuration/components.rb +19 -10
- data/lib/datadog/core/configuration/option.rb +61 -25
- data/lib/datadog/core/configuration/settings.rb +10 -0
- data/lib/datadog/core/configuration/stable_config.rb +23 -0
- data/lib/datadog/core/configuration.rb +24 -0
- data/lib/datadog/core/crashtracking/component.rb +1 -9
- data/lib/datadog/core/diagnostics/environment_logger.rb +1 -1
- data/lib/datadog/core/environment/git.rb +1 -0
- data/lib/datadog/core/environment/variable_helpers.rb +1 -1
- data/lib/datadog/core/metrics/client.rb +8 -7
- data/lib/datadog/core/process_discovery.rb +32 -0
- data/lib/datadog/core/remote/client.rb +7 -0
- data/lib/datadog/core/runtime/metrics.rb +1 -1
- data/lib/datadog/core/telemetry/component.rb +60 -50
- data/lib/datadog/core/telemetry/emitter.rb +17 -11
- data/lib/datadog/core/telemetry/event.rb +7 -4
- data/lib/datadog/core/telemetry/http/adapters/net.rb +12 -97
- data/lib/datadog/core/telemetry/metric.rb +5 -5
- data/lib/datadog/core/telemetry/request.rb +4 -4
- data/lib/datadog/core/telemetry/transport/http/api.rb +43 -0
- data/lib/datadog/core/telemetry/transport/http/client.rb +49 -0
- data/lib/datadog/core/telemetry/transport/http/telemetry.rb +92 -0
- data/lib/datadog/core/telemetry/transport/http.rb +63 -0
- data/lib/datadog/core/telemetry/transport/telemetry.rb +52 -0
- data/lib/datadog/core/telemetry/worker.rb +45 -0
- data/lib/datadog/core/utils/time.rb +12 -0
- data/lib/datadog/core/workers/async.rb +20 -2
- data/lib/datadog/core/workers/interval_loop.rb +12 -1
- data/lib/datadog/core/workers/runtime_metrics.rb +2 -2
- data/lib/datadog/core.rb +8 -0
- data/lib/datadog/di/boot.rb +34 -0
- data/lib/datadog/di/probe_notification_builder.rb +1 -1
- data/lib/datadog/di/remote.rb +2 -0
- data/lib/datadog/di/transport/http/diagnostics.rb +0 -1
- data/lib/datadog/di/transport/http/input.rb +0 -1
- data/lib/datadog/di/transport/http.rb +0 -6
- data/lib/datadog/di.rb +5 -32
- data/lib/datadog/error_tracking/collector.rb +87 -0
- data/lib/datadog/error_tracking/component.rb +167 -0
- data/lib/datadog/error_tracking/configuration/settings.rb +63 -0
- data/lib/datadog/error_tracking/configuration.rb +11 -0
- data/lib/datadog/error_tracking/ext.rb +18 -0
- data/lib/datadog/error_tracking/extensions.rb +16 -0
- data/lib/datadog/error_tracking/filters.rb +77 -0
- data/lib/datadog/error_tracking.rb +18 -0
- data/lib/datadog/kit/identity.rb +1 -1
- data/lib/datadog/profiling/collectors/info.rb +3 -0
- data/lib/datadog/profiling/encoded_profile.rb +11 -0
- data/lib/datadog/profiling/exporter.rb +3 -4
- data/lib/datadog/profiling/ext.rb +0 -1
- data/lib/datadog/profiling/flush.rb +4 -7
- data/lib/datadog/profiling/http_transport.rb +10 -59
- data/lib/datadog/profiling/stack_recorder.rb +4 -4
- data/lib/datadog/profiling.rb +1 -0
- data/lib/datadog/tracing/analytics.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb +2 -0
- data/lib/datadog/tracing/contrib/karafka/monitor.rb +1 -1
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +8 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +18 -1
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +17 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +9 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +5 -1
- data/lib/datadog/tracing/contrib/rack/request_queue.rb +1 -1
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
- data/lib/datadog/tracing/distributed/datadog.rb +2 -2
- data/lib/datadog/tracing/sampling/rate_sampler.rb +2 -1
- data/lib/datadog/tracing/span_event.rb +1 -1
- data/lib/datadog/tracing/span_operation.rb +38 -14
- data/lib/datadog/tracing/trace_operation.rb +15 -7
- data/lib/datadog/tracing/tracer.rb +7 -3
- data/lib/datadog/tracing/utils.rb +1 -1
- data/lib/datadog/version.rb +1 -1
- data/lib/datadog.rb +2 -3
- metadata +40 -10
- data/lib/datadog/core/telemetry/http/env.rb +0 -20
- data/lib/datadog/core/telemetry/http/ext.rb +0 -28
- data/lib/datadog/core/telemetry/http/response.rb +0 -70
- data/lib/datadog/core/telemetry/http/transport.rb +0 -90
@@ -0,0 +1,15 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#include "datadog_ruby_common.h"
|
4
|
+
#include "crashtracker.h"
|
5
|
+
#include "process_discovery.h"
|
6
|
+
#include "library_config.h"
|
7
|
+
|
8
|
+
void DDTRACE_EXPORT Init_libdatadog_api(void) {
|
9
|
+
VALUE datadog_module = rb_define_module("Datadog");
|
10
|
+
VALUE core_module = rb_define_module_under(datadog_module, "Core");
|
11
|
+
|
12
|
+
crashtracker_init(core_module);
|
13
|
+
process_discovery_init(core_module);
|
14
|
+
library_config_init(core_module);
|
15
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <datadog/library-config.h>
|
3
|
+
|
4
|
+
#include "library_config.h"
|
5
|
+
#include "datadog_ruby_common.h"
|
6
|
+
|
7
|
+
static VALUE _native_configurator_new(VALUE klass);
|
8
|
+
static VALUE _native_configurator_get(VALUE self);
|
9
|
+
|
10
|
+
static VALUE config_vec_class = Qnil;
|
11
|
+
|
12
|
+
// ddog_Configurator memory management
|
13
|
+
static void configurator_free(void *configurator_ptr) {
|
14
|
+
ddog_Configurator *configurator = (ddog_Configurator *)configurator_ptr;
|
15
|
+
|
16
|
+
ddog_library_configurator_drop(configurator);
|
17
|
+
}
|
18
|
+
|
19
|
+
static const rb_data_type_t configurator_typed_data = {
|
20
|
+
.wrap_struct_name = "Datadog::Core::Configuration::StableConfig::Configurator",
|
21
|
+
.function = {
|
22
|
+
.dfree = configurator_free,
|
23
|
+
.dsize = NULL,
|
24
|
+
},
|
25
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
26
|
+
};
|
27
|
+
|
28
|
+
// ddog_Vec_LibraryConfig memory management
|
29
|
+
static void config_vec_free(void *config_vec_ptr) {
|
30
|
+
ddog_Vec_LibraryConfig *config_vec = (ddog_Vec_LibraryConfig *)config_vec_ptr;
|
31
|
+
|
32
|
+
ddog_library_config_drop(*config_vec);
|
33
|
+
ruby_xfree(config_vec_ptr);
|
34
|
+
}
|
35
|
+
|
36
|
+
static const rb_data_type_t config_vec_typed_data = {
|
37
|
+
.wrap_struct_name = "Datadog::Core::Configuration::StableConfigVec",
|
38
|
+
.function = {
|
39
|
+
.dfree = config_vec_free,
|
40
|
+
.dsize = NULL,
|
41
|
+
},
|
42
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
43
|
+
};
|
44
|
+
|
45
|
+
void library_config_init(VALUE core_module) {
|
46
|
+
rb_global_variable(&config_vec_class);
|
47
|
+
VALUE configuration_module = rb_define_module_under(core_module, "Configuration");
|
48
|
+
VALUE stable_config_module = rb_define_module_under(configuration_module, "StableConfig");
|
49
|
+
VALUE configurator_class = rb_define_class_under(stable_config_module, "Configurator", rb_cObject);
|
50
|
+
config_vec_class = rb_define_class_under(configuration_module, "StableConfigVec", rb_cObject);
|
51
|
+
|
52
|
+
rb_define_alloc_func(configurator_class, _native_configurator_new);
|
53
|
+
rb_define_method(configurator_class, "get", _native_configurator_get, 0);
|
54
|
+
|
55
|
+
rb_undef_alloc_func(config_vec_class); // It cannot be created from Ruby code and only serves as an intermediate object for the Ruby GC
|
56
|
+
}
|
57
|
+
|
58
|
+
// TODO: After libdatadog 17.1 release, delete rb_raise, uncomment code and change `DDTRACE_UNUSED VALUE _klass` by `VALUE klass`
|
59
|
+
static VALUE _native_configurator_new(DDTRACE_UNUSED VALUE _klass) {
|
60
|
+
/*
|
61
|
+
ddog_Configurator *configurator = ddog_library_configurator_new(false, DDOG_CHARSLICE_C("ruby"));
|
62
|
+
|
63
|
+
ddog_library_configurator_with_detect_process_info(configurator);
|
64
|
+
|
65
|
+
return TypedData_Wrap_Struct(klass, &configurator_typed_data, configurator);
|
66
|
+
*/
|
67
|
+
|
68
|
+
rb_raise(rb_eNotImpError, "TODO: Not in use yet, waiting for libdatadog 17.1");
|
69
|
+
}
|
70
|
+
|
71
|
+
static VALUE _native_configurator_get(VALUE self) {
|
72
|
+
ddog_Configurator *configurator;
|
73
|
+
TypedData_Get_Struct(self, ddog_Configurator, &configurator_typed_data, configurator);
|
74
|
+
|
75
|
+
ddog_Result_VecLibraryConfig configurator_result = ddog_library_configurator_get(configurator);
|
76
|
+
|
77
|
+
if (configurator_result.tag == DDOG_RESULT_VEC_LIBRARY_CONFIG_ERR_VEC_LIBRARY_CONFIG) {
|
78
|
+
ddog_Error err = configurator_result.err;
|
79
|
+
VALUE message = get_error_details_and_drop(&err);
|
80
|
+
if (is_config_loaded()) {
|
81
|
+
log_warning(message);
|
82
|
+
} else {
|
83
|
+
log_warning_without_config(message);
|
84
|
+
}
|
85
|
+
return rb_hash_new();
|
86
|
+
}
|
87
|
+
|
88
|
+
// Wrapping config_vec into a Ruby object enables the Ruby GC to manage its memory
|
89
|
+
// We need to allocate memory for config_vec because once it is out of scope, it will be freed (at the end of this function)
|
90
|
+
// So we cannot reference it with &config_vec
|
91
|
+
// We are doing this in case one of the ruby API raises an exception before the end of this function,
|
92
|
+
// so the allocated memory will still be freed
|
93
|
+
ddog_Vec_LibraryConfig *config_vec = ruby_xmalloc(sizeof(ddog_Vec_LibraryConfig));
|
94
|
+
*config_vec = configurator_result.ok;
|
95
|
+
VALUE config_vec_rb = TypedData_Wrap_Struct(config_vec_class, &config_vec_typed_data, config_vec);
|
96
|
+
|
97
|
+
VALUE local_config_hash = rb_hash_new();
|
98
|
+
VALUE fleet_config_hash = rb_hash_new();
|
99
|
+
// TODO: Uncomment next block after libdatadog 17.1 release
|
100
|
+
/*
|
101
|
+
for (uintptr_t i = 0; i < config_vec->len; i++) {
|
102
|
+
ddog_LibraryConfig config = config_vec->ptr[i];
|
103
|
+
VALUE selected_hash;
|
104
|
+
if (config.source == DDOG_LIBRARY_CONFIG_SOURCE_LOCAL_STABLE_CONFIG) {
|
105
|
+
selected_hash = local_config_hash;
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
selected_hash = fleet_config_hash;
|
109
|
+
}
|
110
|
+
|
111
|
+
ddog_CStr name = ddog_library_config_name_to_env(config.name);
|
112
|
+
rb_hash_aset(selected_hash, rb_str_new(name.ptr, name.length), rb_str_new(config.value.ptr, config.value.length));
|
113
|
+
}
|
114
|
+
*/
|
115
|
+
|
116
|
+
VALUE result = rb_hash_new();
|
117
|
+
rb_hash_aset(result, ID2SYM(rb_intern("local")), local_config_hash);
|
118
|
+
rb_hash_aset(result, ID2SYM(rb_intern("fleet")), fleet_config_hash);
|
119
|
+
|
120
|
+
RB_GC_GUARD(config_vec_rb);
|
121
|
+
return result;
|
122
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "datadog_ruby_common.h"
|
4
|
+
|
5
|
+
void library_config_init(VALUE core_module);
|
6
|
+
|
7
|
+
static inline bool is_config_loaded(void) {
|
8
|
+
VALUE datadog_module = rb_const_get(rb_cObject, rb_intern("Datadog"));
|
9
|
+
VALUE is_config_loaded = rb_funcall(datadog_module, rb_intern("configuration?"), 0);
|
10
|
+
|
11
|
+
return is_config_loaded == Qtrue;
|
12
|
+
}
|
13
|
+
|
14
|
+
static inline VALUE log_warning_without_config(VALUE warning) {
|
15
|
+
VALUE datadog_module = rb_const_get(rb_cObject, rb_intern("Datadog"));
|
16
|
+
VALUE logger = rb_funcall(datadog_module, rb_intern("logger_without_configuration"), 0);
|
17
|
+
|
18
|
+
return rb_funcall(logger, rb_intern("warn"), 1, warning);
|
19
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#include <errno.h>
|
2
|
+
#include <stdlib.h>
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <datadog/common.h>
|
5
|
+
|
6
|
+
#include "datadog_ruby_common.h"
|
7
|
+
|
8
|
+
static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self);
|
9
|
+
static VALUE _native_to_rb_int(DDTRACE_UNUSED VALUE _self, VALUE tracer_memfd);
|
10
|
+
static VALUE _native_close_tracer_memfd(DDTRACE_UNUSED VALUE _self, VALUE tracer_memfd, VALUE logger);
|
11
|
+
|
12
|
+
static void tracer_memfd_free(void *ptr) {
|
13
|
+
int *fd = (int *)ptr;
|
14
|
+
if (*fd != -1) {
|
15
|
+
close(*fd);
|
16
|
+
}
|
17
|
+
ruby_xfree(ptr);
|
18
|
+
}
|
19
|
+
|
20
|
+
static const rb_data_type_t tracer_memfd_type = {
|
21
|
+
.wrap_struct_name = "Datadog::Core::ProcessDiscovery::TracerMemfd",
|
22
|
+
.function = {
|
23
|
+
.dfree = tracer_memfd_free,
|
24
|
+
.dsize = NULL,
|
25
|
+
},
|
26
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
27
|
+
};
|
28
|
+
|
29
|
+
void process_discovery_init(VALUE core_module) {
|
30
|
+
VALUE process_discovery_class = rb_define_class_under(core_module, "ProcessDiscovery", rb_cObject);
|
31
|
+
VALUE tracer_memfd_class = rb_define_class_under(process_discovery_class, "TracerMemfd", rb_cObject);
|
32
|
+
rb_undef_alloc_func(tracer_memfd_class); // Class cannot be instantiated from Ruby
|
33
|
+
|
34
|
+
rb_define_singleton_method(process_discovery_class, "_native_store_tracer_metadata", _native_store_tracer_metadata, -1);
|
35
|
+
rb_define_singleton_method(process_discovery_class, "_native_to_rb_int", _native_to_rb_int, 1);
|
36
|
+
rb_define_singleton_method(process_discovery_class, "_native_close_tracer_memfd", _native_close_tracer_memfd, 2);
|
37
|
+
}
|
38
|
+
|
39
|
+
// TODO: Remove DDTRACE_UNUSED and rename _self to self once we have updated libdatadog to 17.1
|
40
|
+
static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self) {
|
41
|
+
VALUE logger;
|
42
|
+
VALUE options;
|
43
|
+
rb_scan_args(argc, argv, "1:", &logger, &options);
|
44
|
+
if (options == Qnil) options = rb_hash_new();
|
45
|
+
|
46
|
+
VALUE schema_version = rb_hash_fetch(options, ID2SYM(rb_intern("schema_version")));
|
47
|
+
VALUE runtime_id = rb_hash_fetch(options, ID2SYM(rb_intern("runtime_id")));
|
48
|
+
VALUE tracer_language = rb_hash_fetch(options, ID2SYM(rb_intern("tracer_language")));
|
49
|
+
VALUE tracer_version = rb_hash_fetch(options, ID2SYM(rb_intern("tracer_version")));
|
50
|
+
VALUE hostname = rb_hash_fetch(options, ID2SYM(rb_intern("hostname")));
|
51
|
+
VALUE service_name = rb_hash_fetch(options, ID2SYM(rb_intern("service_name")));
|
52
|
+
VALUE service_env = rb_hash_fetch(options, ID2SYM(rb_intern("service_env")));
|
53
|
+
VALUE service_version = rb_hash_fetch(options, ID2SYM(rb_intern("service_version")));
|
54
|
+
|
55
|
+
ENFORCE_TYPE(schema_version, T_FIXNUM);
|
56
|
+
ENFORCE_TYPE(runtime_id, T_STRING);
|
57
|
+
ENFORCE_TYPE(tracer_language, T_STRING);
|
58
|
+
ENFORCE_TYPE(tracer_version, T_STRING);
|
59
|
+
ENFORCE_TYPE(hostname, T_STRING);
|
60
|
+
ENFORCE_TYPE(service_name, T_STRING);
|
61
|
+
ENFORCE_TYPE(service_env, T_STRING);
|
62
|
+
ENFORCE_TYPE(service_version, T_STRING);
|
63
|
+
|
64
|
+
/*
|
65
|
+
ddog_Result_TracerMemfdHandle result = ddog_store_tracer_metadata(
|
66
|
+
(uint8_t) NUM2UINT(schema_version),
|
67
|
+
char_slice_from_ruby_string(runtime_id),
|
68
|
+
char_slice_from_ruby_string(tracer_language),
|
69
|
+
char_slice_from_ruby_string(tracer_version),
|
70
|
+
char_slice_from_ruby_string(hostname),
|
71
|
+
char_slice_from_ruby_string(service_name),
|
72
|
+
char_slice_from_ruby_string(service_env),
|
73
|
+
char_slice_from_ruby_string(service_version)
|
74
|
+
);
|
75
|
+
|
76
|
+
if (result.tag == DDOG_RESULT_TRACER_MEMFD_HANDLE_ERR_TRACER_MEMFD_HANDLE) {
|
77
|
+
rb_funcall(logger, rb_intern("debug"), 1, rb_sprintf("Failed to store the tracer configuration in a memory file descriptor: %"PRIsVALUE, get_error_details_and_drop(&result.err)));
|
78
|
+
return Qnil;
|
79
|
+
}
|
80
|
+
|
81
|
+
// &result.ok is a ddog_TracerMemfdHandle, which is a struct only containing int fd, which is a file descriptor
|
82
|
+
// We should just return the fd
|
83
|
+
int *fd = ruby_xmalloc(sizeof(int));
|
84
|
+
|
85
|
+
*fd = result.ok.fd;
|
86
|
+
VALUE tracer_memfd_class = rb_const_get(self, rb_intern("TracerMemfd"));
|
87
|
+
VALUE tracer_memfd = TypedData_Wrap_Struct(tracer_memfd_class, &tracer_memfd_type, fd);
|
88
|
+
return tracer_memfd;
|
89
|
+
*/
|
90
|
+
|
91
|
+
rb_raise(rb_eNotImpError, "TODO: Not in use yet, waiting for libdatadog 17.1");
|
92
|
+
}
|
93
|
+
|
94
|
+
static VALUE _native_to_rb_int(DDTRACE_UNUSED VALUE _self, VALUE tracer_memfd) {
|
95
|
+
int *fd;
|
96
|
+
TypedData_Get_Struct(tracer_memfd, int, &tracer_memfd_type, fd);
|
97
|
+
return INT2NUM(*fd);
|
98
|
+
}
|
99
|
+
|
100
|
+
static VALUE _native_close_tracer_memfd(DDTRACE_UNUSED VALUE _self, VALUE tracer_memfd, VALUE logger) {
|
101
|
+
int *fd;
|
102
|
+
TypedData_Get_Struct(tracer_memfd, int, &tracer_memfd_type, fd);
|
103
|
+
if (*fd == -1) {
|
104
|
+
rb_funcall(logger, rb_intern("debug"), 1, rb_sprintf("The tracer configuration memory file descriptor has already been closed"));
|
105
|
+
return Qnil;
|
106
|
+
}
|
107
|
+
|
108
|
+
int close_result = close(*fd);
|
109
|
+
*fd = -1;
|
110
|
+
|
111
|
+
if (close_result == -1) {
|
112
|
+
rb_funcall(logger, rb_intern("debug"), 1, rb_sprintf("Failed to close the tracer configuration memory file descriptor: %s", strerror(errno)));
|
113
|
+
return Qnil;
|
114
|
+
}
|
115
|
+
|
116
|
+
return Qnil;
|
117
|
+
}
|
@@ -33,7 +33,7 @@ module Datadog
|
|
33
33
|
event_category = Ext::EXPLOIT_PREVENTION_EVENT_CATEGORY
|
34
34
|
tag_key = Ext::TAG_METASTRUCT_STACK_TRACE
|
35
35
|
|
36
|
-
existing_stack_data = active_span.get_metastruct_tag(tag_key).dup || {
|
36
|
+
existing_stack_data = active_span.get_metastruct_tag(tag_key).dup || {event_category => []}
|
37
37
|
max_stack_traces = Datadog.configuration.appsec.stack_trace.max_stack_traces
|
38
38
|
return if max_stack_traces != 0 && existing_stack_data[event_category].count >= max_stack_traces
|
39
39
|
|
@@ -42,7 +42,8 @@ module Datadog
|
|
42
42
|
active_span.set_metastruct_tag(tag_key, existing_stack_data)
|
43
43
|
end
|
44
44
|
|
45
|
-
def generate_schema(_action_params)
|
45
|
+
def generate_schema(_action_params)
|
46
|
+
end
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -1,7 +1,52 @@
|
|
1
|
-
|
1
|
+
AppSec WAF rules based on [appsec-event-rules](https://github.com/datadog/appsec-event-rules) builds
|
2
2
|
|
3
|
-
|
4
|
-
these rules.
|
3
|
+
## How to update
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
> [!WARNING]
|
6
|
+
> This process is a temporary workaround to maintain compatibility with the existing code structure and will be changed.
|
7
|
+
|
8
|
+
1. Download `recommended.json` and `strict.json` of the desired version from [appsec-event-rules](https://github.com/datadog/appsec-event-rules) (example: [v1.13.3](https://github.com/DataDog/appsec-event-rules/tree/1.13.3/build))
|
9
|
+
2. Run the script below inside `waf_rules` folder to extract scanners and processors into separate files
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
recommended_rules = JSON.parse(File.read(File.expand_path('recommended.json', __dir__)))
|
15
|
+
strict_rules = JSON.parse(File.read(File.expand_path('strict.json', __dir__)))
|
16
|
+
|
17
|
+
recommended_processors = recommended_rules.delete('processors')
|
18
|
+
strict_processors = strict_rules.delete('processors')
|
19
|
+
|
20
|
+
if recommended_processors.sort_by { |processor| processor['id'] } !=
|
21
|
+
strict_processors.sort_by { |processor| processor['id'] }
|
22
|
+
raise 'Processors are not the same, unable to extract them'
|
23
|
+
end
|
24
|
+
|
25
|
+
puts 'Extracting processors...'
|
26
|
+
File.open(File.expand_path('processors.json', __dir__), 'wb') do |file|
|
27
|
+
file.write(JSON.pretty_generate(recommended_processors))
|
28
|
+
end
|
29
|
+
|
30
|
+
recommended_scanners = recommended_rules.delete('scanners')
|
31
|
+
strict_scanners = strict_rules.delete('scanners')
|
32
|
+
|
33
|
+
if recommended_scanners.sort_by { |processor| processor['id'] } !=
|
34
|
+
strict_scanners.sort_by { |processor| processor['id'] }
|
35
|
+
raise 'Scanners are not the same, unable to extract them'
|
36
|
+
end
|
37
|
+
|
38
|
+
puts 'Extracting scanners...'
|
39
|
+
File.open(File.expand_path('scanners.json', __dir__), 'wb') do |file|
|
40
|
+
file.write(JSON.pretty_generate(recommended_scanners))
|
41
|
+
end
|
42
|
+
|
43
|
+
puts 'Updating rules...'
|
44
|
+
|
45
|
+
File.open(File.expand_path('recommended.json', __dir__), 'wb') do |file|
|
46
|
+
file.write(JSON.pretty_generate(recommended_rules))
|
47
|
+
end
|
48
|
+
|
49
|
+
File.open(File.expand_path('strict.json', __dir__), 'wb') do |file|
|
50
|
+
file.write(JSON.pretty_generate(strict_rules))
|
51
|
+
end
|
52
|
+
```
|
@@ -1,6 +1,57 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
|
-
"id": "
|
3
|
+
"id": "http-endpoint-fingerprint",
|
4
|
+
"generator": "http_endpoint_fingerprint",
|
5
|
+
"conditions": [
|
6
|
+
{
|
7
|
+
"operator": "exists",
|
8
|
+
"parameters": {
|
9
|
+
"inputs": [
|
10
|
+
{
|
11
|
+
"address": "waf.context.event"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"address": "server.business_logic.users.login.failure"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"address": "server.business_logic.users.login.success"
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"parameters": {
|
24
|
+
"mappings": [
|
25
|
+
{
|
26
|
+
"method": [
|
27
|
+
{
|
28
|
+
"address": "server.request.method"
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"uri_raw": [
|
32
|
+
{
|
33
|
+
"address": "server.request.uri.raw"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"body": [
|
37
|
+
{
|
38
|
+
"address": "server.request.body"
|
39
|
+
}
|
40
|
+
],
|
41
|
+
"query": [
|
42
|
+
{
|
43
|
+
"address": "server.request.query"
|
44
|
+
}
|
45
|
+
],
|
46
|
+
"output": "_dd.appsec.fp.http.endpoint"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
},
|
50
|
+
"evaluate": false,
|
51
|
+
"output": true
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"id": "extract-content",
|
4
55
|
"generator": "extract_schema",
|
5
56
|
"conditions": [
|
6
57
|
{
|
@@ -32,10 +83,10 @@
|
|
32
83
|
{
|
33
84
|
"inputs": [
|
34
85
|
{
|
35
|
-
"address": "server.request.
|
86
|
+
"address": "server.request.cookies"
|
36
87
|
}
|
37
88
|
],
|
38
|
-
"output": "_dd.appsec.s.req.
|
89
|
+
"output": "_dd.appsec.s.req.cookies"
|
39
90
|
},
|
40
91
|
{
|
41
92
|
"inputs": [
|
@@ -56,29 +107,89 @@
|
|
56
107
|
{
|
57
108
|
"inputs": [
|
58
109
|
{
|
59
|
-
"address": "server.
|
110
|
+
"address": "server.response.body"
|
60
111
|
}
|
61
112
|
],
|
62
|
-
"output": "_dd.appsec.s.
|
113
|
+
"output": "_dd.appsec.s.res.body"
|
63
114
|
},
|
64
115
|
{
|
65
116
|
"inputs": [
|
66
117
|
{
|
67
|
-
"address": "server.
|
118
|
+
"address": "graphql.server.all_resolvers"
|
68
119
|
}
|
69
120
|
],
|
70
|
-
"output": "_dd.appsec.s.
|
121
|
+
"output": "_dd.appsec.s.graphql.all_resolvers"
|
71
122
|
},
|
72
123
|
{
|
73
124
|
"inputs": [
|
74
125
|
{
|
75
|
-
"address": "server.
|
126
|
+
"address": "graphql.server.resolver"
|
76
127
|
}
|
77
128
|
],
|
78
|
-
"output": "_dd.appsec.s.
|
129
|
+
"output": "_dd.appsec.s.graphql.resolver"
|
130
|
+
}
|
131
|
+
],
|
132
|
+
"scanners": [
|
133
|
+
{
|
134
|
+
"tags": {
|
135
|
+
"category": "payment"
|
136
|
+
}
|
137
|
+
},
|
138
|
+
{
|
139
|
+
"tags": {
|
140
|
+
"category": "pii"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
]
|
144
|
+
},
|
145
|
+
"evaluate": false,
|
146
|
+
"output": true
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"id": "extract-headers",
|
150
|
+
"generator": "extract_schema",
|
151
|
+
"conditions": [
|
152
|
+
{
|
153
|
+
"operator": "equals",
|
154
|
+
"parameters": {
|
155
|
+
"inputs": [
|
156
|
+
{
|
157
|
+
"address": "waf.context.processor",
|
158
|
+
"key_path": [
|
159
|
+
"extract-schema"
|
160
|
+
]
|
161
|
+
}
|
162
|
+
],
|
163
|
+
"type": "boolean",
|
164
|
+
"value": true
|
165
|
+
}
|
166
|
+
}
|
167
|
+
],
|
168
|
+
"parameters": {
|
169
|
+
"mappings": [
|
170
|
+
{
|
171
|
+
"inputs": [
|
172
|
+
{
|
173
|
+
"address": "server.request.headers.no_cookies"
|
174
|
+
}
|
175
|
+
],
|
176
|
+
"output": "_dd.appsec.s.req.headers"
|
177
|
+
},
|
178
|
+
{
|
179
|
+
"inputs": [
|
180
|
+
{
|
181
|
+
"address": "server.response.headers.no_cookies"
|
182
|
+
}
|
183
|
+
],
|
184
|
+
"output": "_dd.appsec.s.res.headers"
|
79
185
|
}
|
80
186
|
],
|
81
187
|
"scanners": [
|
188
|
+
{
|
189
|
+
"tags": {
|
190
|
+
"category": "credentials"
|
191
|
+
}
|
192
|
+
},
|
82
193
|
{
|
83
194
|
"tags": {
|
84
195
|
"category": "pii"
|
@@ -88,5 +199,123 @@
|
|
88
199
|
},
|
89
200
|
"evaluate": false,
|
90
201
|
"output": true
|
202
|
+
},
|
203
|
+
{
|
204
|
+
"id": "http-header-fingerprint",
|
205
|
+
"generator": "http_header_fingerprint",
|
206
|
+
"conditions": [
|
207
|
+
{
|
208
|
+
"operator": "exists",
|
209
|
+
"parameters": {
|
210
|
+
"inputs": [
|
211
|
+
{
|
212
|
+
"address": "waf.context.event"
|
213
|
+
},
|
214
|
+
{
|
215
|
+
"address": "server.business_logic.users.login.failure"
|
216
|
+
},
|
217
|
+
{
|
218
|
+
"address": "server.business_logic.users.login.success"
|
219
|
+
}
|
220
|
+
]
|
221
|
+
}
|
222
|
+
}
|
223
|
+
],
|
224
|
+
"parameters": {
|
225
|
+
"mappings": [
|
226
|
+
{
|
227
|
+
"headers": [
|
228
|
+
{
|
229
|
+
"address": "server.request.headers.no_cookies"
|
230
|
+
}
|
231
|
+
],
|
232
|
+
"output": "_dd.appsec.fp.http.header"
|
233
|
+
}
|
234
|
+
]
|
235
|
+
},
|
236
|
+
"evaluate": false,
|
237
|
+
"output": true
|
238
|
+
},
|
239
|
+
{
|
240
|
+
"id": "http-network-fingerprint",
|
241
|
+
"generator": "http_network_fingerprint",
|
242
|
+
"conditions": [
|
243
|
+
{
|
244
|
+
"operator": "exists",
|
245
|
+
"parameters": {
|
246
|
+
"inputs": [
|
247
|
+
{
|
248
|
+
"address": "waf.context.event"
|
249
|
+
},
|
250
|
+
{
|
251
|
+
"address": "server.business_logic.users.login.failure"
|
252
|
+
},
|
253
|
+
{
|
254
|
+
"address": "server.business_logic.users.login.success"
|
255
|
+
}
|
256
|
+
]
|
257
|
+
}
|
258
|
+
}
|
259
|
+
],
|
260
|
+
"parameters": {
|
261
|
+
"mappings": [
|
262
|
+
{
|
263
|
+
"headers": [
|
264
|
+
{
|
265
|
+
"address": "server.request.headers.no_cookies"
|
266
|
+
}
|
267
|
+
],
|
268
|
+
"output": "_dd.appsec.fp.http.network"
|
269
|
+
}
|
270
|
+
]
|
271
|
+
},
|
272
|
+
"evaluate": false,
|
273
|
+
"output": true
|
274
|
+
},
|
275
|
+
{
|
276
|
+
"id": "session-fingerprint",
|
277
|
+
"generator": "session_fingerprint",
|
278
|
+
"conditions": [
|
279
|
+
{
|
280
|
+
"operator": "exists",
|
281
|
+
"parameters": {
|
282
|
+
"inputs": [
|
283
|
+
{
|
284
|
+
"address": "waf.context.event"
|
285
|
+
},
|
286
|
+
{
|
287
|
+
"address": "server.business_logic.users.login.failure"
|
288
|
+
},
|
289
|
+
{
|
290
|
+
"address": "server.business_logic.users.login.success"
|
291
|
+
}
|
292
|
+
]
|
293
|
+
}
|
294
|
+
}
|
295
|
+
],
|
296
|
+
"parameters": {
|
297
|
+
"mappings": [
|
298
|
+
{
|
299
|
+
"cookies": [
|
300
|
+
{
|
301
|
+
"address": "server.request.cookies"
|
302
|
+
}
|
303
|
+
],
|
304
|
+
"session_id": [
|
305
|
+
{
|
306
|
+
"address": "usr.session_id"
|
307
|
+
}
|
308
|
+
],
|
309
|
+
"user_id": [
|
310
|
+
{
|
311
|
+
"address": "usr.id"
|
312
|
+
}
|
313
|
+
],
|
314
|
+
"output": "_dd.appsec.fp.session"
|
315
|
+
}
|
316
|
+
]
|
317
|
+
},
|
318
|
+
"evaluate": false,
|
319
|
+
"output": true
|
91
320
|
}
|
92
|
-
]
|
321
|
+
]
|