waha-ruby 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc9414c7b9bb51ef5a2e118d72f6b0d33bc099b91ea8b705a11f6c17d63ca7ac
4
- data.tar.gz: 8fa5cba6397385326900b0d420a45fb2029c33350205c038046f0fd314588540
3
+ metadata.gz: b6143fc09b5ea2bfb45b55cba490a5b2f4b2527800991e8207f9f838c363998f
4
+ data.tar.gz: e740e63e91ffadba7ee5919d36722f973847c86818c244753535f98dca9cd70d
5
5
  SHA512:
6
- metadata.gz: 69d17352f8e08d07e2d86948a31c7079ff7cdacb7b9bca0ac91f72a292caa6eb50e5f7c9a9ba90d4b7b4886cc3ba7683a544176a77c1f56e9de643c6852e935a
7
- data.tar.gz: 29707e3dfac2eca128adc7ab801e5e062d523944a32db35d0500870fb46b4dfcedeb2c6523828108a0dc556735b91e129bcf1a60d6e6e17c3e176335773ac7f4
6
+ metadata.gz: 63f59ffd2b58f82e9ca8e925b5e8c07958e8e508f12a1df49c73cc9ffaf3311b7be6546632d988b987ac35cd11169bfe9effd2896642763a371501a6e04a2462
7
+ data.tar.gz: 4dee276f3bbfbb301a9f4beaa499c92e0bbba61ada941acef1487bcbe041539f21746f071679b8359044bb11d97a8761905ff06d37cc5b64cf3353b8001f39ec
data/.rubocop.yml CHANGED
@@ -30,12 +30,12 @@ Metrics/ClassLength:
30
30
  Metrics/ParameterLists:
31
31
  Exclude:
32
32
  - "lib/waha/resources/messages.rb"
33
- - "lib/waha/transport/http_party.rb"
33
+ - "lib/waha/transport/faraday.rb"
34
34
 
35
35
  Metrics/AbcSize:
36
36
  Exclude:
37
37
  - "lib/waha/resources/messages.rb"
38
- - "lib/waha/transport/http_party.rb"
38
+ - "lib/waha/transport/faraday.rb"
39
39
 
40
40
  Layout/LineLength:
41
41
  Exclude:
data/CHANGELOG.md CHANGED
@@ -8,6 +8,20 @@ and this project adheres to
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ### Fixed
12
+
13
+ - `Waha::Webhook.verify!` fails closed when the secret is nil, empty, or
14
+ blank, preventing signature forgery against unconfigured consumers.
15
+ - Webhook comparison delegates to `OpenSSL.secure_compare` for native
16
+ constant-time comparison.
17
+ - `Waha::Resources::Media#download` only accepts media URLs served by the
18
+ configured WAHA host; all loopback origins (`localhost`, `127.0.0.1`,
19
+ `::1`) rebase to the base URL, closing an SSRF and API-key exfiltration
20
+ vector.
21
+ - `Waha::Resources::Webhooks` deep duplication uses identity-based
22
+ memoization so value-equal config entries no longer alias each other.
23
+ - Chats message query keyword `last_message_id` maps to `lastMessageId`.
24
+
11
25
  ## [0.1.0] - 2026-09-09
12
26
 
13
27
  ### Added
@@ -6,6 +6,7 @@ module Waha
6
6
  module Resources
7
7
  class Media < Resource
8
8
  DOWNLOAD_TIMEOUT = 60
9
+ LOOPBACK_HOSTS = %w[localhost 127.0.0.1 ::1].freeze
9
10
 
10
11
  def initialize(transport:, base_url:)
11
12
  super(transport:, session: nil)
@@ -36,19 +37,26 @@ module Waha
36
37
  raise ValidationError.new(operation: "download_media", details: "unsupported media URL scheme")
37
38
  end
38
39
 
39
- return uri.to_s unless uri.host == "localhost"
40
+ return rebase_to_base_url(uri) if LOOPBACK_HOSTS.include?(uri.host)
40
41
 
