-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exists operator and
waf.context.event
virtual address (#321)
- Loading branch information
Showing
12 changed files
with
338 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Unless explicitly stated otherwise all files in this repository are | ||
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2021 Datadog, Inc. | ||
|
||
#pragma once | ||
|
||
#include "condition/structured_condition.hpp" | ||
|
||
namespace ddwaf { | ||
|
||
class exists_condition : public base_impl<exists_condition> { | ||
public: | ||
static constexpr std::array<std::string_view, 1> param_names{"inputs"}; | ||
|
||
explicit exists_condition( | ||
std::vector<condition_parameter> args, const object_limits &limits = {}) | ||
: base_impl<exists_condition>(std::move(args), limits) | ||
{} | ||
|
||
protected: | ||
[[nodiscard]] eval_result eval_impl(const unary_argument<const ddwaf_object *> &input, | ||
condition_cache &cache, const exclusion::object_set_ref & /*objects_excluded*/, | ||
ddwaf::timer & /*deadline*/) const | ||
{ | ||
cache.match = {{{{"input", {}, input.address, {}}}, {}, "exists", {}, input.ephemeral}}; | ||
return {true, input.ephemeral}; | ||
} | ||
|
||
friend class base_impl<exists_condition>; | ||
}; | ||
|
||
} // namespace ddwaf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tests/integration/context/ruleset/context_event_address.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"version": "2.2", | ||
"metadata": { | ||
"rules_version": "1.8.0" | ||
}, | ||
"rules": [ | ||
{ | ||
"id": "rule1", | ||
"name": "rule1", | ||
"tags": { | ||
"type": "flow1", | ||
"category": "category1" | ||
}, | ||
"conditions": [ | ||
{ | ||
"parameters": { | ||
"inputs": [ | ||
{ | ||
"address": "waf.trigger" | ||
} | ||
], | ||
"regex": "rule" | ||
}, | ||
"operator": "match_regex" | ||
} | ||
] | ||
} | ||
], | ||
"processors": [ | ||
{ | ||
"id": "processor-001", | ||
"generator": "http_endpoint_fingerprint", | ||
"conditions": [ | ||
{ | ||
"operator": "exists", | ||
"parameters": { | ||
"inputs": [ | ||
{ | ||
"address": "waf.context.event" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"parameters": { | ||
"mappings": [ | ||
{ | ||
"method": [ | ||
{ | ||
"address": "server.request.method" | ||
} | ||
], | ||
"uri_raw": [ | ||
{ | ||
"address": "server.request.uri.raw" | ||
} | ||
], | ||
"body": [ | ||
{ | ||
"address": "server.request.body" | ||
} | ||
], | ||
"query": [ | ||
{ | ||
"address": "server.request.query" | ||
} | ||
], | ||
"output": "_dd.appsec.fp.http.endpoint" | ||
} | ||
] | ||
}, | ||
"evaluate": false, | ||
"output": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Unless explicitly stated otherwise all files in this repository are | ||
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2021 Datadog, Inc. | ||
|
||
#include "../test.hpp" | ||
#include "condition/exists.hpp" | ||
|
||
using namespace ddwaf; | ||
using namespace std::literals; | ||
|
||
namespace { | ||
|
||
template <typename... Args> std::vector<condition_parameter> gen_param_def(Args... addresses) | ||
{ | ||
return {{{{std::string{addresses}, get_target_index(addresses)}}}...}; | ||
} | ||
|
||
TEST(TestExistsCondition, AddressAvailable) | ||
{ | ||
exists_condition cond{{gen_param_def("server.request.uri_raw")}}; | ||
|
||
ddwaf_object tmp; | ||
ddwaf_object root; | ||
ddwaf_object_map(&root); | ||
ddwaf_object_map_add(&root, "server.request.uri_raw", ddwaf_object_invalid(&tmp)); | ||
|
||
object_store store; | ||
store.insert(root); | ||
|
||
ddwaf::timer deadline{2s}; | ||
condition_cache cache; | ||
auto res = cond.eval(cache, store, {}, {}, deadline); | ||
ASSERT_TRUE(res.outcome); | ||
} | ||
|
||
TEST(TestExistsCondition, AddressNotAvaialble) | ||
{ | ||
exists_condition cond{{gen_param_def("server.request.uri_raw")}}; | ||
|
||
ddwaf_object tmp; | ||
ddwaf_object root; | ||
ddwaf_object_map(&root); | ||
ddwaf_object_map_add(&root, "server.request.query", ddwaf_object_invalid(&tmp)); | ||
|
||
object_store store; | ||
store.insert(root); | ||
|
||
ddwaf::timer deadline{2s}; | ||
condition_cache cache; | ||
auto res = cond.eval(cache, store, {}, {}, deadline); | ||
ASSERT_FALSE(res.outcome); | ||
} | ||
|
||
} // namespace |
Oops, something went wrong.