libddwaf 1.10.0.0.0-x86_64-darwin → 1.14.0.0.0-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '02248ee39e61d34007658043633b2a7120c8450325883eb52f1ab67a542e2fa7'
4
- data.tar.gz: fcf423136f88a75ca6419afc49e9565d867bc5d719e82dcb383d9d0064cc1179
3
+ metadata.gz: 01aa45a7f4d814627c8ba5673090c1e649fea6eca2bab27610c7419bbcf47e57
4
+ data.tar.gz: 8c9b9ee8a288f523a2aec7dc30790b61e596a9cd7f2862bbf5130e116a01f7c3
5
5
  SHA512:
6
- metadata.gz: f005a55fe1ace373bb987d791d12f2dfaca132f1fae4899545c7692e5d64727ff05a5c81a785fc4da1b93d314f90dd9bb980012aa96f533532d881db0242f57e
7
- data.tar.gz: 40dc280690d2560d128f47621a865703bdeebe5f26a56c1047d301dda45ff8795963f9f5e31febfe3a693d96161702436e8f61ecfed21ff3e680bf07cafa9927
6
+ metadata.gz: cae407afb5eb7df290143746428a86db76da82a48ccbdfff9fee763ddf61e728cdb47d345c545e2e2efcc852f670931344a687696a722131ab463d85c21dc9e7
7
+ data.tar.gz: 1d58b866a525292d2aa88602b015a2bcd8730ea644549888bc137bb8aaafa927d03913683fe6ed357324f6e3fce29ac519e57ea28f1c72ddc0b52a4c70252f63
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ # 2023-09-11 v.1.14.0.0.0
2
+ - Update to libddwaf 1.14.0
3
+ - Add support for `Float` and `Nil` scalar values when converting from ruby to WAF Object and vice versa.
4
+
5
+
6
+ # 2023-08-29 v.1.11.0.0.0
7
+
8
+ - Update to libddwaf 1.11.0
9
+ - Changed `Datadog::AppSec::WAF::Handle#ruleset_info` to `Datadog::AppSec::WAF::Handle#diagnostics``. (Breaking change)
10
+ The schema of the diagnostics variable can be found [here](https://github.com/DataDog/libddwaf/blob/master/schema/diagnostics.json)
11
+ - Changed `Datadog::AppSec::WAF::Result#data` to `Datadog::AppSec::WAF::Result#events`. (Breaking change)
12
+ The schema of the events variable can be found [here](https://github.com/DataDog/libddwaf/blob/master/schema/events.json)
13
+
14
+
15
+ # 2023-08-28 v.1.10.0.0.0
16
+
17
+ - Update to libddwaf 1.10.0
18
+
1
19
  # 2023-06-13 v.1.9.0.0.1
2
20
 
3
21
  - Handle invalid encoding
@@ -2,7 +2,7 @@ module Datadog
2
2
  module AppSec
3
3
  module WAF
4
4
  module VERSION
5
- BASE_STRING = '1.10.0'
5
+ BASE_STRING = '1.14.0'
6
6
  STRING = "#{BASE_STRING}.0.0"
7
7
  MINIMUM_RUBY_VERSION = '2.1'
8
8
  end
@@ -8,10 +8,10 @@ module Datadog
8
8
  module WAF
9
9
  module LibDDWAF
10
10
  class Error < StandardError
11
- attr_reader :ruleset_info
11
+ attr_reader :diagnostics
12
12
 
13
- def initialize(msg, ruleset_info: nil)
14
- @ruleset_info = ruleset_info
13
+ def initialize(msg, diagnostics: nil)
14
+ @diagnostics = diagnostics
15
15
  end
16
16
  end
17
17
 
@@ -111,7 +111,10 @@ module Datadog
111
111
  :ddwaf_obj_string, 1 << 2,
112
112
  :ddwaf_obj_array, 1 << 3,
113
113
  :ddwaf_obj_map, 1 << 4,
114
- :ddwaf_obj_bool, 1 << 5
114
+ :ddwaf_obj_bool, 1 << 5,
115
+ :ddwaf_obj_float, 1 << 6,
116
+ :ddwaf_obj_null, 1 << 7
117
+
115
118
  typedef DDWAF_OBJ_TYPE, :ddwaf_obj_type
116
119
 
117
120
  typedef :pointer, :charptr
@@ -140,7 +143,8 @@ module Datadog
140
143
  :uintValue, :uint64,
141
144
  :intValue, :int64,
142
145
  :array, :pointer,
143
- :boolean, :bool
146
+ :boolean, :bool,
147
+ :f64, :double
144
148
  end
145
149
 
146
150
  class Object < ::FFI::Struct
@@ -159,11 +163,13 @@ module Datadog
159
163
  attach_function :ddwaf_object_string, [:ddwaf_object, :string], :ddwaf_object
160
164
  attach_function :ddwaf_object_stringl, [:ddwaf_object, :charptr, :size_t], :ddwaf_object
161
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
162
168
  attach_function :ddwaf_object_unsigned, [:ddwaf_object, :uint64], :ddwaf_object
163
169
  attach_function :ddwaf_object_signed, [:ddwaf_object, :int64], :ddwaf_object
164
- attach_function :ddwaf_object_unsigned_force, [:ddwaf_object, :uint64], :ddwaf_object
165
- attach_function :ddwaf_object_signed_force, [:ddwaf_object, :int64], :ddwaf_object
166
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
167
173
 
168
174
  attach_function :ddwaf_object_array, [:ddwaf_object], :ddwaf_object
169
175
  attach_function :ddwaf_object_array_add, [:ddwaf_object, :ddwaf_object], :bool
@@ -184,6 +190,7 @@ module Datadog
184
190
  attach_function :ddwaf_object_get_signed, [:ddwaf_object], :int64
185
191
  attach_function :ddwaf_object_get_index, [:ddwaf_object, :size_t], :ddwaf_object
186
192
  attach_function :ddwaf_object_get_bool, [:ddwaf_object], :bool
193
+ attach_function :ddwaf_object_get_float, [:ddwaf_object], :double
187
194
 
188
195
  ## freeers
189
196
 
@@ -216,20 +223,8 @@ module Datadog
216
223
 
217
224
  typedef Config.by_ref, :ddwaf_config
218
225
 
219
- class RuleSetInfo < ::FFI::Struct
220
- layout :loaded, :uint16,
221
- :failed, :uint16,
222
- :errors, Object,
223
- :version, :string
224
- end
225
-
226
- typedef RuleSetInfo.by_ref, :ddwaf_ruleset_info
227
- RuleSetInfoNone = Datadog::AppSec::WAF::LibDDWAF::RuleSetInfo.new(::FFI::Pointer::NULL)
228
-
229
- attach_function :ddwaf_ruleset_info_free, [:ddwaf_ruleset_info], :void
230
-
231
- attach_function :ddwaf_init, [:ddwaf_rule, :ddwaf_config, :ddwaf_ruleset_info], :ddwaf_handle
232
- attach_function :ddwaf_update, [:ddwaf_handle, :ddwaf_object, :ddwaf_ruleset_info], :ddwaf_handle
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
233
228
  attach_function :ddwaf_destroy, [:ddwaf_handle], :void
234
229
 
235
230
  attach_function :ddwaf_required_addresses, [:ddwaf_handle, UInt32Ptr], :charptrptr
@@ -250,16 +245,12 @@ module Datadog
250
245
  attach_function :ddwaf_context_init, [:ddwaf_handle], :ddwaf_context
251
246
  attach_function :ddwaf_context_destroy, [:ddwaf_context], :void
252
247
 
253
- class ResultActions < ::FFI::Struct
254
- layout :array, :charptrptr,
255
- :size, :uint32
256
- end
257
-
258
248
  class Result < ::FFI::Struct
259
- layout :timeout, :bool,
260
- :data, :string,
261
- :actions, ResultActions,
262
- :total_runtime, :uint64
249
+ layout :timeout, :bool,
250
+ :events, Object,
251
+ :actions, Object,
252
+ :derivatives, Object,
253
+ :total_runtime, :uint64
263
254
  end
264
255
 
265
256
  typedef Result.by_ref, :ddwaf_result
@@ -297,7 +288,7 @@ module Datadog
297
288
  LibDDWAF.ddwaf_get_version
298
289
  end
299
290
 
300
- # rubocop:disable Metrics/MethodLength
291
+ # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
301
292
  def self.ruby_to_object(val, max_container_size: nil, max_container_depth: nil, max_string_length: nil, coerce: true)
302
293
  case val
303
294
  when Array
@@ -375,9 +366,9 @@ module Datadog
375
366
  res = if coerce
376
367
  LibDDWAF.ddwaf_object_string(obj, val.to_s)
377
368
  elsif val < 0
378
- LibDDWAF.ddwaf_object_signed_force(obj, val)
369
+ LibDDWAF.ddwaf_object_signed(obj, val)
379
370
  else
380
- LibDDWAF.ddwaf_object_unsigned_force(obj, val)
371
+ LibDDWAF.ddwaf_object_unsigned(obj, val)
381
372
  end
382
373
  if res.null?
383
374
  fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
@@ -386,7 +377,11 @@ module Datadog
386
377
  obj
387
378
  when Float
388
379
  obj = LibDDWAF::Object.new
389
- res = LibDDWAF.ddwaf_object_string(obj, val.to_s)
380
+ res = if coerce
381
+ LibDDWAF.ddwaf_object_string(obj, val.to_s)
382
+ else
383
+ LibDDWAF.ddwaf_object_float(obj, val)
384
+ end
390
385
  if res.null?
391
386
  fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
392
387
  end
@@ -403,16 +398,28 @@ module Datadog
403
398
  fail LibDDWAF::Error, "Could not convert into object: #{val.inspect}"
404
399
  end
405
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
+
406
413
  obj
407
414
  else
408
415
  ruby_to_object(''.freeze)
409
416
  end
410
417
  end
411
- # rubocop:enable Metrics/MethodLength
418
+ # rubocop:enable Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
412
419
 
413
420
  def self.object_to_ruby(obj)
414
421
  case obj[:type]
415
- when :ddwaf_obj_invalid
422
+ when :ddwaf_obj_invalid, :ddwaf_obj_null
416
423
  nil
417
424
  when :ddwaf_obj_bool
418
425
  obj[:valueUnion][:boolean]
@@ -422,6 +429,8 @@ module Datadog
422
429
  obj[:valueUnion][:intValue]
423
430
  when :ddwaf_obj_unsigned
424
431
  obj[:valueUnion][:uintValue]
432
+ when :ddwaf_obj_float
433
+ obj[:valueUnion][:f64]
425
434
  when :ddwaf_obj_array
426
435
  (0...obj[:nbEntries]).each.with_object([]) do |i, a|
427
436
  ptr = obj[:valueUnion][:array] + i * LibDDWAF::Object.size
@@ -479,7 +488,7 @@ module Datadog
479
488
  }