41
- rebase_to_base_url(uri)
42
+ unless uri.host == base_uri.host
43
+ raise ValidationError.new(operation: "download_media", details: "media URL host is not the WAHA server")
44
+ end
45
+
46
+ uri.to_s
42
47
  end
43
48
 
44
49
  def rebase_to_base_url(uri)
45
- base_uri = URI.parse(@base_url)
46
50
  uri.scheme = base_uri.scheme
47
51
  uri.host = base_uri.host
48
52
  uri.port = base_uri.port
49
53
  uri.to_s
50
54
  end
51
55
 
56
+ def base_uri
57
+ @base_uri ||= URI.parse(@base_url.to_s)
58
+ end
59
+
52
60
  def parse_uri(url)
53
61
  text = url.to_s
54
62
  uri = URI.parse(text)
@@ -63,7 +63,7 @@ module Waha
63
63
  Support.value(session_data, "name") || fallback
64
64
  end
65
65
 
66
- def deep_dup(value, seen = {})
66
+ def deep_dup(value, seen = {}.compare_by_identity)
67
67
  return value unless value.is_a?(Hash) || value.is_a?(Array)
68
68
  return seen[value] if seen.key?(value)
69
69
 
data/lib/waha/support.rb CHANGED
@@ -21,7 +21,7 @@ module Waha
21
21
  sort_by: "sortBy",
22
22
  sort_order: "sortOrder",
23
23
  last_message_timestamp: "lastMessageTimestamp",
24
- last_message_lid: "lastMessageId",
24
+ last_message_id: "lastMessageId",
25
25
  contact_id: "contactId",
26
26
  phone_number: "phoneNumber"
27
27
  }.freeze
data/lib/waha/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Waha
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/waha/webhook.rb CHANGED
@@ -9,10 +9,14 @@ module Waha
9
9
  module_function
10
10
 
11
11
  def verify!(body:, signature:, algorithm:, secret:)
12
+ if secret.to_s.strip.empty?
13
+ raise VerificationError.new(operation: "verify_webhook", details: "secret is required")
14
+ end
15
+
12
16
  verify_algorithm!(algorithm)
13
17
  signature_text = verified_signature_text(signature)
14
18
  expected = OpenSSL::HMAC.hexdigest(DIGEST, secret.to_s, body.to_s)
15
- return true if secure_compare?(signature_text, expected)
19
+ return true if OpenSSL.secure_compare(signature_text, expected)
16
20
 
17
21
  raise VerificationError.new(operation: "verify_webhook", details: "signature mismatch")
18
22
  end
@@ -32,18 +36,5 @@ module Waha
32
36
  raise VerificationError.new(operation: "verify_webhook", details: "malformed signature")
33
37
  end
34
38
  private_class_method :verified_signature_text
35
-
36
- def secure_compare?(signature, expected)
37
- signature.bytesize == expected.bytesize && secure_bytes_equal?(signature, expected)
38
- end
39
- private_class_method :secure_compare?
40
-
41
- def secure_bytes_equal?(left, right)
42
- left_bytes = left.unpack("C*")
43
- right_bytes = right.unpack("C*")
44
- comparison = left_bytes.zip(right_bytes).reduce(0) { |result, pair| result | (pair[0] ^ pair[1]) }
45
- comparison.zero?
46
- end
47
- private_class_method :secure_bytes_equal?
48
39
  end
49
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waha-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Zaffari
@@ -251,7 +251,7 @@ licenses:
251
251
  - MIT
252
252
  metadata:
253
253
  homepage_uri: https://github.com/develoz-com/waha-ruby
254
- source_code_uri: https://github.com/develoz-com/waha-ruby/tree/v0.1.0
254
+ source_code_uri: https://github.com/develoz-com/waha-ruby/tree/v0.1.1
255
255
  changelog_uri: https://github.com/develoz-com/waha-ruby/blob/main/CHANGELOG.md
256
256
  rubygems_mfa_required: 'true'
257
257
  rdoc_options: []