Skip to content

Commit

Permalink
Fix ASM setting for automated user events.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GustavoCaso committed Aug 23, 2023
1 parent e1079ba commit f73885d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/datadog/appsec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.' \
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/appsec/configuration/settings.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/datadog/appsec/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f73885d

Please sign in to comment.