ruby-whatsapp 0.3.0 → 0.3.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: 1149fca141867e8a80ee6276d8e39ea1a814630964d6d219119fb80c919de35b
4
- data.tar.gz: a2d1a15a8a17f9b0065cf36ded985a329b35b9a7e7ef6408b0ba817551d90085
3
+ metadata.gz: 87f6d35b2ab7e711f12f6b3c6fe0598f0c6d46f6b69c2144827dac7cf1324ab2
4
+ data.tar.gz: 548dcf049e669ac9d79ef5b7d0b72d1d6324c04f8440b43ddc3849da8976c2cf
5
5
  SHA512:
6
- metadata.gz: 6bd1b41cd41a1745923e23445d1df5fc4af58bcccf52c3e88346b5064276bcc0d046f25e23a7905987393e5dab13571b04f92fcde7fbf1cd8a2bde6ede839330
7
- data.tar.gz: a4e8dbb9bafa710512201d6b1e588c9b0193e64a43f3afc4cb08acec5a5fc45f1ce80ec3f5fe3da98f876b0a4cf26bbf6ef432d9f3305d6cab15ef05502bf14f
6
+ metadata.gz: edd6bac30de43279bd6a964e724606974eec99c729649b5eb647635ff1088264d1539ecec627bd101ef3599dd96b3536dddfbb212e76ea95894225b860f6c0dc
7
+ data.tar.gz: a2eb64df9a84e90f0453e96f884a3740942eea31fa73512eea7f8bedb4057314d382ba60da2a36e8ba7cc7a7a2851e23575aa989f8392ab4b784d5a2da13aa7a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2026-08-13
4
+
5
+ - Fix `Client#inspect` leaking the raw `api_key` in its default output — and, through it, any object holding a client (`Media#inspect`, `MessageTemplates#inspect`). Now redacted the same way `Configuration#inspect` already was. If a token may have reached an error tracker or console output that captures local variables, rotate it.
6
+ - Fix `Client#path_for` passing IDs into the request path unencoded. A caller-supplied ID (e.g. `template_id`, `media_id`) could inject a query string or redirect an authenticated request to a different Graph API edge. Segments are now percent-encoded.
7
+ - Fix `Webhook::Signature.valid?` raising `TypeError` instead of returning `false` for a `nil` payload.
8
+
3
9
  ## [0.3.0] - 2026-08-05
4
10
 
5
11
  - Add template management: `Whatsapp::MessageTemplates` provides full CRUD over the templates on a WhatsApp Business Account — `create`, `list`, `find`, `update`, `delete`, plus `upsert` for multi-language authentication templates and `create_from_library` for Meta's pre-written library. Templates are built from validated value objects (`Template`, `ComponentSet`, `Component::*`, `Button::*`) that enforce Meta's documented rules — name format, character limits, placeholder/example matching, quick-reply contiguity, carousel structure, limited-time-offer restrictions — before a request is made, so a rejection costs nothing instead of a review cycle. Covers standard, authentication/OTP, carousel, limited-time-offer, and library templates.
data/README.md CHANGED
@@ -64,7 +64,7 @@ Whatsapp.configure do |config|
64
64
  end
65
65
  ```
66
66
 
67
- `api_key`, `app_secret`, and `verify_token` are redacted from `Configuration#inspect`, so they will not leak into logs.
67
+ `api_key`, `app_secret`, and `verify_token` are redacted from `Configuration#inspect` and `Client#inspect`, so they will not leak into logs or error reports.
68
68
 
69
69
  ## Quick Start
70
70
 
@@ -5,6 +5,9 @@ module Whatsapp
5
5
  # Default request timeout in seconds.
6
6
  DEFAULT_TIMEOUT = 30
7
7
 
8
+ # Characters that must be percent-escaped in a path segment (everything except RFC 3986 "unreserved").
9
+ SEGMENT_UNRESERVED = /[^A-Za-z0-9\-._~]/
10
+
8
11
  # @!attribute [rw] host
9
12
  # @return [String]
10
13
  attr_accessor :host
@@ -69,14 +72,32 @@ module Whatsapp
69
72
  end
70
73
  end
71
74
 
72
- # Builds a versioned request path.
75
+ # Builds a versioned request path. Segments are percent-encoded so a caller-supplied
76
+ # ID can't inject a query string or redirect to a different Graph edge.
73
77
  # @example
74
78
  # path_for(phone_id, "messages") #=> "/v24.0/<phone_id>/messages"
75
79
  # path_for(media_id) #=> "/v24.0/<media_id>"
76
80
  # @param segments [Array<String>] Path segments appended after the version.
77
81
  # @return [String] The full request path.
78
82
  def path_for(*segments)
79
- "/#{[version, *segments].join('/')}"
83
+ "/#{[version, *segments].map { |segment| encode_segment(segment) }.join('/')}"
84
+ end
85
+
86
+ # Redacts the api_key so it never leaks into logs or console output.
87
+ # @return [String]
88
+ def inspect
89
+ redacted_api_key = api_key.nil? ? "nil" : "[REDACTED]"
90
+ "#<#{self.class.name} host=#{host.inspect} version=#{version.inspect} " \
91
+ "api_key=#{redacted_api_key} phone_id=#{phone_id.inspect} waba_id=#{waba_id.inspect}>"
92
+ end
93
+
94
+ private
95
+
96
+ # Percent-encodes one path segment, byte-wise so multibyte input is handled correctly.
97
+ # @param segment [#to_s] The segment to encode.
98
+ # @return [String]
99
+ def encode_segment(segment)
100
+ segment.to_s.b.gsub(SEGMENT_UNRESERVED) { |byte| format("%%%02X", byte.ord) }
80
101
  end
81
102
  end
82
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whatsapp
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -9,13 +9,14 @@ module Whatsapp
9
9
  PREFIX = "sha256="
10
10
 
11
11
  class << self
12
- # @param payload [String] The raw (unparsed) request body.
12
+ # @param payload [String, nil] The raw (unparsed) request body.
13
13
  # @param header [String, nil] The `X-Hub-Signature-256` header value.
14
14
  # @param app_secret [String, nil] The secret to verify against. Defaults to the
15
15
  # globally configured secret; pass an explicit value for multi-tenant apps where
16
16
  # each account has its own Meta App (and therefore its own secret).
17
17
  # @return [Boolean] Whether the header matches the computed signature.
18
18
  def valid?(payload:, header:, app_secret: Whatsapp.configuration.app_secret)
19
+ return false if payload.nil?
19
20
  return false if header.nil? || header.empty?
20
21
  return false if app_secret.nil? || app_secret.empty?
21
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-whatsapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raniery