480
489
 
481
490
  class Handle
482
- attr_reader :handle_obj, :ruleset_info, :config
491
+ attr_reader :handle_obj, :diagnostics, :config
483
492
 
484
493
  def initialize(rule, limits: {}, obfuscator: {})
485
494
  rule_obj = Datadog::AppSec::WAF.ruby_to_object(rule)
@@ -501,24 +510,19 @@ module Datadog
501
510
 
502
511
  @config = config_obj
503
512
 
504
- ruleset_info = LibDDWAF::RuleSetInfo.new
513
+ diagnostics_obj = Datadog::AppSec::WAF::LibDDWAF::Object.new
505
514
 
506
- @handle_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj, ruleset_info)
515
+ @handle_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj, diagnostics_obj)
507
516
 
508
- @ruleset_info = {
509
- loaded: ruleset_info[:loaded],
510
- failed: ruleset_info[:failed],
511
- errors: WAF.object_to_ruby(ruleset_info[:errors]),
512
- version: ruleset_info[:version],
513
- }
517
+ @diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj)
514
518
 
515
519
  if @handle_obj.null?
516
- fail LibDDWAF::Error.new('Could not create handle', ruleset_info: @ruleset_info)
520
+ fail LibDDWAF::Error.new('Could not create handle', diagnostics: @diagnostics)
517
521
  end
