33//
44// This product includes software developed at Datadog
55// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
6- #include " ../std_logging.hpp"
7- #include " ddwaf.h"
86#include < atomic>
97#include < chrono>
108#include < cstdlib>
1816#include < string_view>
1917
2018#include " ../json_helper.hpp"
19+ #include " ../std_logging.hpp"
2120#include " ../tags.hpp"
21+ #include " base64.h"
22+ #include " compression.hpp"
23+ #include " ddwaf.h"
2224#include " waf.hpp"
2325
2426namespace dds ::waf {
@@ -39,11 +41,6 @@ dds::subscriber::event format_waf_result(ddwaf_result &res)
3941 output.data .emplace_back (std::move (parameter_to_json (event)));
4042 }
4143
42- const parameter_view schemas{res.derivatives };
43- for (const auto &schema : schemas) {
44- output.schemas .emplace (
45- schema.key (), std::move (parameter_to_json (schema)));
46- }
4744 } catch (const std::exception &e) {
4845 SPDLOG_ERROR (" failed to parse WAF output: {}" , e.what ());
4946 }
@@ -209,6 +206,11 @@ std::optional<subscriber::event> instance::listener::call(
209206 // NOLINTNEXTLINE
210207 total_runtime_ += res.total_runtime / 1000.0 ;
211208
209+ const parameter_view schemas{res.derivatives };
210+ for (const auto &schema : schemas) {
211+ schemas_.emplace (schema.key (), std::move (parameter_to_json (schema)));
212+ }
213+
212214 switch (code) {
213215 case DDWAF_MATCH:
214216 return format_waf_result (res);
@@ -236,6 +238,20 @@ void instance::listener::get_meta_and_metrics(
236238{
237239 meta[std::string (tag::event_rules_version)] = ruleset_version_;
238240 metrics[tag::waf_duration] = total_runtime_;
241+
242+ for (const auto &[key, value] : schemas_) {
243+ std::string schema = value;
244+ if (value.length () > max_plain_schema_allowed) {
245+ auto encoded = compress (schema);
246+ if (encoded) {
247+ schema = base64_encode (encoded.value (), false );
248+ }
249+ }
250+
251+ if (schema.length () <= max_schema_size) {
252+ meta.emplace (key, std::move (schema));
253+ }
254+ }
239255}
240256
241257instance::instance (parameter &rule, std::map<std::string, std::string> &meta,
0 commit comments