libddwaf 1.15.0.0.0-aarch64-linux-musl

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 263fd5eecef7f262464554370ba8ada3d696231343df66fa42f6d9d6bcd55aca
4
+ data.tar.gz: 38b0e8b7e58c31d444b1572fd26305e636c4a75ef5855f36ed769068e6f0bbae
5
+ SHA512:
6
+ metadata.gz: 85a5bf5d342fd172512d2dbf512056ba6d3a0a0d0b5f84617bd21a28f358b7b24149619e6be11ecf3bc4b7cd47ae597d8d8d06755ea8e8dd85800b729f9d7afd
7
+ data.tar.gz: 209070b65189c6e8c51e4f5cb58ae2935c5c87264c4d3321ee099d1a4d9575c3ee1a8b6fb9e7fa9bd60117f1b23a6609a3d28997d65f5924047cbee424a01ed5
data/CHANGELOG.md ADDED
@@ -0,0 +1,128 @@
1
+ # 2024-10-29 v.1.15.0.0.0
2
+ - Update to libddwaf 1.15.0
3
+ - Changed `Datadog::AppSec::WAF::Context#run` interface to accommodate ephemeral data ([Breaking change](https://github.com/DataDog/libddwaf/blob/master/CHANGELOG.md#v1150-unstable))
4
+
5
+ # 2023-09-11 v.1.14.0.0.0
6
+ - Update to libddwaf 1.14.0
7
+ - Add support for `Float` and `Nil` scalar values when converting from ruby to WAF Object and vice versa.
8
+
9
+
10
+ # 2023-08-29 v.1.11.0.0.0
11
+
12
+ - Update to libddwaf 1.11.0
13
+ - Changed `Datadog::AppSec::WAF::Handle#ruleset_info` to `Datadog::AppSec::WAF::Handle#diagnostics`. (Breaking change)
14
+ The schema of the diagnostics variable can be found [here](https://github.com/DataDog/libddwaf/blob/master/schema/diagnostics.json)
15
+ - Changed `Datadog::AppSec::WAF::Result#data` to `Datadog::AppSec::WAF::Result#events`. (Breaking change)
16
+ The schema of the events variable can be found [here](https://github.com/DataDog/libddwaf/blob/master/schema/events.json)
17
+
18
+
19
+ # 2023-08-28 v.1.10.0.0.0
20
+
21
+ - Update to libddwaf 1.10.0
22
+
23
+ # 2023-06-13 v.1.9.0.0.1
24
+
25
+ - Handle invalid encoding
26
+ - Ensure strings passed to libddwaf are not clipped inside a code point
27
+ - Ensure strings passed to libddwaf are UTF-8
28
+
29
+ # 2023-05-17 v1.9.0.0.0
30
+
31
+ - Update to libddwaf 1.9.0
32
+ - Support [`custom_rules`](https://github.com/DataDog/libddwaf/pull/154)
33
+
34
+ # 2023-03-03 v1.8.2.0.0
35
+
36
+ - Update to libddwaf 1.8.2
37
+ - Added Waf::Handle#merge method
38
+ - Remove Waf::Handle#update_rule_data and Waf::Handle#toggle_rules methods
39
+ - Remove WAF::LibDDWAF.ddwaf_required_rule_data_ids method
40
+
41
+ # 2023-02-03 v1.7.0.0.0
42
+
43
+ - Update to libddwaf 1.7.0
44
+
45
+ # 2023-02-03 v1.6.2.0.0
46
+
47
+ - Update to libddwaf 1.6.2
48
+ - Add specs for the getter functions
49
+
50
+ # 2023-02-01 v1.5.1.0.1
51
+
52
+ - Fix incorrect size in input string limit
53
+ - Fix object freeing on `update_rule_data` and `toggle_rules`
54
+
55
+ # 2022-10-04 v1.5.1.0.0
56
+
57
+ - Update to libddwaf 1.5.1
58
+ - Add live rule data update API
59
+ - Add live rule toggle API
60
+ - Add libddwaf boolean type support
61
+ - Add Ruby to libddwaf object conversion limits
62
+ - Add Ruby to libddwaf object converter optional coercion of scalars to string
63
+ - Add static type checking via RBS+Steep
64
+ - Change version to return a string
65
+ - Change free function to be passed as config instead of context init argument
66
+ - Change result to include action list
67
+ - Change return code from action to status
68
+ - Change handle and context freeing model from GC-based to explicit
69
+ - Fix double-free upon finalization of retained C objects
70
+ - Fix context crash by retaining necessary C objects
71
+
72
+ # 2022-05-20 v1.3.0.2.0
73
+
74
+ - Fix multibyte string handling
75
+ - Support JRuby
76
+
77
+ # 2022-04-29 v1.3.0.1.0
78
+
79
+ Promotion of v1.3.0.1.0.beta1 to stable
80
+
81
+ # 2022-04-25 v1.3.0.1.0.beta1
82
+
83
+ - Add obfuscator configuration
84
+ - Add nested object limit configuration
85
+ - Add report ruleset information
86
+
87
+ # 2022-04-29 v1.3.0.0.0
88
+
89
+ - Promote v1.3.0.0.0.beta1 to stable
90
+
91
+ # 2022-04-20 v1.3.0.0.0.beta1
92
+
93
+ - Update to libddwaf 1.3.0
94
+
95
+ # 2022-03-18 v1.2.1.0.0.beta1
96
+
97
+ - Update to libddwaf 1.2.1
98
+ - Fix incorrect types for a few binding functions
99
+
100
+ # 2022-03-04 v1.0.14.2.1.beta1
101
+
102
+ - Fix incorrect return code
103
+ - Fix passing nil in libddwaf object containers
104
+
105
+ # 2022-02-07 v1.0.14.2.0.beta1
106
+
107
+ - Change Datadog::Security to Datadog::AppSec
108
+
109
+ # 2022-02-01 v1.0.14.1.0.beta2
110
+
111
+ - Add support for Ruby 3.1
112
+
113
+ # 2021-12-14 v1.0.14.1.0.beta1
114
+
115
+ - Fix sequential runs on a single context by retaining C input data objects
116
+
117
+ # 2021-11-24 v1.0.14.0.0.beta1
118
+
119
+ - Update to libddwaf 1.0.14
120
+
121
+ # 2021-11-24 v1.0.13.0.0.beta1
122
+
123
+ - Add ruby platform fallback for unsupported platforms
124
+ - Update to libddwaf 1.0.13
125
+
126
+ # 2021-10-13 v1.0.12.0.0.beta1
127
+
128
+ - Initial release
data/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ ## License
2
+
3
+ This work is dual-licensed under Apache 2.0 or BSD3.
4
+ You may select, at your option, one of the above-listed licenses.
5
+
6
+ `SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause`
@@ -0,0 +1,2 @@
1
+ Component,Origin,License,Copyright
2
+ core,https://github.com/ffi/ffi,BSD-3-Clause,"Copyright (c) 2008-2016, Ruby FFI project contributors"
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,4 @@
1
+ Datadog libddwaf-rb
2
+ Copyright 2021-Present Datadog, Inc.
3
+
4
+ This product includes software developed at Datadog, Inc. (https://www.datadoghq.com/).
@@ -0,0 +1,11 @@
1
+ module Datadog
2
+ module AppSec
3
+ module WAF
4
+ module VERSION
5
+ BASE_STRING = '1.15.0'
6
+ STRING = "#{BASE_STRING}.0.0"
7
+ MINIMUM_RUBY_VERSION = '2.5'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,713 @@
1
+ require 'ffi'
2
+ require 'json'
3
+ require 'datadog/appsec/waf/version'
4
+
5
+ module Datadog
6
+ module AppSec
7
+ # rubocop:disable Metrics/ModuleLength
8
+ module WAF
9
+ module LibDDWAF
10
+ class Error < StandardError
11
+ attr_reader :diagnostics
12
+
13
+ def initialize(msg, diagnostics: nil)
14
+ @diagnostics = diagnostics
15
+ end
16
+ end
17
+
18
+ extend ::FFI::Library
19
+
20
+ def self.local_os
21
+ if RUBY_ENGINE == 'jruby'
22
+ os_name = java.lang.System.get_property('os.name')
23
+
24
+ os = case os_name
25
+ when /linux/i then 'linux'
26
+ when /mac/i then 'darwin'
27
+ else raise Error, "unsupported JRuby os.name: #{os_name.inspect}"
28
+ end
29
+
30
+ return os
31
+ end
32
+
33
+ Gem::Platform.local.os
34
+ end
35
+
36
+ def self.local_version
37
+ return nil unless local_os == 'linux'
38
+
39
+ # Old rubygems don't handle non-gnu linux correctly
40
+ return $1 if RUBY_PLATFORM =~ /linux-(.+)$/
41
+
42
+ 'gnu'
43
+ end
44
+
45
+ def self.local_cpu
46
+ if RUBY_ENGINE == 'jruby'
47
+ os_arch = java.lang.System.get_property('os.arch')
48
+
49
+ cpu = case os_arch
50
+ when 'amd64' then 'x86_64'
51
+ when 'aarch64' then 'aarch64'
52
+ else raise Error, "unsupported JRuby os.arch: #{os_arch.inspect}"
53
+ end
54
+
55
+ return cpu
56
+ end
57
+
58
+ Gem::Platform.local.cpu
59
+ end
60
+
61
+ def self.source_dir
62
+ __dir__ || raise('__dir__ is nil: eval?')
63
+ end
64
+
65
+ def self.vendor_dir
66
+ File.join(source_dir, '../../../vendor')
67
+ end
68
+
69
+ def self.libddwaf_vendor_dir
70
+ File.join(vendor_dir, 'libddwaf')
71
+ end
72
+
73
+ def self.shared_lib_triplet(version: local_version)
74
+ version ? "#{local_os}-#{version}-#{local_cpu}" : "#{local_os}-#{local_cpu}"
75
+ end
76
+
77
+ def self.libddwaf_dir
78
+ default = File.join(libddwaf_vendor_dir,
79
+ "libddwaf-#{Datadog::AppSec::WAF::VERSION::BASE_STRING}-#{shared_lib_triplet}")
80
+ candidates = [
81
+ default
82
+ ]
83
+
84
+ if local_os == 'linux'
85
+ candidates << File.join(libddwaf_vendor_dir,
86
+ "libddwaf-#{Datadog::AppSec::WAF::VERSION::BASE_STRING}-#{shared_lib_triplet(version: nil)}")
87
+ end
88
+
89
+ candidates.find { |d| Dir.exist?(d) } || default
90
+ end
91
+
92
+ def self.shared_lib_extname
93
+ Gem::Platform.local.os == 'darwin' ? '.dylib' : '.so'
94
+ end
95
+
96
+ def self.shared_lib_path
97
+ File.join(libddwaf_dir, 'lib', "libddwaf#{shared_lib_extname}")
98
+ end
99
+
100
+ ffi_lib [shared_lib_path]
101
+
102
+ # version
103
+
104
+ attach_function :ddwaf_get_version, [], :string
105
+
106
+ # ddwaf::object data structure
107
+
108
+ DDWAF_OBJ_TYPE = enum :ddwaf_obj_invalid, 0,
109
+ :ddwaf_obj_signed, 1 << 0,
110
+ :ddwaf_obj_unsigned, 1 << 1,
111
+ :ddwaf_obj_string, 1 << 2,
112
+ :ddwaf_obj_array, 1 << 3,
113
+ :ddwaf_obj_map, 1 << 4,
114
+ :ddwaf_obj_bool, 1 << 5,
115
+ :ddwaf_obj_float, 1 << 6,
116
+ :ddwaf_obj_null, 1 << 7
117
+
118
+ typedef DDWAF_OBJ_TYPE, :ddwaf_obj_type
119
+
120
+ typedef :pointer, :charptr
121
+ typedef :pointer, :charptrptr
122
+
123
+ class UInt32Ptr < ::FFI::Struct
124
+ layout :value, :uint32
125
+ end
126
+
127
+ typedef UInt32Ptr.by_ref, :uint32ptr
128
+
129
+ class UInt64Ptr < ::FFI::Struct
130
+ layout :value, :uint64
131
+ end
132
+
133
+ typedef UInt64Ptr.by_ref, :uint64ptr
134
+
135
+ class SizeTPtr < ::FFI::Struct
136
+ layout :value, :size_t
137
+ end
138
+
139
+ typedef SizeTPtr.by_ref, :sizeptr
140
+
141
+ class ObjectValueUnion < ::FFI::Union
142
+ layout :stringValue, :charptr,
143
+ :uintValue, :uint64,
144
+ :intValue, :int64,
145
+ :array, :pointer,
146
+ :boolean, :bool,
147
+ :f64, :double
148
+ end
149
+
150
+ class Object < ::FFI::Struct
151
+ layout :parameterName, :charptr,
152
+ :parameterNameLength, :uint64,
153
+ :valueUnion, ObjectValueUnion,
154
+ :nbEntries, :uint64,
155
+ :type, :ddwaf_obj_type
156
+ end
157
+
158
+ typedef Object.by_ref, :ddwaf_object
159
+
160
+ ## setters
161
+
162
+ attach_function :ddwaf_object_invalid, [:ddwaf_object], :ddwaf_object
163
+ attach_function :ddwaf_object_string, [:ddwaf_object, :string], :ddwaf_object
164
+ attach_function :ddwaf_object_stringl, [:ddwaf_object, :charptr, :size_t], :ddwaf_object
165
+ attach_function :ddwaf_object_stringl_nc, [:ddwaf_object, :charptr, :size_t], :ddwaf_object
166
+ attach_function :ddwaf_object_string_from_unsigned, [:ddwaf_object, :uint64], :ddwaf_object
167
+ attach_function :ddwaf_object_string_from_signed, [:ddwaf_object, :int64], :ddwaf_object
168
+ attach_function :ddwaf_object_unsigned, [:ddwaf_object, :uint64], :ddwaf_object
169
+ attach_function :ddwaf_object_signed, [:ddwaf_object, :int64], :ddwaf_object
170
+ attach_function :ddwaf_object_bool, [:ddwaf_object, :bool], :ddwaf_object
171
+ attach_function :ddwaf_object_null, [:ddwaf_object], :ddwaf_object
172
+ attach_function :ddwaf_object_float, [:ddwaf_object, :double], :ddwaf_object
173
+
174
+ attach_function :ddwaf_object_array, [:ddwaf_object], :ddwaf_object
175
+ attach_function :ddwaf_object_array_add, [:ddwaf_object, :ddwaf_object], :bool
176
+
177
+ attach_function :ddwaf_object_map, [:ddwaf_object], :ddwaf_object
178
+ attach_function :ddwaf_object_map_add, [:ddwaf_object, :string, :pointer], :bool
179
+ attach_function :ddwaf_object_map_addl, [:ddwaf_object, :charptr, :size_t, :pointer], :bool
180
+ attach_function :ddwaf_object_map_addl_nc, [:ddwaf_object, :charptr, :size_t, :pointer], :bool
181
+
182
+ ## getters
183
+
184
+ attach_function :ddwaf_object_type, [:ddwaf_object], DDWAF_OBJ_TYPE
185
+ attach_function :ddwaf_object_size, [:ddwaf_object], :uint64
186
+ attach_function :ddwaf_object_length, [:ddwaf_object], :size_t
187
+ attach_function :ddwaf_object_get_key, [:ddwaf_object, :sizeptr], :charptr
188
+ attach_function :ddwaf_object_get_string, [:ddwaf_object, :sizeptr], :charptr
189
+ attach_function :ddwaf_object_get_unsigned, [:ddwaf_object], :uint64
190
+ attach_function :ddwaf_object_get_signed, [:ddwaf_object], :int64
191
+ attach_function :ddwaf_object_get_index, [:ddwaf_object, :size_t], :ddwaf_object
192
+ attach_function :ddwaf_object_get_bool, [:ddwaf_object], :bool
193
+ attach_function :ddwaf_object_get_float, [:ddwaf_object], :double
194
+
195
+ ## freeers
196
+
197
+ ObjectFree = attach_function :ddwaf_object_free, [:ddwaf_object], :void
198
+ ObjectNoFree = ::FFI::Pointer::NULL
199
+
200
+ # main handle
201
+
202
+ typedef :pointer, :ddwaf_handle
203
+ typedef Object.by_ref, :ddwaf_rule
204
+
205
+ callback :ddwaf_object_free_fn, [:ddwaf_object], :void
206
+
207
+ class Config < ::FFI::Struct
208
+ class Limits < ::FFI::Struct
209
+ layout :max_container_size, :uint32,
210
+ :max_container_depth, :uint32,
211
+ :max_string_length, :uint32
212
+ end
213
+
214
+ class Obfuscator < ::FFI::Struct
215
+ layout :key_regex, :pointer, # should be :charptr
216
+ :value_regex, :pointer # should be :charptr
217
+ end
218
+
219
+ layout :limits, Limits,
220
+ :obfuscator, Obfuscator,
221
+ :free_fn, :pointer #:ddwaf_object_free_fn
222
+ end
223
+
224
+ typedef Config.by_ref, :ddwaf_config
225
+
226
+ attach_function :ddwaf_init, [:ddwaf_rule, :ddwaf_config, :ddwaf_object], :ddwaf_handle
227
+ attach_function :ddwaf_update, [:ddwaf_handle, :ddwaf_object, :ddwaf_object], :ddwaf_handle
228
+ attach_function :ddwaf_destroy, [:ddwaf_handle], :void
229
+
230
+ attach_function :ddwaf_known_addresses, [:ddwaf_handle, UInt32Ptr], :charptrptr
231
+
232
+ # updating
233
+
234
+ DDWAF_RET_CODE = enum :ddwaf_err_internal, -3,
235
+ :ddwaf_err_invalid_object, -2,
236
+ :ddwaf_err_invalid_argument, -1,
237
+ :ddwaf_ok, 0,
238
+ :ddwaf_match, 1
239
+ typedef DDWAF_RET_CODE, :ddwaf_ret_code
240
+
241
+ # running
242
+
243
+ typedef :pointer, :ddwaf_context
244
+
245
+ attach_function :ddwaf_context_init, [:ddwaf_handle], :ddwaf_context
246
+ attach_function :ddwaf_context_destroy, [:ddwaf_context], :void
247
+
248
+ class Result < ::FFI::Struct
249
+ layout :timeout, :bool,
250
+ :events, Object,
251
+ :actions, Object,
252
+ :derivatives, Object,
253
+ :total_runtime, :uint64
254
+ end
255
+
256
+ typedef Result.by_ref, :ddwaf_result
257
+ typedef :uint64, :timeout_us
258
+
259
+ attach_function :ddwaf_run, [:ddwaf_context, :ddwaf_object, :ddwaf_object, :ddwaf_result, :timeout_us], :ddwaf_ret_code, blocking: true
260
+ attach_function :ddwaf_result_free, [:ddwaf_result], :void
261
+
262
+ # logging
263
+
264
+ DDWAF_LOG_LEVEL = enum :ddwaf_log_trace,
265
+ :ddwaf_log_debug,
266
+ :ddwaf_log_info,
267
+ :ddwaf_log_warn,
268
+ :ddwaf_log_error,
269
+ :ddwaf_log_off
270
+ typedef DDWAF_LOG_LEVEL, :ddwaf_log_level
271
+
272
+ callback :ddwaf_log_cb, [:ddwaf_log_level, :string, :string, :uint, :charptr, :uint64], :void
273
+
274
+ attach_function :ddwaf_set_log_cb, [:ddwaf_log_cb, :ddwaf_log_level], :bool
275
+
276
+ DEFAULT_MAX_CONTAINER_SIZE = 256
277
+ DEFAULT_MAX_CONTAINER_DEPTH = 20
278
+ DEFAULT_MAX_STRING_LENGTH = 16_384 # in bytes, UTF-8 worst case being 4x size in terms of code point)
279
+
280
+ DDWAF_MAX_CONTAINER_SIZE = 256
281
+ DDWAF_MAX_CONTAINER_DEPTH = 20
282
+ DDWAF_MAX_STRING_LENGTH = 4096
283
+
284
+ DDWAF_RUN_TIMEOUT = 5000
285
+ end
286
+
287
+ def self.version
288
+ LibDDWAF.ddwaf_get_version
289
+ end
290
+
291
+ # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
292
+ def self.ruby_to_object(val, max_container_size: nil, max_container_depth: nil, max_string_length: nil, coerce: true)
293
+ case val
294
+ when Array
295
+ obj = LibDDWAF::Object.new
296
+ res = LibDDWAF.ddwaf_object_array(obj)
297
+ if res.null?
298
+ fail LibDDWAF::Error, "Could not convert into object: #{val}"
299
+ end
300
+
301
+ max_index = max_container_size - 1 if max_container_size
302
+ val.each.with_index do |e, i|
303
+ member = ruby_to_object(e,
304
+ max_container_size: max_container_size,
305
+ max_container_depth: (max_container_depth - 1 if max_container_depth),
306
+ max_string_length: max_string_length,
307
+ coerce: coerce)
308
+ e_res = LibDDWAF.ddwaf_object_array_add(obj, member)
309
+ unless e_res
310
+ fail LibDDWAF::Error, "Could not add to array object: #{e.inspect}"
311
+ end
312
+
313
+ break val if max_index && i >= max_index
314
+ end unless max_container_depth == 0
315
+
316
+ obj
317
+ when Hash
318
+ obj = LibDDWAF::Object.new
319
+ res = LibDDWAF.ddwaf_object_map(obj)
320
+ if res.null?
321
+ fail LibDDWAF::Error, "Could not convert into object: #{val}"
322
+ end
323
+
324
+ max_index = max_container_size - 1 if max_container_size
325
+ val.each.with_index do |e, i|
326
+ k, v = e[0], e[1] # for Steep, which doesn't handle |(k, v), i|
327
+
328
+ k = k.to_s[0, max_string_length] if max_string_length
329
+ member = ruby_to_object(v,
330
+ max_container_size: max_container_size,
331
+ max_container_depth: (max_container_depth - 1 if max_container_depth),
332
+ max_string_length: max_string_length,
333
+ coerce: coerce)
334
+ kv_res = LibDDWAF.ddwaf_object_map_addl(obj, k.to_s, k.to_s.bytesize, member)
335
+ unless kv_res
336
+ fail LibDDWAF::Error, "Could not add to map object: #{k.inspect} => #{v.inspect}"
337
+ end
338
+
339
+ break val if max_index && i >= max_index
340
+ end unless max_container_depth == 0
341
+
342
+ obj
343
+ when String
344
+ obj = LibDDWAF::Object.new
345
+ encoded_val = val.to_s.encode('utf-8', invalid: :replace, undef: :replace)
346
+ val = encoded_val[0, max_string_length] if max_string_length
347
+ str = val.to_s
348
+ res = LibDDWAF.ddwaf_object_stringl(obj, str, str.bytesize)
349
+ if res.null?
350
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
351
+ end
352
+
353
+ obj
354
+ when Symbol
355
+ obj = LibDDWAF::Object.new
356
+ val = val.to_s[0, max_string_length] if max_string_length
357
+ str = val.to_s
358
+ res = LibDDWAF.ddwaf_object_stringl(obj, str, str.bytesize)
359
+ if res.null?
360
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
361
+ end
362
+
363
+ obj
364
+ when Integer
365
+ obj = LibDDWAF::Object.new
366
+ res = if coerce
367
+ LibDDWAF.ddwaf_object_string(obj, val.to_s)
368
+ elsif val < 0
369
+ LibDDWAF.ddwaf_object_signed(obj, val)
370
+ else
371
+ LibDDWAF.ddwaf_object_unsigned(obj, val)
372
+ end
373
+ if res.null?
374
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
375
+ end
376
+
377
+ obj
378
+ when Float
379
+ obj = LibDDWAF::Object.new
380
+ res = if coerce
381
+ LibDDWAF.ddwaf_object_string(obj, val.to_s)
382
+ else
383
+ LibDDWAF.ddwaf_object_float(obj, val)
384
+ end
385
+ if res.null?
386
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
387
+ end
388
+
389
+ obj
390
+ when TrueClass, FalseClass
391
+ obj = LibDDWAF::Object.new
392
+ res = if coerce
393
+ LibDDWAF.ddwaf_object_string(obj, val.to_s)
394
+ else
395
+ LibDDWAF.ddwaf_object_bool(obj, val)
396
+ end
397
+ if res.null?
398
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
399
+ end
400
+
401
+ obj
402
+ when NilClass
403
+ obj = LibDDWAF::Object.new
404
+ res = if coerce
405
+ LibDDWAF.ddwaf_object_string(obj, '')
406
+ else
407
+ LibDDWAF.ddwaf_object_null(obj)
408
+ end
409
+ if res.null?
410
+ fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
411
+ end
412
+
413
+ obj
414
+ else
415
+ ruby_to_object(''.freeze)
416
+ end
417
+ end
418
+ # rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
419
+
420
+ def self.object_to_ruby(obj)
421
+ case obj[:type]
422
+ when :ddwaf_obj_invalid, :ddwaf_obj_null
423
+ nil
424
+ when :ddwaf_obj_bool
425
+ obj[:valueUnion][:boolean]
426
+ when :ddwaf_obj_string
427
+ obj[:valueUnion][:stringValue].read_bytes(obj[:nbEntries])
428
+ when :ddwaf_obj_signed
429
+ obj[:valueUnion][:intValue]
430
+ when :ddwaf_obj_unsigned
431
+ obj[:valueUnion][:uintValue]
432
+ when :ddwaf_obj_float
433
+ obj[:valueUnion][:f64]
434
+ when :ddwaf_obj_array
435
+ (0...obj[:nbEntries]).each.with_object([]) do |i, a|
436
+ ptr = obj[:valueUnion][:array] + i * LibDDWAF::Object.size
437
+ e = object_to_ruby(LibDDWAF::Object.new(ptr))
438
+ a << e # steep:ignore
439
+ end
440
+ when :ddwaf_obj_map
441
+ (0...obj[:nbEntries]).each.with_object({}) do |i, h|
442
+ ptr = obj[:valueUnion][:array] + i * Datadog::AppSec::WAF::LibDDWAF::Object.size
443
+ o = Datadog::AppSec::WAF::LibDDWAF::Object.new(ptr)
444
+ l = o[:parameterNameLength]
445
+ k = o[:parameterName].read_bytes(l)
446
+ v = object_to_ruby(LibDDWAF::Object.new(ptr))
447
+ h[k] = v # steep:ignore
448
+ end
449
+ end
450
+ end
451
+
452
+ def self.log_callback(level, func, file, line, message, len)
453
+ return if logger.nil?
454
+
455
+ logger.debug do
456
+ {
457
+ level: level,
458
+ func: func,
459
+ file: file,
460
+ line: line,
461
+ message: message.read_bytes(len)
462
+ }.inspect
463
+ end
464
+ end
465
+
466
+ def self.logger
467
+ @logger
468
+ end
469
+
470
+ def self.logger=(logger)
471
+ unless @log_callback
472
+ log_callback = method(:log_callback)
473
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_set_log_cb(log_callback, :ddwaf_log_trace)
474
+
475
+ # retain logging proc if set properly
476
+ @log_callback = log_callback
477
+ end
478
+
479
+ @logger = logger
480
+ end
481
+
482
+ RESULT_CODE = {
483
+ ddwaf_err_internal: :err_internal,
484
+ ddwaf_err_invalid_object: :err_invalid_object,
485
+ ddwaf_err_invalid_argument: :err_invalid_argument,
486
+ ddwaf_ok: :ok,
487
+ ddwaf_match: :match,
488
+ }
489
+
490
+ class Handle
491
+ attr_reader :handle_obj, :diagnostics, :config
492
+
493
+ def initialize(rule, limits: {}, obfuscator: {})
494
+ rule_obj = Datadog::AppSec::WAF.ruby_to_object(rule)
495
+ if rule_obj.null? || rule_obj[:type] == :ddwaf_object_invalid
496
+ fail LibDDWAF::Error, "Could not convert object #{rule.inspect}"
497
+ end
498
+
499
+ config_obj = Datadog::AppSec::WAF::LibDDWAF::Config.new
500
+ if config_obj.null?
501
+ fail LibDDWAF::Error, 'Could not create config struct'
502
+ end
503
+
504
+ config_obj[:limits][:max_container_size] = limits[:max_container_size] || LibDDWAF::DEFAULT_MAX_CONTAINER_SIZE
505
+ config_obj[:limits][:max_container_depth] = limits[:max_container_depth] || LibDDWAF::DEFAULT_MAX_CONTAINER_DEPTH
506
+ config_obj[:limits][:max_string_length] = limits[:max_string_length] || LibDDWAF::DEFAULT_MAX_STRING_LENGTH
507
+ config_obj[:obfuscator][:key_regex] = FFI::MemoryPointer.from_string(obfuscator[:key_regex]) if obfuscator[:key_regex]
508
+ config_obj[:obfuscator][:value_regex] = FFI::MemoryPointer.from_string(obfuscator[:value_regex]) if obfuscator[:value_regex]
509
+ config_obj[:free_fn] = Datadog::AppSec::WAF::LibDDWAF::ObjectNoFree
510
+
511
+ @config = config_obj
512
+
513
+ diagnostics_obj = Datadog::AppSec::WAF::LibDDWAF::Object.new
514
+
515
+ @handle_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj, diagnostics_obj)
516
+
517
+ @diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj)
518
+
519
+ if @handle_obj.null?
520
+ fail LibDDWAF::Error.new('Could not create handle', diagnostics: @diagnostics)
521
+ end
522
+
523
+ validate!
524
+ ensure
525
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj
526
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj
527
+ end
528
+
529
+ def finalize
530
+ invalidate!
531
+
532
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_destroy(handle_obj)
533
+ end
534
+
535
+ def required_addresses
536
+ valid!
537
+
538
+ count = Datadog::AppSec::WAF::LibDDWAF::UInt32Ptr.new
539
+ list = Datadog::AppSec::WAF::LibDDWAF.ddwaf_known_addresses(handle_obj, count)
540
+
541
+ return [] if count == 0 # list is null
542
+
543
+ list.get_array_of_string(0, count[:value])
544
+ end
545
+
546
+ def merge(data)
547
+ data_obj = Datadog::AppSec::WAF.ruby_to_object(data, coerce: false)
548
+ diagnostics_obj = LibDDWAF::Object.new
549
+ new_handle = Datadog::AppSec::WAF::LibDDWAF.ddwaf_update(handle_obj, data_obj, diagnostics_obj)
550
+
551
+ return if new_handle.null?
552
+
553
+ diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj)
554
+ new_from_handle(new_handle, diagnostics, config)
555
+ ensure
556
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(data_obj) if data_obj
557
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj
558
+ end
559
+
560
+ private
561
+
562
+ def new_from_handle(handle_object, diagnostics, config)
563
+ obj = self.class.allocate
564
+ obj.instance_variable_set(:@handle_obj, handle_object)
565
+ obj.instance_variable_set(:@diagnostics, diagnostics)
566
+ obj.instance_variable_set(:@config, config)
567
+ obj
568
+ end
569
+
570
+ def validate!
571
+ @valid = true
572
+ end
573
+
574
+ def invalidate!
575
+ @valid = false
576
+ end
577
+
578
+ def valid?
579
+ @valid
580
+ end
581
+
582
+ def valid!
583
+ return if valid?
584
+
585
+ fail LibDDWAF::Error, "Attempt to use an invalid instance: #{inspect}"
586
+ end
587
+ end
588
+
589
+ class Result
590
+ attr_reader :status, :events, :total_runtime, :timeout, :actions, :derivatives
591
+
592
+ def initialize(status, events, total_runtime, timeout, actions, derivatives)
593
+ @status = status
594
+ @events = events
595
+ @total_runtime = total_runtime
596
+ @timeout = timeout
597
+ @actions = actions
598
+ @derivatives = derivatives
599
+ end
600
+ end
601
+
602
+ class Context
603
+ attr_reader :context_obj
604
+
605
+ def initialize(handle)
606
+ handle_obj = handle.handle_obj
607
+ retain(handle)
608
+
609
+ @context_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_context_init(handle_obj)
610
+ if @context_obj.null?
611
+ fail LibDDWAF::Error, 'Could not create context'
612
+ end
613
+
614
+ validate!
615
+ end
616
+
617
+ def finalize
618
+ invalidate!
619
+
620
+ retained.each do |retained_obj|
621
+ next unless retained_obj.is_a?(Datadog::AppSec::WAF::LibDDWAF::Object)
622
+
623
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(retained_obj)
624
+ end
625
+
626
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_context_destroy(context_obj)
627
+ end
628
+
629
+ def run(persistent_data, ephemeral_data, timeout = LibDDWAF::DDWAF_RUN_TIMEOUT)
630
+ valid!
631
+
632
+ persistent_data_obj = Datadog::AppSec::WAF.ruby_to_object(
633
+ persistent_data,
634
+ max_container_size: LibDDWAF::DDWAF_MAX_CONTAINER_SIZE,
635
+ max_container_depth: LibDDWAF::DDWAF_MAX_CONTAINER_DEPTH,
636
+ max_string_length: LibDDWAF::DDWAF_MAX_STRING_LENGTH,
637
+ coerce: false
638
+ )
639
+ if persistent_data_obj.null?
640
+ fail LibDDWAF::Error, "Could not convert persistent data: #{persistent_data.inspect}"
641
+ end
642
+
643
+ # retain C objects in memory for subsequent calls to run
644
+ retain(persistent_data_obj)
645
+
646
+ ephemeral_data_obj = Datadog::AppSec::WAF.ruby_to_object(
647
+ ephemeral_data,
648
+ max_container_size: LibDDWAF::DDWAF_MAX_CONTAINER_SIZE,
649
+ max_container_depth: LibDDWAF::DDWAF_MAX_CONTAINER_DEPTH,
650
+ max_string_length: LibDDWAF::DDWAF_MAX_STRING_LENGTH,
651
+ coerce: false
652
+ )
653
+ if ephemeral_data_obj.null?
654
+ fail LibDDWAF::Error, "Could not convert ephemeral data: #{ephemeral_data.inspect}"
655
+ end
656
+
657
+ result_obj = Datadog::AppSec::WAF::LibDDWAF::Result.new
658
+ if result_obj.null?
659
+ fail LibDDWAF::Error, "Could not create result object"
660
+ end
661
+
662
+ code = Datadog::AppSec::WAF::LibDDWAF.ddwaf_run(@context_obj, persistent_data_obj, ephemeral_data_obj, result_obj, timeout)
663
+
664
+ result = Result.new(
665
+ RESULT_CODE[code],
666
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:events]),
667
+ result_obj[:total_runtime],
668
+ result_obj[:timeout],
669
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:actions]),
670
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:derivatives]),
671
+ )
672
+
673
+ [RESULT_CODE[code], result]
674
+ ensure
675
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_result_free(result_obj) if result_obj
676
+ end
677
+
678
+ private
679
+
680
+ def validate!
681
+ @valid = true
682
+ end
683
+
684
+ def invalidate!
685
+ @valid = false
686
+ end
687
+
688
+ def valid?
689
+ @valid
690
+ end
691
+
692
+ def valid!
693
+ return if valid?
694
+
695
+ fail LibDDWAF::Error, "Attempt to use an invalid instance: #{inspect}"
696
+ end
697
+
698
+ def retained
699
+ @retained ||= []
700
+ end
701
+
702
+ def retain(object)
703
+ retained << object
704
+ end
705
+
706
+ def release(object)
707
+ retained.delete(object)
708
+ end
709
+ end
710
+ end
711
+ # rubocop:enable Metrics/ModuleLength
712
+ end
713
+ end
data/lib/libddwaf.rb ADDED
@@ -0,0 +1 @@
1
+ require 'datadog/appsec/waf'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libddwaf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.15.0.0.0
5
+ platform: aarch64-linux-musl
6
+ authors:
7
+ - Datadog, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-18 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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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
+ - CHANGELOG.md
37
+ - LICENSE
38
+ - LICENSE-3rdparty.csv
39
+ - LICENSE.Apache
40
+ - LICENSE.BSD3
41
+ - NOTICE
42
+ - lib/datadog/appsec/waf.rb
43
+ - lib/datadog/appsec/waf/version.rb
44
+ - lib/libddwaf.rb
45
+ - vendor/libddwaf/libddwaf-1.15.0-linux-aarch64/lib/libddwaf.so
46
+ homepage: https://github.com/DataDog/libddwaf-rb
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.5'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.0.0
65
+ requirements: []
66
+ rubygems_version: 3.5.21
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Datadog WAF
70
+ test_files: []