libddwaf 1.0.12.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 149b110d2839d0a87023bcb956689ecc5a65c366080979a7fbdd458a59f2f928
4
+ data.tar.gz: 8d5181f1cb4e98ed8aa065a948480de18a032f5a7c31f084b936e6b10800d81b
5
+ SHA512:
6
+ metadata.gz: 83006f3f968659cd4701f87469bd8b570bb1f245282b4a2c037a45f2e7b71bd3f4def34cba9ace7eefdd2eb0d0ba269b9d0c1301920610bd8ad0d97138413f45
7
+ data.tar.gz: 31dc16a314fd59ccafb97ad828e9ac8ddfadda8b44e412f9067ae982328e5582b5d6b66e24f9d992231b0f494949b9d2cee4ce09177a3af51488d5f5c9dc304f
@@ -0,0 +1,135 @@
1
+ name: Package
2
+ on:
3
+ - push
4
+
5
+ jobs:
6
+ package:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ include:
11
+ - os: ubuntu-20.04
12
+ cpu: x86_64
13
+ platform: x86_64-linux
14
+ - os: ubuntu-20.04
15
+ cpu: aarch64
16
+ platform: aarch64-linux
17
+ - os: macos-10.15
18
+ cpu: x86_64
19
+ platform: x86_64-darwin
20
+ - os: macos-10.15
21
+ cpu: arm64
22
+ platform: arm64-darwin
23
+ name: Build package (${{ matrix.platform }})
24
+ runs-on: ${{ matrix.os }}
25
+ steps:
26
+ - name: Checkout
27
+ uses: actions/checkout@v2
28
+ - name: Install Linux build tools
29
+ if: ${{ startsWith(matrix.os, 'ubuntu-') }}
30
+ run: sudo apt-get install -y ruby ruby-bundler
31
+ - name: Bundle
32
+ run: |
33
+ bundle install
34
+ - name: Fetch binary library
35
+ run: |
36
+ bundle exec rake fetch[${{ matrix.platform }}]
37
+ - name: Extract binary library
38
+ run: |
39
+ bundle exec rake extract[${{ matrix.platform }}]
40
+ - name: Build package
41
+ run: |
42
+ bundle exec rake binary[${{ matrix.platform }}]
43
+ - name: Upload gem
44
+ uses: actions/upload-artifact@v2
45
+ with:
46
+ name: libddwaf-${{ matrix.platform }}-${{ github.run_id }}-${{ github.sha }}
47
+ path: pkg
48
+ test-linux:
49
+ needs: package
50
+ strategy:
51
+ fail-fast: false
52
+ matrix:
53
+ include:
54
+ - os: ubuntu-20.04
55
+ cpu: x86_64
56
+ platform: x86_64-linux
57
+ image: ruby:2.6
58
+ qemu: amd64
59
+ libc: gnu
60
+ - os: ubuntu-20.04
61
+ cpu: aarch64
62
+ platform: aarch64-linux
63
+ image: ruby:2.6
64
+ qemu: aarch64
65
+ libc: gnu
66
+ - os: ubuntu-20.04
67
+ cpu: x86_64
68
+ platform: x86_64-linux
69
+ image: ruby:2.6-alpine
70
+ qemu: amd64
71
+ libc: musl
72
+ - os: ubuntu-20.04
73
+ cpu: aarch64
74
+ platform: aarch64-linux
75
+ image: ruby:2.6-alpine
76
+ qemu: aarch64
77
+ libc: musl
78
+ name: Test package (${{ matrix.platform }}-${{ matrix.libc }})
79
+ runs-on: ${{ matrix.os }}
80
+ steps:
81
+ - name: Enable ${{ matrix.qemu }} platform
82
+ id: qemu
83
+ if: ${{ matrix.cpu != 'amd64' }}
84
+ run: |
85
+ docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.qemu }} | tee platforms.json
86
+ echo "::set-output name=platforms::$(cat platforms.json)"
87
+ - name: Start container
88
+ id: container
89
+ run: |
90
+ echo ${{ matrix.image }} > container_image
91
+ docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.qemu }} ${{ matrix.image }} /bin/sleep 64d | tee container_id
92
+ docker exec -w "${PWD}" $(cat container_id) uname -a
93
+ echo "::set-output name=id::$(cat container_id)"
94
+ - uses: actions/download-artifact@v2
95
+ with:
96
+ name: libddwaf-${{ matrix.platform }}-${{ github.run_id }}-${{ github.sha }}
97
+ path: pkg
98
+ - name: List artifact files
99
+ run: find .
100
+ working-directory: pkg
101
+ - name: Install Alpine system dependencies
102
+ if: ${{ matrix.libc == 'musl' }}
103
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base
104
+ - name: Install gem
105
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem install --verbose pkg/*.gem
106
+ - name: Run smoke test
107
+ run: |
108
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} ruby -r 'libddwaf' -e 'v = Datadog::Security::WAF::LibDDWAF::Version.new; Datadog::Security::WAF::LibDDWAF.ddwaf_get_version(v); p [v[:major], v[:minor], v[:patch]]'
109
+ test-darwin:
110
+ needs: package
111
+ strategy:
112
+ fail-fast: false
113
+ matrix:
114
+ include:
115
+ - os: macos-10.15
116
+ cpu: x86_64
117
+ platform: x86_64-darwin
118
+ # - os: macos-11.0
119
+ # cpu: arm64
120
+ # platform: arm64-darwin
121
+ name: Test package (${{ matrix.platform }})
122
+ runs-on: ${{ matrix.os }}
123
+ steps:
124
+ - uses: actions/download-artifact@v2
125
+ with:
126
+ name: libddwaf-${{ matrix.platform }}-${{ github.run_id }}-${{ github.sha }}
127
+ path: pkg
128
+ - name: List artifact files
129
+ run: find .
130
+ working-directory: pkg
131
+ - name: Install gem
132
+ run: gem install --verbose pkg/*.gem
133
+ - name: Run smoke test
134
+ run: |
135
+ ruby -r 'libddwaf' -e 'v = Datadog::Security::WAF::LibDDWAF::Version.new; Datadog::Security::WAF::LibDDWAF.ddwaf_get_version(v); p [v[:major], v[:minor], v[:patch]]'
@@ -0,0 +1,201 @@
1
+ name: Test
2
+ on:
3
+ - push
4
+
5
+ jobs:
6
+ test-linux:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ include:
11
+ - os: ubuntu-20.04
12
+ cpu: x86_64
13
+ platform: x86_64-linux
14
+ image: ruby:3.0
15
+ qemu: amd64
16
+ libc: gnu
17
+ - os: ubuntu-20.04
18
+ cpu: aarch64
19
+ platform: aarch64-linux
20
+ image: ruby:3.0
21
+ qemu: arm64
22
+ libc: gnu
23
+ - os: ubuntu-20.04
24
+ cpu: x86_64
25
+ platform: x86_64-linux
26
+ image: ruby:2.7
27
+ qemu: amd64
28
+ libc: gnu
29
+ - os: ubuntu-20.04
30
+ cpu: aarch64
31
+ platform: aarch64-linux
32
+ image: ruby:2.7
33
+ qemu: arm64
34
+ libc: gnu
35
+ - os: ubuntu-20.04
36
+ cpu: x86_64
37
+ platform: x86_64-linux
38
+ image: ruby:2.6
39
+ qemu: amd64
40
+ libc: gnu
41
+ - os: ubuntu-20.04
42
+ cpu: aarch64
43
+ platform: aarch64-linux
44
+ image: ruby:2.6
45
+ qemu: arm64
46
+ libc: gnu
47
+ - os: ubuntu-20.04
48
+ cpu: x86_64
49
+ platform: x86_64-linux
50
+ image: ruby:2.5
51
+ qemu: amd64
52
+ libc: gnu
53
+ - os: ubuntu-20.04
54
+ cpu: x86_64
55
+ platform: x86_64-linux
56
+ image: ruby:2.4
57
+ qemu: amd64
58
+ libc: gnu
59
+ - os: ubuntu-20.04
60
+ cpu: x86_64
61
+ platform: x86_64-linux
62
+ image: ruby:2.3
63
+ qemu: amd64
64
+ libc: gnu
65
+ - os: ubuntu-20.04
66
+ cpu: x86_64
67
+ platform: x86_64-linux
68
+ image: ruby:2.2
69
+ qemu: amd64
70
+ libc: gnu
71
+ - os: ubuntu-20.04
72
+ cpu: x86_64
73
+ platform: x86_64-linux
74
+ image: ruby:2.1
75
+ qemu: amd64
76
+ libc: gnu
77
+ - os: ubuntu-20.04
78
+ cpu: x86_64
79
+ platform: x86_64-linux
80
+ image: ruby:3.0-alpine
81
+ qemu: amd64
82
+ libc: musl
83
+ - os: ubuntu-20.04
84
+ cpu: aarch64
85
+ platform: aarch64-linux
86
+ image: ruby:3.0-alpine
87
+ qemu: arm64
88
+ libc: musl
89
+ - os: ubuntu-20.04
90
+ cpu: x86_64
91
+ platform: x86_64-linux
92
+ image: ruby:2.7-alpine
93
+ qemu: amd64
94
+ libc: musl
95
+ - os: ubuntu-20.04
96
+ cpu: aarch64
97
+ platform: aarch64-linux
98
+ image: ruby:2.7-alpine
99
+ qemu: arm64
100
+ libc: musl
101
+ - os: ubuntu-20.04
102
+ cpu: x86_64
103
+ platform: x86_64-linux
104
+ image: ruby:2.6-alpine
105
+ qemu: amd64
106
+ libc: musl
107
+ - os: ubuntu-20.04
108
+ cpu: aarch64
109
+ platform: aarch64-linux
110
+ image: ruby:2.6-alpine
111
+ qemu: arm64
112
+ libc: musl
113
+ # TODO: jruby images have no sudo so apt-get can't get a lock
114
+ # - os: ubuntu-20.04
115
+ # cpu: x86_64
116
+ # platform: x86_64-linux
117
+ # image: jruby:9.3
118
+ # qemu: amd64
119
+ # libc: gnu
120
+ # - os: ubuntu-20.04
121
+ # cpu: x86_64
122
+ # platform: x86_64-linux
123
+ # image: jruby:9.2
124
+ # qemu: amd64
125
+ # libc: gnu
126
+ # - os: ubuntu-20.04
127
+ # cpu: x86_64
128
+ # platform: x86_64-linux
129
+ # image: jruby:9.1
130
+ # qemu: amd64
131
+ # libc: gnu
132
+ name: Test (${{ matrix.image }}, ${{ matrix.cpu }})
133
+ runs-on: ${{ matrix.os }}
134
+ steps:
135
+ - name: Enable ${{ matrix.qemu }} platform
136
+ id: qemu
137
+ if: ${{ matrix.cpu != 'amd64' }}
138
+ run: |
139
+ docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.qemu }} | tee platforms.json
140
+ echo "::set-output name=platforms::$(cat platforms.json)"
141
+ - name: Start container
142
+ id: container
143
+ run: |
144
+ echo ${{ matrix.image }} > container_image
145
+ docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.qemu }} ${{ matrix.image }} /bin/sleep 64d | tee container_id
146
+ docker exec -w "${PWD}" $(cat container_id) uname -a
147
+ echo "::set-output name=id::$(cat container_id)"
148
+ - name: Install Alpine system dependencies
149
+ if: ${{ matrix.libc == 'musl' }}
150
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base git
151
+ - name: Install JRuby system dependencies
152
+ if: ${{ startsWith(matrix.image, 'jruby') }}
153
+ run: |
154
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} sudo apt-get update
155
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} sudo apt-get install -y build-essential git
156
+ - name: Checkout
157
+ uses: actions/checkout@v2
158
+ - name: Bundle
159
+ run: |
160
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
161
+ - name: Fetch binary library
162
+ run: |
163
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake fetch[${{ matrix.platform }}]
164
+ - name: Extract binary library
165
+ run: |
166
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake extract[${{ matrix.platform }}]
167
+ - name: Run specs
168
+ run: |
169
+ docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake spec
170
+ test-darwin:
171
+ strategy:
172
+ fail-fast: false
173
+ matrix:
174
+ include:
175
+ - os: macos-10.15
176
+ cpu: x86_64
177
+ platform: x86_64-darwin
178
+ - os: macos-11.0
179
+ cpu: x86_64
180
+ platform: x86_64-darwin
181
+ # - os: macos-11.0
182
+ # cpu: arm64
183
+ # platform: arm64-darwin
184
+ name: Test (${{ matrix.os }} ${{ matrix.cpu }})
185
+ runs-on: ${{ matrix.os }}
186
+ steps:
187
+ - name: Checkout
188
+ uses: actions/checkout@v2
189
+ - name: Bundle
190
+ run: |
191
+ bundle install
192
+ - name: Fetch binary library
193
+ run: |
194
+ bundle exec rake fetch[${{ matrix.platform }}]
195
+ - name: Extract binary library
196
+ run: |
197
+ bundle exec rake extract[${{ matrix.platform }}]
198
+ - name: Run specs
199
+ run: |
200
+ bundle exec rake spec
201
+
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ Gemfile.lock
2
+ /.envrc
3
+ /vendor/bundle
4
+ /vendor/libddwaf
5
+ /*.nix
6
+ /pkg
7
+ *.gem
8
+ *.vim
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,84 @@
1
+ # Contributing
2
+
3
+ Community contributions to the Datadog bindings to libddwaf for Ruby are welcome! See below for some basic guidelines.
4
+
5
+ ## Want to request a new feature?
6
+
7
+ Many great ideas for new features come from the community, and we'd be happy to consider yours!
8
+
9
+ To share your request, you can [open a Github issue](https://github.com/DataDog/libddwaf-rb/issues/new) with the details about what you'd like to see. At a minimum, please provide:
10
+
11
+ - The goal of the new feature
12
+ - A description of how it might be used or behave
13
+ - Links to any important resources (e.g. Github repos, websites, screenshots, specifications, diagrams)
14
+
15
+ Additionally, if you can, include:
16
+
17
+ - A description of how it could be accomplished
18
+ - Code snippets that might demonstrate its use or implementation
19
+ - Screenshots or mockups that visually demonstrate the feature
20
+ - Links to similar features that would serve as a good comparison
21
+ - (Any other details that would be useful for implementing this feature!)
22
+
23
+ Feature requests will be reviewed and discussed.
24
+
25
+ ## Found a bug?
26
+
27
+ For any urgent matters (such as outages) or issues concerning the Datadog service or UI, contact our support team via https://docs.datadoghq.com/help/ for direct, faster assistance.
28
+
29
+ You may submit bug reports concerning the Datadog bindings to libddwaf for Ruby by [opening a Github issue](https://github.com/DataDog/libddwaf-rb/issues/new). At a minimum, please provide:
30
+
31
+ - A description of the problem
32
+ - Steps to reproduce
33
+ - Expected behavior
34
+ - Actual behavior
35
+ - Errors (with stack traces) or warnings received
36
+ - Any details you can share about your configuration including:
37
+ - Ruby version & platform
38
+ - `libddwaf` version
39
+ - Versions of any other relevant gems (or a `Gemfile.lock` if available)
40
+
41
+ If at all possible, also provide:
42
+
43
+ - Logs from the application or other diagnostics
44
+ - Screenshots, links, or other visual aids that are publicly accessible
45
+ - Code sample or test that reproduces the problem
46
+ - An explanation of what causes the bug and/or how it can be fixed
47
+
48
+ Reports that include rich detail are better, and ones with code that reproduce the bug are best. Bug requests will be triaged and reviewed by our collaborators.
49
+
50
+ ## Have a patch?
51
+
52
+ We welcome code contributions to the library, which you can [submit as a pull request](https://github.com/DataDog/libddwaf-rb/pull/new/master). To create a pull request:
53
+
54
+ 1. **Fork the repository** from https://github.com/DataDog/libddwaf-rb
55
+ 2. **Make any changes** for your patch.
56
+ 3. **Write tests** that demonstrate how the feature works or how the bug is fixed.
57
+ 4. **Update any documentation** especially for new features.
58
+ 5. **Submit the pull request** from your fork back to the latest revision of the `master` branch on https://github.com/DataDog/libddwaf-rb.
59
+
60
+ The pull request will be run through our CI pipeline, and a project member will review the changes with you. At a minimum, to be accepted and merged, pull requests must:
61
+
62
+ - Have a stated goal and detailed description of the changes made
63
+ - Include thorough test coverage and documentation, where applicable
64
+ - Pass all tests and code quality checks (linting/coverage) on CI
65
+ - Receive at least one approval from a project member with push permissions
66
+
67
+ We also recommend that you share in your description:
68
+
69
+ - Any motivations or intent for the contribution
70
+ - Links to any issues/pull requests it might be related to
71
+ - Links to any webpages or other external resources that might be related to the change
72
+ - Screenshots, code samples, or other visual aids that demonstrate the changes or how they are implemented
73
+ - Benchmarks if the feature is anticipated to have performance implications
74
+ - Any limitations, constraints or risks that are important to consider
75
+
76
+ Pull requests will be reviewed by our collaborators.
77
+
78
+ For more information on common topics such as debugging locally, or how to write new integrations, check out [our development guide](https://github.com/DataDog/libddwaf-rb/blob/master/README.md#development). If at any point you have a question or need assistance with your pull request, feel free to mention a project member! We're always happy to help contributors with their pull requests.
79
+
80
+ ## Final word
81
+
82
+ Many thanks to all of our contributors, and looking forward to seeing you on Github! :tada:
83
+
84
+ - Datadog Ruby Team
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/).
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # libddwaf Ruby bindings
2
+
3
+ ``libddwaf-rb`` is library exposing the libddwaf C++ library to Ruby, packaging it in a multiplatform gem.
4
+
5
+ For the libddwaf implementation, see this repository:
6
+ - [``libddwaf``: libddwaf](https://github.com/DataDog/libddwaf.git)
@@ -0,0 +1,12 @@
1
+ module Datadog
2
+ module Security
3
+ module WAF
4
+ module VERSION
5
+ BASE_STRING = '1.0.12'
6
+ STRING = "#{BASE_STRING}.0.0.beta1"
7
+ MINIMUM_RUBY_VERSION = '2.1'
8
+ MAXIMUM_RUBY_VERSION = '3.1'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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'
data/libddwaf.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'datadog/security/waf/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'libddwaf'
9
+ spec.version = Datadog::Security::WAF::VERSION::STRING
10
+ spec.required_ruby_version = [">= #{Datadog::Security::WAF::VERSION::MINIMUM_RUBY_VERSION}", "< #{Datadog::Security::WAF::VERSION::MAXIMUM_RUBY_VERSION}"]
11
+ spec.required_rubygems_version = '>= 2.0.0'
12
+ spec.authors = ['Datadog, Inc.']
13
+ spec.email = ['dev@datadoghq.com']
14
+
15
+ spec.summary = 'Datadog WAF'
16
+ spec.description = <<-EOS.gsub(/^[\s]+/, '')
17
+ libddwaf packages a WAF implementation in C++, exposed to Ruby
18
+ EOS
19
+
20
+ spec.homepage = 'https://github.com/DataDog/libddwaf'
21
+ spec.license = 'BSD-3-Clause'
22
+
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
27
+ end
28
+
29
+ spec.files =
30
+ `git ls-files -z`
31
+ .split("\x0")
32
+ .reject { |f| f.match(%r{^(spec|[.]circleci)/}) }
33
+ .reject do |f|
34
+ ['.dockerignore', '.env', '.rspec', '.rubocop.yml', '.rubocop_todo.yml',
35
+ '.simplecov', 'Gemfile', 'Rakefile', 'docker-compose.yml'].include?(f)
36
+ end
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_dependency 'ffi'
40
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libddwaf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.12.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Datadog, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-01 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
+ - ".github/workflows/package.yml"
37
+ - ".github/workflows/test.yml"
38
+ - ".gitignore"
39
+ - CONTRIBUTING.md
40
+ - LICENSE
41
+ - LICENSE-3rdparty.csv
42
+ - LICENSE.Apache
43
+ - LICENSE.BSD3
44
+ - NOTICE
45
+ - README.md
46
+ - lib/datadog/security/waf.rb
47
+ - lib/datadog/security/waf/version.rb
48
+ - lib/libddwaf.rb
49
+ - libddwaf.gemspec
50
+ homepage: https://github.com/DataDog/libddwaf
51
+ licenses:
52
+ - BSD-3-Clause
53
+ metadata:
54
+ allowed_push_host: https://rubygems.org
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '2.1'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.1'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.0.0
72
+ requirements: []
73
+ rubygems_version: 3.2.16
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Datadog WAF
77
+ test_files: []