Skip to content
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

skip passing waf addresses when the value is empty #3188

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/datadog/appsec/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)

start_ns = Core::Utils::Time.get_time(:nanosecond)

input.reject! do |_, v|
case v
when TrueClass, FalseClass
false
else
v.nil? ? true : v.empty?
end
end

_code, res = @context.run(input, timeout)

stop_ns = Core::Utils::Time.get_time(:nanosecond)
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/appsec/processor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Datadog
@run_mutex: ::Thread::Mutex

def initialize: (Processor processor) -> void
def run: (data input, ?::Integer timeout) -> WAF::Result
def run: (Hash[untyped, untyped] input, ?::Integer timeout) -> WAF::Result
def extract_schema: () -> WAF::Result?
def finalize: () -> void

Expand Down
74 changes: 74 additions & 0 deletions spec/datadog/appsec/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,80 @@
matches.map(&:actions)
end

context 'clear key with empty values' do
it 'removes nil values' do
input = {
'nil_value' => nil,
'string_value' => 'hello'
}
expect(context.instance_variable_get(:@context)).to receive(:run).with(
{
'string_value' => 'hello'
},
timeout
).and_call_original

context.run(input, timeout)
end

it 'do not removes boolean values' do
input = {
'false_value' => false,
'true_value' => true
}
expect(context.instance_variable_get(:@context)).to receive(:run).with(
input, timeout
).and_call_original

context.run(input, timeout)
end

it 'removes empty string values' do
input = {
'empty_string_value' => '',
'string_value' => 'hello'
}
expect(context.instance_variable_get(:@context)).to receive(:run).with(
{
'string_value' => 'hello'
},
timeout
).and_call_original

context.run(input, timeout)
end

it 'removes empty arrays values' do
input = {
'empty_array' => [],
'non_empty_array_value' => [1, 2],
}
expect(context.instance_variable_get(:@context)).to receive(:run).with(
{
'non_empty_array_value' => [1, 2]
},
timeout
).and_call_original

context.run(input, timeout)
end

it 'removes empty hash values' do
input = {
'empty_hash' => {},
'non_empty_hash_value' => { 'hello' => 'world' },
}
expect(context.instance_variable_get(:@context)).to receive(:run).with(
{
'non_empty_hash_value' => { 'hello' => 'world' }
},
timeout
).and_call_original

context.run(input, timeout)
end
end

context 'no attack' do
let(:input) { input_safe }

Expand Down
Loading