518
522
 
519
523
  validate!
520
524
  ensure
521
- Datadog::AppSec::WAF::LibDDWAF.ddwaf_ruleset_info_free(ruleset_info) if ruleset_info
525
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj
522
526
  Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj
523
527
  end
524
528
 
@@ -541,29 +545,24 @@ module Datadog
541
545
 
542
546
  def merge(data)
543
547
  data_obj = Datadog::AppSec::WAF.ruby_to_object(data, coerce: false)
544
- ruleset_info = LibDDWAF::RuleSetInfo.new
545
- new_handle = Datadog::AppSec::WAF::LibDDWAF.ddwaf_update(handle_obj, data_obj, ruleset_info)
548
+ diagnostics_obj = LibDDWAF::Object.new
549
+ new_handle = Datadog::AppSec::WAF::LibDDWAF.ddwaf_update(handle_obj, data_obj, diagnostics_obj)
546
550
 
547
551
  return if new_handle.null?
548
552
 
549
- info = {
550
- loaded: ruleset_info[:loaded],
551
- failed: ruleset_info[:failed],
552
- errors: WAF.object_to_ruby(ruleset_info[:errors]),
553
- version: ruleset_info[:version],
554
- }
555
- new_from_handle(new_handle, info, config)
553
+ diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj)
554
+ new_from_handle(new_handle, diagnostics, config)
556
555
  ensure
