-
Notifications
You must be signed in to change notification settings - Fork 394
[APPSEC-8112] Appsec allow to set user id denylist #2612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a7f13b4
65eabdb
ecf17ad
36aaf27
296b62b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -40,6 +40,10 @@ def ip_denylist=(value) | |||||
options[:ip_denylist] = value | ||||||
end | ||||||
|
||||||
def user_id_denylist=(value) | ||||||
options[:user_id_denylist] = value | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should rather resolve to a default here:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that. That way the setting of sane defaults happen at the right layer 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
end | ||||||
|
||||||
# in microseconds | ||||||
def waf_timeout=(value) | ||||||
options[:waf_timeout] = value | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,14 +44,15 @@ def finalize | |
def initialize | ||
@ruleset_info = nil | ||
@addresses = [] | ||
settings = Datadog::AppSec.settings | ||
|
||
unless load_libddwaf && load_ruleset && create_waf_handle | ||
unless load_libddwaf && load_ruleset(settings) && create_waf_handle(settings) | ||
Datadog.logger.warn { 'AppSec is disabled, see logged errors above' } | ||
|
||
return | ||
end | ||
|
||
update_ip_denylist | ||
apply_denylist_data(settings) | ||
end | ||
|
||
def ready? | ||
|
@@ -70,20 +71,6 @@ def toggle_rules(map) | |
@handle.toggle_rules(map) | ||
end | ||
|
||
def update_ip_denylist(denylist = Datadog::AppSec.settings.ip_denylist, id: 'blocked_ips') | ||
denylist ||= [] | ||
|
||
ruledata_setting = [ | ||
{ | ||
'id' => id, | ||
'type' => 'data_with_expiration', | ||
'data' => denylist.map { |ip| { 'value' => ip.to_s, 'expiration' => 2**63 } } | ||
} | ||
] | ||
|
||
update_rule_data(ruledata_setting) | ||
end | ||
|
||
def finalize | ||
@handle.finalize | ||
end | ||
|
@@ -94,12 +81,28 @@ def finalize | |
|
||
private | ||
|
||
def apply_denylist_data(settings) | ||
ruledata_setting = [] | ||
ruledata_setting << denylist_data('blocked_ips', settings.ip_denylist) | ||
ruledata_setting << denylist_data('blocked_users', settings.user_id_denylist) | ||
|
||
update_rule_data(ruledata_setting) | ||
end | ||
|
||
def denylist_data(id, denylist) | ||
{ | ||
'id' => id, | ||
'type' => 'data_with_expiration', | ||
'data' => denylist.map { |v| { 'value' => v.to_s, 'expiration' => 2**63 } } | ||
} | ||
end | ||
|
||
def load_libddwaf | ||
Processor.require_libddwaf && Processor.libddwaf_provides_waf? | ||
end | ||
|
||
def load_ruleset | ||
ruleset_setting = Datadog::AppSec.settings.ruleset | ||
def load_ruleset(settings) | ||
ruleset_setting = settings.ruleset | ||
|
||
begin | ||
@ruleset = case ruleset_setting | ||
|
@@ -132,13 +135,13 @@ def load_ruleset | |
end | ||
end | ||
|
||
def create_waf_handle | ||
def create_waf_handle(settings) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. I think this also makes it more testable |
||
# TODO: this may need to be reset if the main Datadog logging level changes after initialization | ||
Datadog::AppSec::WAF.logger = Datadog.logger if Datadog.logger.debug? && Datadog::AppSec.settings.waf_debug | ||
Datadog::AppSec::WAF.logger = Datadog.logger if Datadog.logger.debug? && settings.waf_debug | ||
|
||
obfuscator_config = { | ||
key_regex: Datadog::AppSec.settings.obfuscator_key_regex, | ||
value_regex: Datadog::AppSec.settings.obfuscator_value_regex, | ||
key_regex: settings.obfuscator_key_regex, | ||
value_regex: settings.obfuscator_value_regex, | ||
} | ||
@handle = Datadog::AppSec::WAF::Handle.new(@ruleset, obfuscator: obfuscator_config) | ||
@ruleset_info = @handle.ruleset_info | ||
|
Uh oh!
There was an error while loading. Please reload this page.