libddwaf 1.0.12.0.0.beta1-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +6 -0
- data/LICENSE-3rdparty.csv +2 -0
- data/LICENSE.Apache +200 -0
- data/LICENSE.BSD3 +24 -0
- data/NOTICE +4 -0
- data/lib/datadog/security/waf/version.rb +12 -0
- data/lib/datadog/security/waf.rb +402 -0
- data/lib/libddwaf.rb +1 -0
- data/vendor/libddwaf/libddwaf-1.0.12-linux-x86_64/include/ddwaf.h +486 -0
- data/vendor/libddwaf/libddwaf-1.0.12-linux-x86_64/lib/libddwaf.so +0 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dab12980ca6c95ec58d821288140619a2d17f84b433fb497ab796ec0ef04f021
|
4
|
+
data.tar.gz: e14881741eddcb4a472c8ce8642158b5ff0efaa37e9b74dd986f2473a467d301
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c3193bbaa560bece066b05fb549c1715b0a15305e298baf00fb1cf916d1c5324fc4c9d68e1c20d3361013eab0538d99754c747eac2262cd6ce5dba7120eb485
|
7
|
+
data.tar.gz: d9f44ab78c539a7cd3a33d9e5ab04f26b3146f7adbdd81316cc7c2653a8a1dc2f50db53c0817be2d079eb41724243f1fe959fb3ed0ae38fe0d48f943a9d85cbe
|
data/LICENSE
ADDED
data/LICENSE.Apache
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2021 Datadog, Inc.
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
191
|
+
you may not use this file except in compliance with the License.
|
192
|
+
You may obtain a copy of the License at
|
193
|
+
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
195
|
+
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
199
|
+
See the License for the specific language governing permissions and
|
200
|
+
limitations under the License.
|
data/LICENSE.BSD3
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2021, Datadog <info@datadoghq.com>
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of Datadog nor the
|
12
|
+
names of its contributors may be used to endorse or promote products
|
13
|
+
derived from this software without specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/NOTICE
ADDED
@@ -0,0 +1,402 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'json'
|
3
|
+
require 'datadog/security/waf/version'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Security
|
7
|
+
module WAF
|
8
|
+
module LibDDWAF
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
extend ::FFI::Library
|
12
|
+
|
13
|
+
def self.local_os
|
14
|
+
if RUBY_ENGINE == 'jruby'
|
15
|
+
os_name = java.lang.System.get_property('os.name')
|
16
|
+
|
17
|
+
os = case os_name
|
18
|
+
when /linux/i then 'linux'
|
19
|
+
when /mac/i then 'darwin'
|
20
|
+
else raise Error, "unsupported JRuby os.name: #{os_name.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
return os
|
24
|
+
end
|
25
|
+
|
26
|
+
Gem::Platform.local.os
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.local_cpu
|
30
|
+
if RUBY_ENGINE == 'jruby'
|
31
|
+
os_arch = java.lang.System.get_property('os.arch')
|
32
|
+
|
33
|
+
cpu = case os_arch
|
34
|
+
when 'amd64' then 'x86_64'
|
35
|
+
else raise Error, "unsupported JRuby os.arch: #{os_arch.inspect}"
|
36
|
+
end
|
37
|
+
|
38
|
+
return cpu
|
39
|
+
end
|
40
|
+
|
41
|
+
Gem::Platform.local.cpu
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.shared_lib_extname
|
45
|
+
Gem::Platform.local.os == 'darwin' ? '.dylib' : '.so'
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.shared_lib_path
|
49
|
+
File.join(__dir__, "../../../vendor/libddwaf/libddwaf-#{Datadog::Security::WAF::VERSION::BASE_STRING}-#{local_os}-#{local_cpu}/lib/libddwaf#{shared_lib_extname}")
|
50
|
+
end
|
51
|
+
|
52
|
+
ffi_lib [shared_lib_path]
|
53
|
+
|
54
|
+
# version
|
55
|
+
|
56
|
+
class Version < ::FFI::Struct
|
57
|
+
layout :major, :uint16,
|
58
|
+
:minor, :uint16,
|
59
|
+
:patch, :uint16
|
60
|
+
end
|
61
|
+
|
62
|
+
typedef Version.by_ref, :ddwaf_version
|
63
|
+
|
64
|
+
attach_function :ddwaf_get_version, [:ddwaf_version], :void
|
65
|
+
|
66
|
+
# ddwaf::object data structure
|
67
|
+
|
68
|
+
DDWAF_OBJ_TYPE = enum :ddwaf_obj_invalid, 0,
|
69
|
+
:ddwaf_obj_signed, 1 << 0,
|
70
|
+
:ddwaf_obj_unsigned, 1 << 1,
|
71
|
+
:ddwaf_obj_string, 1 << 2,
|
72
|
+
:ddwaf_obj_array, 1 << 3,
|
73
|
+
:ddwaf_obj_map, 1 << 4
|
74
|
+
|
75
|
+
typedef :pointer, :charptr
|
76
|
+
|
77
|
+
class ObjectValueUnion < ::FFI::Union
|
78
|
+
layout :stringValue, :charptr,
|
79
|
+
:uintValue, :uint64,
|
80
|
+
:intValue, :int64,
|
81
|
+
:array, :pointer
|
82
|
+
end
|
83
|
+
|
84
|
+
class Object < ::FFI::Struct
|
85
|
+
layout :parameterName, :charptr,
|
86
|
+
:parameterNameLength, :uint64,
|
87
|
+
:valueUnion, ObjectValueUnion,
|
88
|
+
:nbEntries, :uint64,
|
89
|
+
:type, DDWAF_OBJ_TYPE
|
90
|
+
end
|
91
|
+
|
92
|
+
typedef Object.by_ref, :ddwaf_object
|
93
|
+
|
94
|
+
attach_function :ddwaf_object_invalid, [:ddwaf_object], :ddwaf_object
|
95
|
+
attach_function :ddwaf_object_string, [:ddwaf_object, :string], :ddwaf_object
|
96
|
+
attach_function :ddwaf_object_stringl, [:ddwaf_object, :charptr, :size_t], :ddwaf_object
|
97
|
+
attach_function :ddwaf_object_stringl_nc, [:ddwaf_object, :charptr, :size_t], :ddwaf_object
|
98
|
+
attach_function :ddwaf_object_unsigned, [:ddwaf_object, :uint64], :ddwaf_object
|
99
|
+
attach_function :ddwaf_object_signed, [:ddwaf_object, :int64], :ddwaf_object
|
100
|
+
attach_function :ddwaf_object_unsigned_force, [:ddwaf_object, :uint64], :ddwaf_object
|
101
|
+
attach_function :ddwaf_object_signed_force, [:ddwaf_object, :int64], :ddwaf_object
|
102
|
+
|
103
|
+
attach_function :ddwaf_object_array, [:ddwaf_object], :ddwaf_object
|
104
|
+
attach_function :ddwaf_object_array_add, [:ddwaf_object, :ddwaf_object], :bool
|
105
|
+
|
106
|
+
attach_function :ddwaf_object_map, [:ddwaf_object], :ddwaf_object
|
107
|
+
attach_function :ddwaf_object_map_add, [:ddwaf_object, :string, :pointer], :bool
|
108
|
+
attach_function :ddwaf_object_map_addl, [:ddwaf_object, :charptr, :size_t, :pointer], :bool
|
109
|
+
attach_function :ddwaf_object_map_addl_nc, [:ddwaf_object, :charptr, :size_t, :pointer], :bool
|
110
|
+
|
111
|
+
ObjectFree = attach_function :ddwaf_object_free, [:ddwaf_object], :void
|
112
|
+
ObjectNoFree = ::FFI::Pointer::NULL
|
113
|
+
|
114
|
+
# main handle
|
115
|
+
|
116
|
+
typedef :pointer, :ddwaf_handle
|
117
|
+
typedef Object.by_ref, :ddwaf_rule
|
118
|
+
|
119
|
+
class Config < ::FFI::Struct
|
120
|
+
layout :maxArrayLength, :uint64,
|
121
|
+
:maxMapDepth, :uint64,
|
122
|
+
:maxTimeStore, :uint64
|
123
|
+
end
|
124
|
+
|
125
|
+
typedef Config.by_ref, :ddwaf_config
|
126
|
+
|
127
|
+
attach_function :ddwaf_init, [:ddwaf_rule, :ddwaf_config], :ddwaf_handle
|
128
|
+
attach_function :ddwaf_destroy, [:ddwaf_handle], :void
|
129
|
+
|
130
|
+
# running
|
131
|
+
|
132
|
+
typedef :pointer, :ddwaf_context
|
133
|
+
|
134
|
+
callback :ddwaf_object_free_fn, [:ddwaf_object], :void
|
135
|
+
|
136
|
+
attach_function :ddwaf_context_init, [:ddwaf_handle, :ddwaf_object_free_fn], :ddwaf_context
|
137
|
+
attach_function :ddwaf_context_destroy, [:ddwaf_context], :void
|
138
|
+
|
139
|
+
|
140
|
+
DDWAF_RET_CODE = enum :ddwaf_err_internal, -4,
|
141
|
+
:ddwaf_err_invalid_object, -3,
|
142
|
+
:ddwaf_err_invalid_argument, -2,
|
143
|
+
:ddwaf_err_timeout, -1,
|
144
|
+
:ddwaf_good, 0,
|
145
|
+
:ddwaf_monitor, 1,
|
146
|
+
:ddwaf_block, 2
|
147
|
+
|
148
|
+
class Result < ::FFI::Struct
|
149
|
+
layout :action, DDWAF_RET_CODE,
|
150
|
+
:data, :string,
|
151
|
+
:perfData, :string,
|
152
|
+
:perfTotalRuntime, :uint32 # in us
|
153
|
+
end
|
154
|
+
|
155
|
+
typedef Result.by_ref, :ddwaf_result
|
156
|
+
typedef :uint64, :timeout_us
|
157
|
+
|
158
|
+
attach_function :ddwaf_run, [:ddwaf_context, :ddwaf_object, :ddwaf_result, :timeout_us], DDWAF_RET_CODE, blocking: true
|
159
|
+
attach_function :ddwaf_result_free, [:ddwaf_result], :void
|
160
|
+
|
161
|
+
# logging
|
162
|
+
|
163
|
+
DDWAF_LOG_LEVEL = enum :ddwaf_log_trace,
|
164
|
+
:ddwaf_log_debug,
|
165
|
+
:ddwaf_log_info,
|
166
|
+
:ddwaf_log_warn,
|
167
|
+
:ddwaf_log_error,
|
168
|
+
:ddwaf_log_off
|
169
|
+
|
170
|
+
callback :ddwaf_log_cb, [DDWAF_LOG_LEVEL, :string, :string, :uint, :charptr, :uint64], :void
|
171
|
+
|
172
|
+
attach_function :ddwaf_set_log_cb, [:ddwaf_log_cb, DDWAF_LOG_LEVEL], :bool
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.version
|
176
|
+
version = LibDDWAF::Version.new
|
177
|
+
LibDDWAF.ddwaf_get_version(version.pointer)
|
178
|
+
|
179
|
+
[version[:major], version[:minor], version[:patch]]
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.ruby_to_object(val)
|
183
|
+
case val
|
184
|
+
when Array
|
185
|
+
obj = LibDDWAF::Object.new
|
186
|
+
res = LibDDWAF.ddwaf_object_array(obj)
|
187
|
+
if res.null?
|
188
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
189
|
+
end
|
190
|
+
|
191
|
+
val.each do |e|
|
192
|
+
res = LibDDWAF.ddwaf_object_array_add(obj, ruby_to_object(e))
|
193
|
+
unless res
|
194
|
+
fail LibDDWAF::Error, "Could not add to map object: #{k.inspect} => #{v.inspect}"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
obj
|
199
|
+
when Hash
|
200
|
+
obj = LibDDWAF::Object.new
|
201
|
+
res = LibDDWAF.ddwaf_object_map(obj)
|
202
|
+
if res.null?
|
203
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
204
|
+
end
|
205
|
+
|
206
|
+
val.each do |k, v|
|
207
|
+
res = LibDDWAF.ddwaf_object_map_addl(obj, k.to_s, k.to_s.size, ruby_to_object(v))
|
208
|
+
unless res
|
209
|
+
fail LibDDWAF::Error, "Could not add to map object: #{k.inspect} => #{v.inspect}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
obj
|
214
|
+
when String
|
215
|
+
obj = LibDDWAF::Object.new
|
216
|
+
res = LibDDWAF.ddwaf_object_stringl(obj, val, val.size)
|
217
|
+
if res.null?
|
218
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
219
|
+
end
|
220
|
+
|
221
|
+
obj
|
222
|
+
when Symbol
|
223
|
+
obj = LibDDWAF::Object.new
|
224
|
+
res = LibDDWAF.ddwaf_object_stringl(obj, val.to_s, val.size)
|
225
|
+
if res.null?
|
226
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
227
|
+
end
|
228
|
+
|
229
|
+
obj
|
230
|
+
when Integer
|
231
|
+
obj = LibDDWAF::Object.new
|
232
|
+
res = LibDDWAF.ddwaf_object_string(obj, val.to_s)
|
233
|
+
if res.null?
|
234
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
235
|
+
end
|
236
|
+
|
237
|
+
obj
|
238
|
+
when Float
|
239
|
+
obj = LibDDWAF::Object.new
|
240
|
+
res = LibDDWAF.ddwaf_object_string(obj, val.to_s)
|
241
|
+
if res.null?
|
242
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
243
|
+
end
|
244
|
+
|
245
|
+
obj
|
246
|
+
when TrueClass, FalseClass
|
247
|
+
obj = LibDDWAF::Object.new
|
248
|
+
res = LibDDWAF.ddwaf_object_string(obj, val.to_s)
|
249
|
+
if res.null?
|
250
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
251
|
+
end
|
252
|
+
|
253
|
+
obj
|
254
|
+
else
|
255
|
+
obj = LibDDWAF::Object.new
|
256
|
+
res = LibDDWAF.ddwaf_object_invalid(obj)
|
257
|
+
if res.null?
|
258
|
+
fail LibDDWAF::Error, "Could not convert into object: #{val}"
|
259
|
+
end
|
260
|
+
|
261
|
+
obj
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def self.object_to_ruby(obj)
|
266
|
+
case obj[:type]
|
267
|
+
when :ddwaf_obj_invalid
|
268
|
+
nil
|
269
|
+
when :ddwaf_obj_string
|
270
|
+
obj[:valueUnion][:stringValue].read_bytes(obj[:nbEntries])
|
271
|
+
when :ddwaf_obj_signed
|
272
|
+
obj[:valueUnion][:intValue]
|
273
|
+
when :ddwaf_obj_unsigned
|
274
|
+
obj[:valueUnion][:uintValue]
|
275
|
+
when :ddwaf_obj_array
|
276
|
+
(0...obj[:nbEntries]).each.with_object([]) do |i, a|
|
277
|
+
ptr = obj[:valueUnion][:array] + i * LibDDWAF::Object.size
|
278
|
+
e = object_to_ruby(LibDDWAF::Object.new(ptr))
|
279
|
+
a << e
|
280
|
+
end
|
281
|
+
when :ddwaf_obj_map
|
282
|
+
(0...obj[:nbEntries]).each.with_object({}) do |i, h|
|
283
|
+
ptr = obj[:valueUnion][:array] + i * Datadog::Security::WAF::LibDDWAF::Object.size
|
284
|
+
o = Datadog::Security::WAF::LibDDWAF::Object.new(ptr)
|
285
|
+
l = o[:parameterNameLength]
|
286
|
+
k = o[:parameterName].read_bytes(l)
|
287
|
+
v = object_to_ruby(LibDDWAF::Object.new(ptr))
|
288
|
+
h[k] = v
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def self.logger=(logger)
|
294
|
+
@log_cb = proc do |level, func, file, line, message, len|
|
295
|
+
logger.debug { { level: level, func: func, file: file, message: message.read_bytes(len) }.inspect }
|
296
|
+
end
|
297
|
+
|
298
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_set_log_cb(@log_cb, :ddwaf_log_trace)
|
299
|
+
end
|
300
|
+
|
301
|
+
class Handle
|
302
|
+
attr_reader :handle_obj
|
303
|
+
|
304
|
+
DEFAULT_MAX_ARRAY_LENGTH = 0
|
305
|
+
DEFAULT_MAX_MAP_DEPTH = 0
|
306
|
+
DEFAULT_MAX_TIME_STORE = 0
|
307
|
+
|
308
|
+
def initialize(rule, config = {})
|
309
|
+
rule_obj = Datadog::Security::WAF.ruby_to_object(rule)
|
310
|
+
if rule_obj.null? || rule_obj[:type] == :ddwaf_object_invalid
|
311
|
+
fail LibDDWAF::Error, "Could not convert object #{rule.inspect}"
|
312
|
+
end
|
313
|
+
|
314
|
+
config_obj = Datadog::Security::WAF::LibDDWAF::Config.new
|
315
|
+
if config_obj.null?
|
316
|
+
fail LibDDWAF::Error, 'Could not create config struct'
|
317
|
+
end
|
318
|
+
|
319
|
+
config_obj[:maxArrayLength] = config[:max_array_length] || DEFAULT_MAX_ARRAY_LENGTH
|
320
|
+
config_obj[:maxMapDepth] = config[:max_map_depth] || DEFAULT_MAX_MAP_DEPTH
|
321
|
+
config_obj[:maxTimeStore] = config[:max_time_store] || DEFAULT_MAX_TIME_STORE
|
322
|
+
|
323
|
+
@handle_obj = Datadog::Security::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj)
|
324
|
+
if @handle_obj.null?
|
325
|
+
fail LibDDWAF::Error, 'Could not create handle'
|
326
|
+
end
|
327
|
+
|
328
|
+
ObjectSpace.define_finalizer(self, Handle.finalizer(handle_obj))
|
329
|
+
ensure
|
330
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj
|
331
|
+
end
|
332
|
+
|
333
|
+
def self.finalizer(handle_obj)
|
334
|
+
proc do |object_id|
|
335
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_destroy(handle_obj)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
Result = Struct.new(:action, :data, :perf_data, :perf_total_runtime)
|
341
|
+
|
342
|
+
class Context
|
343
|
+
attr_reader :context_obj
|
344
|
+
|
345
|
+
def initialize(handle)
|
346
|
+
handle_obj = handle.handle_obj
|
347
|
+
free_func = Datadog::Security::WAF::LibDDWAF::ObjectNoFree
|
348
|
+
|
349
|
+
@context_obj = Datadog::Security::WAF::LibDDWAF.ddwaf_context_init(handle_obj, free_func)
|
350
|
+
if @context_obj.null?
|
351
|
+
fail LibDDWAF::Error, 'Could not create context'
|
352
|
+
end
|
353
|
+
|
354
|
+
ObjectSpace.define_finalizer(self, Context.finalizer(context_obj))
|
355
|
+
end
|
356
|
+
|
357
|
+
def self.finalizer(context_obj)
|
358
|
+
proc do |object_id|
|
359
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_context_destroy(context_obj)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
DEFAULT_TIMEOUT_US = 10_0000
|
364
|
+
ACTION_MAP_OUT = {
|
365
|
+
ddwaf_err_internal: :err_internal,
|
366
|
+
ddwaf_err_invalid_object: :err_invalid_object,
|
367
|
+
ddwaf_err_invalid_argument: :err_invalid_argument,
|
368
|
+
ddwaf_err_timeout: :err_invalid_object,
|
369
|
+
ddwaf_good: :good,
|
370
|
+
ddwaf_monitor: :monitor,
|
371
|
+
ddwaf_block: :block,
|
372
|
+
}
|
373
|
+
|
374
|
+
def run(input, timeout = DEFAULT_TIMEOUT_US)
|
375
|
+
input_obj = Datadog::Security::WAF.ruby_to_object(input)
|
376
|
+
if input_obj.null?
|
377
|
+
fail LibDDWAF::Error, "Could not convert input: #{input.inspect}"
|
378
|
+
end
|
379
|
+
|
380
|
+
result_obj = Datadog::Security::WAF::LibDDWAF::Result.new
|
381
|
+
if result_obj.null?
|
382
|
+
fail LibDDWAF::Error, "Could not create result object"
|
383
|
+
end
|
384
|
+
|
385
|
+
code = Datadog::Security::WAF::LibDDWAF.ddwaf_run(@context_obj, input_obj, result_obj, timeout)
|
386
|
+
|
387
|
+
result = Result.new(
|
388
|
+
ACTION_MAP_OUT[result_obj[:action]],
|
389
|
+
(JSON.parse(result_obj[:data]) if result_obj[:data] != nil),
|
390
|
+
(JSON.parse(result_obj[:perfData]) if result_obj[:perfData] != nil),
|
391
|
+
result_obj[:perfTotalRuntime],
|
392
|
+
)
|
393
|
+
|
394
|
+
[ACTION_MAP_OUT[code], result]
|
395
|
+
ensure
|
396
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_object_free(input_obj) if input_obj
|
397
|
+
Datadog::Security::WAF::LibDDWAF.ddwaf_result_free(result_obj) if result_obj
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
end
|
data/lib/libddwaf.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'datadog/security/waf'
|
@@ -0,0 +1,486 @@
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are
|
2
|
+
// dual-licensed under the Apache-2.0 License or BSD-3-Clause License.
|
3
|
+
//
|
4
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
|
5
|
+
// Copyright 2021 Datadog, Inc.
|
6
|
+
|
7
|
+
#ifndef pw_h
|
8
|
+
#define pw_h
|
9
|
+
|
10
|
+
#ifdef __cplusplus
|
11
|
+
extern "C"
|
12
|
+
{
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#include <stdbool.h>
|
16
|
+
#include <stdint.h>
|
17
|
+
#include <stddef.h>
|
18
|
+
|
19
|
+
#define DDWAF_MAX_STRING_LENGTH 4096
|
20
|
+
#define DDWAF_MAX_MAP_DEPTH 20
|
21
|
+
#define DDWAF_MAX_ARRAY_LENGTH 256
|
22
|
+
#define DDWAF_RUN_TIMEOUT 5000
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @enum DDWAF_OBJ_TYPE
|
26
|
+
*
|
27
|
+
* Specifies the type of a ddwaf::object.
|
28
|
+
**/
|
29
|
+
typedef enum
|
30
|
+
{
|
31
|
+
DDWAF_OBJ_INVALID = 0,
|
32
|
+
/** Value shall be decoded as a int64_t (or int32_t on 32bits platforms). **/
|
33
|
+
DDWAF_OBJ_SIGNED = 1 << 0,
|
34
|
+
/** Value shall be decoded as a uint64_t (or uint32_t on 32bits platforms). **/
|
35
|
+
DDWAF_OBJ_UNSIGNED = 1 << 1,
|
36
|
+
/** Value shall be decoded as a UTF-8 string of length nbEntries. **/
|
37
|
+
DDWAF_OBJ_STRING = 1 << 2,
|
38
|
+
/** Value shall be decoded as an array of ddwaf_object of length nbEntries, each item having no parameterName. **/
|
39
|
+
DDWAF_OBJ_ARRAY = 1 << 3,
|
40
|
+
/** Value shall be decoded as an array of ddwaf_object of length nbEntries, each item having a parameterName. **/
|
41
|
+
DDWAF_OBJ_MAP = 1 << 4,
|
42
|
+
} DDWAF_OBJ_TYPE;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @enum DDWAF_RET_CODE
|
46
|
+
*
|
47
|
+
* Codes returned by ddwaf_run.
|
48
|
+
**/
|
49
|
+
typedef enum
|
50
|
+
{
|
51
|
+
DDWAF_ERR_INTERNAL = -4,
|
52
|
+
DDWAF_ERR_INVALID_OBJECT = -3,
|
53
|
+
DDWAF_ERR_INVALID_ARGUMENT = -2,
|
54
|
+
DDWAF_ERR_TIMEOUT = -1,
|
55
|
+
DDWAF_GOOD = 0,
|
56
|
+
DDWAF_MONITOR = 1,
|
57
|
+
DDWAF_BLOCK = 2
|
58
|
+
} DDWAF_RET_CODE;
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @enum DDWAF_LOG_LEVEL
|
62
|
+
*
|
63
|
+
* Internal WAF log levels, to be used when setting the minimum log level and cb.
|
64
|
+
**/
|
65
|
+
typedef enum
|
66
|
+
{
|
67
|
+
DDWAF_LOG_TRACE,
|
68
|
+
DDWAF_LOG_DEBUG,
|
69
|
+
DDWAF_LOG_INFO,
|
70
|
+
DDWAF_LOG_WARN,
|
71
|
+
DDWAF_LOG_ERROR,
|
72
|
+
DDWAF_LOG_OFF,
|
73
|
+
} DDWAF_LOG_LEVEL;
|
74
|
+
|
75
|
+
typedef struct _ddwaf_handle* ddwaf_handle;
|
76
|
+
typedef struct _ddwaf_context* ddwaf_context;
|
77
|
+
typedef struct _ddwaf_object ddwaf_object;
|
78
|
+
typedef struct _ddwaf_config ddwaf_config;
|
79
|
+
typedef struct _ddwaf_result ddwaf_result;
|
80
|
+
typedef struct _ddwaf_version ddwaf_version;
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @struct ddwaf_object
|
84
|
+
*
|
85
|
+
* Generic object used to pass data and rules to the WAF.
|
86
|
+
**/
|
87
|
+
struct _ddwaf_object
|
88
|
+
{
|
89
|
+
const char* parameterName;
|
90
|
+
uint64_t parameterNameLength;
|
91
|
+
// uintValue should be at least as wide as the widest type on the platform.
|
92
|
+
union
|
93
|
+
{
|
94
|
+
const char* stringValue;
|
95
|
+
uint64_t uintValue;
|
96
|
+
int64_t intValue;
|
97
|
+
const ddwaf_object* array;
|
98
|
+
};
|
99
|
+
uint64_t nbEntries;
|
100
|
+
DDWAF_OBJ_TYPE type;
|
101
|
+
};
|
102
|
+
|
103
|
+
/**
|
104
|
+
* @struct ddwaf_config
|
105
|
+
*
|
106
|
+
* Configuration to be provided to the WAF
|
107
|
+
**/
|
108
|
+
struct _ddwaf_config
|
109
|
+
{
|
110
|
+
/** Maximum length of ddwaf::object arrays. */
|
111
|
+
uint64_t maxArrayLength;
|
112
|
+
/** Maximum depth of ddwaf::object maps. */
|
113
|
+
uint64_t maxMapDepth;
|
114
|
+
/** Maximum size of the rule run time store. **/
|
115
|
+
int32_t maxTimeStore;
|
116
|
+
};
|
117
|
+
|
118
|
+
/**
|
119
|
+
* @struct ddwaf_result
|
120
|
+
*
|
121
|
+
* Structure containing the result of a WAF run.
|
122
|
+
**/
|
123
|
+
struct _ddwaf_result
|
124
|
+
{
|
125
|
+
/** Run result action **/
|
126
|
+
DDWAF_RET_CODE action;
|
127
|
+
/** Run result in JSON format **/
|
128
|
+
const char* data;
|
129
|
+
/** Performance data in JSON format **/
|
130
|
+
const char* perfData;
|
131
|
+
/** Total run time in microseconds **/
|
132
|
+
uint32_t perfTotalRuntime;
|
133
|
+
};
|
134
|
+
|
135
|
+
/**
|
136
|
+
* @ddwaf_version
|
137
|
+
*
|
138
|
+
* Structure containing the version of the WAF following semver.
|
139
|
+
**/
|
140
|
+
struct _ddwaf_version
|
141
|
+
{
|
142
|
+
uint16_t major;
|
143
|
+
uint16_t minor;
|
144
|
+
uint16_t patch;
|
145
|
+
};
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @typedef ddwaf_object_free_fn
|
149
|
+
*
|
150
|
+
* Type of the function to free ddwaf::objects.
|
151
|
+
**/
|
152
|
+
typedef void (*ddwaf_object_free_fn)(ddwaf_object *object);
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @typedef ddwaf_log_cb
|
156
|
+
*
|
157
|
+
* Callback that powerwaf will call to relay messages to the binding.
|
158
|
+
*
|
159
|
+
* @param level The logging level.
|
160
|
+
* @param function The native function that emitted the message. (nonnull)
|
161
|
+
* @param file The file of the native function that emmitted the message. (nonnull)
|
162
|
+
* @param line The line where the message was emmitted.
|
163
|
+
* @param message The size of the logging message. NUL-terminated
|
164
|
+
* @param message_len The length of the logging message (excluding NUL terminator).
|
165
|
+
*/
|
166
|
+
typedef void (*ddwaf_log_cb)(
|
167
|
+
DDWAF_LOG_LEVEL level, const char* function, const char* file, unsigned line,
|
168
|
+
const char* message, uint64_t message_len);
|
169
|
+
|
170
|
+
/**
|
171
|
+
* ddwaf_init
|
172
|
+
*
|
173
|
+
* Initialize a ddwaf instance
|
174
|
+
*
|
175
|
+
* @param rule ddwaf::object containing the patterns to be used by the WAF. (nonnull)
|
176
|
+
* @param config Optional configuration of the WAF. (nullable)
|
177
|
+
*
|
178
|
+
* @return Handle to the WAF instance.
|
179
|
+
**/
|
180
|
+
ddwaf_handle ddwaf_init(const ddwaf_object *rule, const ddwaf_config* config);
|
181
|
+
|
182
|
+
/**
|
183
|
+
* ddwaf_destroy
|
184
|
+
*
|
185
|
+
* Destroy a WAF instance.
|
186
|
+
*
|
187
|
+
* @param Handle to the WAF instance.
|
188
|
+
*/
|
189
|
+
void ddwaf_destroy(ddwaf_handle handle);
|
190
|
+
|
191
|
+
/**
|
192
|
+
* ddwaf_required_addresses
|
193
|
+
*
|
194
|
+
* Get a list of required (root) addresses. The memory is owned by the WAF and
|
195
|
+
* should not be freed.
|
196
|
+
*
|
197
|
+
* @param Handle to the WAF instance.
|
198
|
+
* @param size Output parameter in which the size will be returned. The value of
|
199
|
+
* size will be 0 if the return value is nullptr.
|
200
|
+
* @return NULL if error, otherwise a pointer to an array with size elements.
|
201
|
+
**/
|
202
|
+
const char* const* ddwaf_required_addresses(const ddwaf_handle handle, uint32_t *size);
|
203
|
+
/**
|
204
|
+
* ddwaf_context_init
|
205
|
+
*
|
206
|
+
* Context object to perform matching using the provided WAF instance.
|
207
|
+
*
|
208
|
+
* @param handle Handle of the WAF instance containing the ruleset definition. (nonnull)
|
209
|
+
* @param obj_free Function to free the ddwaf::object provided to the context
|
210
|
+
* during calls to ddwaf_run. If the value of this function is
|
211
|
+
* NULL, the objects will not be freed. By default the value of
|
212
|
+
* this parameter should be ddwaf_object_free.
|
213
|
+
*
|
214
|
+
* @return Handle to the context instance.
|
215
|
+
*
|
216
|
+
* @note The WAF instance needs to be valid for the lifetime of the context.
|
217
|
+
**/
|
218
|
+
ddwaf_context ddwaf_context_init(const ddwaf_handle handle, ddwaf_object_free_fn obj_free);
|
219
|
+
|
220
|
+
/**
|
221
|
+
* ddwaf_run
|
222
|
+
*
|
223
|
+
* Perform a matching operation on the provided data
|
224
|
+
*
|
225
|
+
* @param context WAF context to be used in this run, this will determine the
|
226
|
+
* ruleset which will be used and it will also ensure that
|
227
|
+
* parameters are taken into account across runs (nonnull)
|
228
|
+
* @param data Data on which to perform the pattern matching. This data will be
|
229
|
+
* stored by the context and used across multiple calls to this
|
230
|
+
* function. Once the context is destroyed, the used-defined free
|
231
|
+
* function will be used to free the data provided. Note that the
|
232
|
+
* data passed must be valid until the destruction of the context.
|
233
|
+
* (nonull)
|
234
|
+
* @param result Structure containing the result of the operation. (nullable)
|
235
|
+
* @param timeout Maximum time budget in microseconds.
|
236
|
+
*
|
237
|
+
* @return Return code of the operation, also contained in the result structure.
|
238
|
+
* @error DDWAF_ERR_INVALID_ARGUMENT The context is invalid, the data will not
|
239
|
+
* be freed.
|
240
|
+
* @error DDWAF_ERR_INVALID_OBJECT The data provided didn't match the desired
|
241
|
+
* structure or contained invalid objects, the
|
242
|
+
* data will be freed by this function.
|
243
|
+
* @error DDWAF_ERR_TIMEOUT The operation timed out, the data will be owned by
|
244
|
+
* the context and freed during destruction.
|
245
|
+
* @error DDWAF_ERR_INTERNAL There was an unexpected error and the operation did
|
246
|
+
* not succeed. The state of the WAF is undefined if
|
247
|
+
* this error is produced and the ownership of the
|
248
|
+
* data is unknown. The result structure will not be
|
249
|
+
* filled if this error occurs.
|
250
|
+
**/
|
251
|
+
DDWAF_RET_CODE ddwaf_run(ddwaf_context context, ddwaf_object *data, ddwaf_result *result, uint64_t timeout);
|
252
|
+
|
253
|
+
/**
|
254
|
+
* ddwaf_context_destroy
|
255
|
+
*
|
256
|
+
* Performs the destruction of the context, freeing the data passed to it through
|
257
|
+
* ddwaf_run using the used-defined free function.
|
258
|
+
*
|
259
|
+
* @param context Context to destroy. (nonnull)
|
260
|
+
**/
|
261
|
+
void ddwaf_context_destroy(ddwaf_context context);
|
262
|
+
|
263
|
+
/**
|
264
|
+
* ddwaf_result_free
|
265
|
+
*
|
266
|
+
* Free a ddwaf_result structure.
|
267
|
+
*
|
268
|
+
* @param result Structure to free. (nonnull)
|
269
|
+
**/
|
270
|
+
void ddwaf_result_free(ddwaf_result *result);
|
271
|
+
|
272
|
+
/**
|
273
|
+
* ddwaf_object_invalid
|
274
|
+
*
|
275
|
+
* Creates an invalid object.
|
276
|
+
*
|
277
|
+
* @param object Object to perform the operation on. (nonnull)
|
278
|
+
*
|
279
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
280
|
+
**/
|
281
|
+
ddwaf_object* ddwaf_object_invalid(ddwaf_object *object);
|
282
|
+
|
283
|
+
/**
|
284
|
+
* ddwaf_object_string
|
285
|
+
*
|
286
|
+
* Creates an object from a string.
|
287
|
+
*
|
288
|
+
* @param object Object to perform the operation on. (nonnull)
|
289
|
+
* @param string String to initialise the object with, this string will be copied
|
290
|
+
* and its length will be calculated using strlen(string). (nonnull)
|
291
|
+
*
|
292
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
293
|
+
**/
|
294
|
+
ddwaf_object* ddwaf_object_string(ddwaf_object *object, const char *string);
|
295
|
+
|
296
|
+
/**
|
297
|
+
* ddwaf_object_stringl
|
298
|
+
*
|
299
|
+
* Creates an object from a string and its length.
|
300
|
+
*
|
301
|
+
* @param object Object to perform the operation on. (nonnull)
|
302
|
+
* @param string String to initialise the object with, this string will be
|
303
|
+
* copied. (nonnull)
|
304
|
+
* @param length Length of the string.
|
305
|
+
*
|
306
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
307
|
+
**/
|
308
|
+
ddwaf_object* ddwaf_object_stringl(ddwaf_object *object, const char *string, size_t length);
|
309
|
+
|
310
|
+
/**
|
311
|
+
* ddwaf_object_stringl_nc
|
312
|
+
*
|
313
|
+
* Creates an object with the string pointer and length provided.
|
314
|
+
*
|
315
|
+
* @param object Object to perform the operation on. (nonnull)
|
316
|
+
* @param string String pointer to initialise the object with.
|
317
|
+
* @param length Length of the string.
|
318
|
+
*
|
319
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
320
|
+
**/
|
321
|
+
ddwaf_object* ddwaf_object_stringl_nc(ddwaf_object *object, const char *string, size_t length);
|
322
|
+
|
323
|
+
/**
|
324
|
+
* ddwaf_object_unsigned
|
325
|
+
*
|
326
|
+
* Creates an object using an unsigned integer (64-bit). The resulting object
|
327
|
+
* will contain a string created using the integer provided. This is the
|
328
|
+
* preferred method for passing an unsigned integer to the WAF.
|
329
|
+
*
|
330
|
+
* @param object Object to perform the operation on. (nonnull)
|
331
|
+
* @param value Integer to initialise the object with.
|
332
|
+
*
|
333
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
334
|
+
**/
|
335
|
+
ddwaf_object* ddwaf_object_unsigned(ddwaf_object *object, uint64_t value);
|
336
|
+
|
337
|
+
/**
|
338
|
+
* ddwaf_object_signed
|
339
|
+
*
|
340
|
+
* Creates an object using a signed integer (64-bit). The resulting object
|
341
|
+
* will contain a string created using the integer provided. This is the
|
342
|
+
* preferred method for passing a signed integer to the WAF.
|
343
|
+
*
|
344
|
+
* @param object Object to perform the operation on. (nonnull)
|
345
|
+
* @param value Integer to initialise the object with.
|
346
|
+
*
|
347
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
348
|
+
**/
|
349
|
+
ddwaf_object* ddwaf_object_signed(ddwaf_object *object, int64_t value);
|
350
|
+
|
351
|
+
/**
|
352
|
+
* ddwaf_object_unsigned_force
|
353
|
+
*
|
354
|
+
* Creates an object using an unsigned integer (64-bit). The resulting object
|
355
|
+
* will contain an unsigned integer as opposed to a string.
|
356
|
+
*
|
357
|
+
* @param object Object to perform the operation on. (nonnull)
|
358
|
+
* @param value Integer to initialise the object with.
|
359
|
+
*
|
360
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
361
|
+
**/
|
362
|
+
ddwaf_object* ddwaf_object_unsigned_force(ddwaf_object *object, uint64_t value);
|
363
|
+
|
364
|
+
/**
|
365
|
+
* ddwaf_object_signed_force
|
366
|
+
*
|
367
|
+
* Creates an object using a signed integer (64-bit). The resulting object
|
368
|
+
* will contain a signed integer as opposed to a string.
|
369
|
+
*
|
370
|
+
* @param object Object to perform the operation on. (nonnull)
|
371
|
+
* @param value Integer to initialise the object with.
|
372
|
+
*
|
373
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
374
|
+
**/
|
375
|
+
ddwaf_object* ddwaf_object_signed_force(ddwaf_object *object, int64_t value);
|
376
|
+
|
377
|
+
/**
|
378
|
+
* ddwaf_object_array
|
379
|
+
*
|
380
|
+
* Creates an array object, for sequential storage.
|
381
|
+
*
|
382
|
+
* @param object Object to perform the operation on. (nonnull)
|
383
|
+
*
|
384
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
385
|
+
**/
|
386
|
+
ddwaf_object* ddwaf_object_array(ddwaf_object *object);
|
387
|
+
|
388
|
+
/**
|
389
|
+
* ddwaf_object_map
|
390
|
+
*
|
391
|
+
* Creates a map object, for key-value storage.
|
392
|
+
*
|
393
|
+
* @param object Object to perform the operation on. (nonnull)
|
394
|
+
*
|
395
|
+
* @return A pointer to the passed object or NULL if the operation failed.
|
396
|
+
**/
|
397
|
+
ddwaf_object* ddwaf_object_map(ddwaf_object *object);
|
398
|
+
|
399
|
+
/**
|
400
|
+
* ddwaf_object_array_add
|
401
|
+
*
|
402
|
+
* Inserts an object into an array object.
|
403
|
+
*
|
404
|
+
* @param array Array in which to insert the object. (nonnull)
|
405
|
+
* @param object Object to insert into the array. (nonnull)
|
406
|
+
*
|
407
|
+
* @return The success or failure of the operation.
|
408
|
+
**/
|
409
|
+
bool ddwaf_object_array_add(ddwaf_object *array, ddwaf_object *object);
|
410
|
+
|
411
|
+
/**
|
412
|
+
* ddwaf_object_map_add
|
413
|
+
*
|
414
|
+
* Inserts an object into an map object, using a key.
|
415
|
+
*
|
416
|
+
* @param map Map in which to insert the object. (nonnull)
|
417
|
+
* @param key The key for indexing purposes, this string will be copied and its
|
418
|
+
* length will be calcualted using strlen(key). (nonnull)
|
419
|
+
* @param object Object to insert into the array. (nonnull)
|
420
|
+
*
|
421
|
+
* @return The success or failure of the operation.
|
422
|
+
**/
|
423
|
+
bool ddwaf_object_map_add(ddwaf_object *map, const char *key, ddwaf_object *object);
|
424
|
+
|
425
|
+
/**
|
426
|
+
* ddwaf_object_map_addl
|
427
|
+
*
|
428
|
+
* Inserts an object into an map object, using a key and its length.
|
429
|
+
*
|
430
|
+
* @param map Map in which to insert the object. (nonnull)
|
431
|
+
* @param key The key for indexing purposes, this string will be copied (nonnull)
|
432
|
+
* @param length Length of the key.
|
433
|
+
* @param object Object to insert into the array. (nonnull)
|
434
|
+
*
|
435
|
+
* @return The success or failure of the operation.
|
436
|
+
**/
|
437
|
+
bool ddwaf_object_map_addl(ddwaf_object *map, const char *key, size_t length, ddwaf_object *object);
|
438
|
+
|
439
|
+
/**
|
440
|
+
* ddwaf_object_map_addl_nc
|
441
|
+
*
|
442
|
+
* Inserts an object into an map object, using a key and its length, but without
|
443
|
+
* creating a copy of the key.
|
444
|
+
*
|
445
|
+
* @param map Map in which to insert the object. (nonnull)
|
446
|
+
* @param key The key for indexing purposes, this string will be copied (nonnull)
|
447
|
+
* @param length Length of the key.
|
448
|
+
* @param object Object to insert into the array. (nonnull)
|
449
|
+
*
|
450
|
+
* @return The success or failure of the operation.
|
451
|
+
**/
|
452
|
+
bool ddwaf_object_map_addl_nc(ddwaf_object *map, const char *key, size_t length, ddwaf_object *object);
|
453
|
+
|
454
|
+
/**
|
455
|
+
* ddwaf_object_free
|
456
|
+
*
|
457
|
+
* @param object Object to free. (nonnull)
|
458
|
+
**/
|
459
|
+
void ddwaf_object_free(ddwaf_object *object);
|
460
|
+
|
461
|
+
/**
|
462
|
+
* ddwaf_get_version
|
463
|
+
*
|
464
|
+
* Return the version of the library
|
465
|
+
*
|
466
|
+
* @param version Version structure following semver
|
467
|
+
**/
|
468
|
+
void ddwaf_get_version(ddwaf_version *version);
|
469
|
+
|
470
|
+
/**
|
471
|
+
* ddwaf_set_log_cb
|
472
|
+
*
|
473
|
+
* Sets the callback to relay logging messages to the binding
|
474
|
+
*
|
475
|
+
* @param cb The callback to call, or NULL to stop relaying messages
|
476
|
+
* @param min_level The minimum logging level for which to relay messages
|
477
|
+
*
|
478
|
+
* @return whether the operation succeeded or not
|
479
|
+
**/
|
480
|
+
bool ddwaf_set_log_cb(ddwaf_log_cb cb, DDWAF_LOG_LEVEL min_level);
|
481
|
+
|
482
|
+
#ifdef __cplusplus
|
483
|
+
}
|
484
|
+
#endif /* __cplusplus */
|
485
|
+
|
486
|
+
#endif /* pw_h */
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libddwaf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.12.0.0.beta1
|
5
|
+
platform: x86_64-linux
|
6
|
+
authors:
|
7
|
+
- Datadog, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: 'libddwaf packages a WAF implementation in C++, exposed to Ruby
|
28
|
+
|
29
|
+
'
|
30
|
+
email:
|
31
|
+
- dev@datadoghq.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- LICENSE-3rdparty.csv
|
38
|
+
- LICENSE.Apache
|
39
|
+
- LICENSE.BSD3
|
40
|
+
- NOTICE
|
41
|
+
- lib/datadog/security/waf.rb
|
42
|
+
- lib/datadog/security/waf/version.rb
|
43
|
+
- lib/libddwaf.rb
|
44
|
+
- vendor/libddwaf/libddwaf-1.0.12-linux-x86_64/include/ddwaf.h
|
45
|
+
- vendor/libddwaf/libddwaf-1.0.12-linux-x86_64/lib/libddwaf.so
|
46
|
+
homepage: https://github.com/DataDog/libddwaf
|
47
|
+
licenses:
|
48
|
+
- BSD-3-Clause
|
49
|
+
metadata:
|
50
|
+
allowed_push_host: https://rubygems.org
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.1'
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.1'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.0.0
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.1.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Datadog WAF
|
73
|
+
test_files: []
|