557
556
  Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(data_obj) if data_obj
558
- Datadog::AppSec::WAF::LibDDWAF.ddwaf_ruleset_info_free(ruleset_info) if ruleset_info
557
+ Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj
559
558
  end
560
559
 
561
560
  private
562
561
 
563
- def new_from_handle(handle_object, info, config)
562
+ def new_from_handle(handle_object, diagnostics, config)
564
563
  obj = self.class.allocate
565
564
  obj.instance_variable_set(:@handle_obj, handle_object)
566
- obj.instance_variable_set(:@ruleset_info, info)
565
+ obj.instance_variable_set(:@diagnostics, diagnostics)
567
566
  obj.instance_variable_set(:@config, config)
568
567
  obj
569
568
  end
@@ -588,14 +587,15 @@ module Datadog
588
587
  end
589
588
 
590
589
  class Result
591
- attr_reader :status, :data, :total_runtime, :timeout, :actions
590
+ attr_reader :status, :events, :total_runtime, :timeout, :actions, :derivatives
592
591
 
593
- def initialize(status, data, total_runtime, timeout, actions)
592
+ def initialize(status, events, total_runtime, timeout, actions, derivatives)
594
593
  @status = status
595
- @data = data
594
+ @events = events
596
595
  @total_runtime = total_runtime
597
596
  @timeout = timeout
598
597
  @actions = actions
598
+ @derivatives = derivatives
599
599
  end
600
600
  end
601
601
 
@@ -636,7 +636,8 @@ module Datadog
636
636
  input_obj = Datadog::AppSec::WAF.ruby_to_object(input,
637
637
  max_container_size: max_container_size,
638
638
  max_container_depth: max_container_depth,
639
- max_string_length: max_string_length)
639
+ max_string_length: max_string_length,
640
+ coerce: false)
640
641
  if input_obj.null?
641
642
  fail LibDDWAF::Error, "Could not convert input: #{input.inspect}"
642
643
  end
@@ -651,18 +652,13 @@ module Datadog
651
652
 
652
653
  code = Datadog::AppSec::WAF::LibDDWAF.ddwaf_run(@context_obj, input_obj, result_obj, timeout)
653
654
 
654
- actions = if result_obj[:actions][:size] > 0
655
- result_obj[:actions][:array].get_array_of_string(0, result_obj[:actions][:size])
656
- else
657
- []
658
- end
659
-
660
655
  result = Result.new(
661
656
  RESULT_CODE[code],
662
- (JSON.parse(result_obj[:data]) if result_obj[:data] != nil),
657
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:events]),
663
658
  result_obj[:total_runtime],
664
659
  result_obj[:timeout],
665
- actions,
660
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:actions]),
661
+ Datadog::AppSec::WAF.object_to_ruby(result_obj[:derivatives]),
666
662
  )
667
663
 
668
664
  [RESULT_CODE[code], result]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libddwaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0.0.0
4
+ version: 1.14.0.0.0
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-28 00:00:00.000000000 Z
11
+ date: 2023-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -42,7 +42,7 @@ files:
42
42
  - lib/datadog/appsec/waf.rb
43
43
  - lib/datadog/appsec/waf/version.rb
44
44
  - lib/libddwaf.rb
45
- - vendor/libddwaf/libddwaf-1.10.0-darwin-x86_64/lib/libddwaf.dylib
45
+ - vendor/libddwaf/libddwaf-1.14.0-darwin-x86_64/lib/libddwaf.dylib
46
46
  homepage: https://github.com/DataDog/libddwaf-rb
47
47
  licenses:
48
48
  - BSD-3-Clause