From f73885dfc8a1d9d67996834f0e1e6a94f6cf2b6c Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 23 Aug 2023 17:26:14 +0200 Subject: [PATCH] Fix ASM setting for automated user events. The automated user events feature has two settings: enable and mode. Both can be configured via code or using a single ENV var: DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING The corner case found is that setting DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING=extended|safe is disabling automated user events. This PR ensures the enabled setting supports extended and safe as valid values. --- lib/datadog/appsec/configuration/settings.rb | 8 +++++++- sig/datadog/appsec/configuration/settings.rbs | 1 + spec/datadog/appsec/configuration/settings_spec.rb | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/datadog/appsec/configuration/settings.rb b/lib/datadog/appsec/configuration/settings.rb index b54a753fad..867ef19c10 100644 --- a/lib/datadog/appsec/configuration/settings.rb +++ b/lib/datadog/appsec/configuration/settings.rb @@ -15,6 +15,10 @@ module Settings 'safe', 'extended' ].freeze + APPSEC_VALID_TRACK_USER_EVENTS_ENABLED_VALUES = [ + '1', + 'true' + ].concat(APPSEC_VALID_TRACK_USER_EVENTS_MODE).freeze def self.extended(base) base = base.singleton_class unless base.is_a?(Class) @@ -100,7 +104,7 @@ def self.add_settings!(base) if env_value == 'disabled' false else - ['1', 'true'].include?(env_value.strip.downcase) + APPSEC_VALID_TRACK_USER_EVENTS_ENABLED_VALUES.include?(env_value.strip.downcase) end end end @@ -112,6 +116,8 @@ def self.add_settings!(base) o.setter do |v| if APPSEC_VALID_TRACK_USER_EVENTS_MODE.include?(v) v + elsif v == 'disabled' + 'safe' else Datadog.logger.warn( 'The appsec.track_user_events.mode value provided is not supported.' \ diff --git a/sig/datadog/appsec/configuration/settings.rbs b/sig/datadog/appsec/configuration/settings.rbs index 54a00e7448..0d069ec4de 100644 --- a/sig/datadog/appsec/configuration/settings.rbs +++ b/sig/datadog/appsec/configuration/settings.rbs @@ -12,6 +12,7 @@ module Datadog DEFAULT_OBFUSCATOR_KEY_REGEX: ::String DEFAULT_OBFUSCATOR_VALUE_REGEX: ::String APPSEC_VALID_TRACK_USER_EVENTS_MODE: ::Array[String] + APPSEC_VALID_TRACK_USER_EVENTS_ENABLED_VALUES: ::Array[String] def self.extended: (untyped base) -> untyped diff --git a/spec/datadog/appsec/configuration/settings_spec.rb b/spec/datadog/appsec/configuration/settings_spec.rb index 18ffdb5b3d..b3e7e87239 100644 --- a/spec/datadog/appsec/configuration/settings_spec.rb +++ b/spec/datadog/appsec/configuration/settings_spec.rb @@ -475,6 +475,14 @@ def patcher it { is_expected.to eq(false) } end + + context 'using the mode values: extended | safe' do + ['extended', 'safe'].each do |value| + let(:track_user_events_enabled) { value } + + it { is_expected.to eq(true) } + end + end end end end