actionmailbox-resend 1.0.1 → 1.0.2

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: b42b54e45b1412b1d80d387526c1014168237d095eb4357e34e005d50ed14fc4
4
- data.tar.gz: 12b8f05d67bc727a91147a1cbca4d9b5b4b34e0ee8368eb9c054ab13f5cb223e
3
+ metadata.gz: d45c722df269ab5d5d3cc9fb7ee00910fe2d484c7c9467f5b5d09f1ead86f7da
4
+ data.tar.gz: a2b6f0e21506575a568099f6a31cf41b407d07d5457645420bbea8abc2a06bfa
5
5
  SHA512:
6
- metadata.gz: b41a106441f4bc4288b24e3857149598c827d3eca6364ff6038f0ed329f60622ebbefc3043d4e3c2039d131b9742f9e9c0e22c694e215109807f9dc5294a910b
7
- data.tar.gz: 8a63047029a116a38346604163379594cde7f9fa5e32dcf602c7db357666c3d55027fa7e4e81ce3a16a8819cfda88cc1c7be26df83c00433b5f0714a13d4f4df
6
+ metadata.gz: adbb6611b11cabfd924664c256ce84b26b26162b9c6592d3756bc53d9aa31c323e22d856cbc872b5e47237723aa33d0359002b7d1bfd1c8d43143887c16dd72a
7
+ data.tar.gz: 9f4c4a4da7dcbca4b1c07fbbfeb356e37cf1730270f96530872f594e51dd2e2122af3df088e63c889e5fbe4e339c6032e47d5b1ead9aa9dde73331d67f6299f9
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "openssl"
4
+
3
5
  # rubocop:disable Metrics/ClassLength
4
6
  module ActionMailbox
5
7
  module Resend
@@ -27,7 +29,7 @@ module ActionMailbox
27
29
 
28
30
  # Extract email_id from webhook
29
31
  email_id = payload.dig('data', 'email_id')
30
- return head(:unprocessable_entity) if email_id.blank?
32
+ return head(422) if email_id.blank?
31
33
 
32
34
  # Fetch full email from Resend API
33
35
  email_data = fetch_email_from_resend(email_id)
@@ -141,9 +143,7 @@ module ActionMailbox
141
143
  request['Authorization'] = "Bearer #{api_key}"
142
144
  request['Content-Type'] = 'application/json'
143
145
 
144
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, open_timeout: 5, read_timeout: 10) do |http|
145
- http.request(request)
146
- end
146
+ response = http_request(uri) { |http| http.request(request) }
147
147
 
148
148
  return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
149
149
 
@@ -290,9 +290,7 @@ module ActionMailbox
290
290
  metadata_request = Net::HTTP::Get.new(metadata_uri)
291
291
  metadata_request['Authorization'] = "Bearer #{api_key}"
292
292
 
293
- metadata_response = Net::HTTP.start(metadata_uri.hostname, metadata_uri.port, use_ssl: true, open_timeout: 5, read_timeout: 10) do |http|
294
- http.request(metadata_request)
295
- end
293
+ metadata_response = http_request(metadata_uri) { |http| http.request(metadata_request) }
296
294
 
297
295
  unless metadata_response.is_a?(Net::HTTPSuccess)
298
296
  Rails.logger.error("Resend API error fetching attachment metadata: #{metadata_response.code} - #{metadata_response.body}")
@@ -317,9 +315,7 @@ module ActionMailbox
317
315
  download_uri = URI(download_url)
318
316
 
319
317
  # Check attachment size before downloading
320
- head_response = Net::HTTP.start(download_uri.hostname, download_uri.port, use_ssl: true, open_timeout: 5, read_timeout: 10) do |http|
321
- http.head(download_uri.request_uri)
322
- end
318
+ head_response = http_request(download_uri) { |http| http.head(download_uri.request_uri) }
323
319
 
324
320
  if head_response['content-length'].present?
325
321
  content_length = head_response['content-length'].to_i
@@ -329,9 +325,7 @@ module ActionMailbox
329
325
  end
330
326
  end
331
327
 
332
- download_response = Net::HTTP.start(download_uri.hostname, download_uri.port, use_ssl: true, open_timeout: 5, read_timeout: 10) do |http|
333
- http.get(download_uri.request_uri)
334
- end
328
+ download_response = http_request(download_uri) { |http| http.get(download_uri.request_uri) }
335
329
 
336
330
  # Block redirects to prevent SSRF attacks
337
331
  if download_response.is_a?(Net::HTTPRedirection)
@@ -419,6 +413,30 @@ module ActionMailbox
419
413
  Rails.logger.error("Invalid URL in Resend webhook: #{url} - #{e.message}")
420
414
  false
421
415
  end
416
+
417
+ # Returns a cert store configured for broad compatibility.
418
+ # OpenSSL 3.x enables CRL checking by default, which fails for many CDNs
419
+ # (including Cloudflare, which fronts Resend's API). This disables CRL
420
+ # checking while maintaining certificate verification.
421
+ def default_cert_store
422
+ store = OpenSSL::X509::Store.new
423
+ store.set_default_paths
424
+ store.flags = 0 # Disable CRL checking for OpenSSL 3.x compatibility
425
+ store
426
+ end
427
+
428
+ def http_request(uri, open_timeout: 5, read_timeout: 10)
429
+ Net::HTTP.start(
430
+ uri.hostname,
431
+ uri.port,
432
+ use_ssl: true,
433
+ cert_store: default_cert_store,
434
+ open_timeout: open_timeout,
435
+ read_timeout: read_timeout
436
+ ) do |http|
437
+ yield http
438
+ end
439
+ end
422
440
  end
423
441
  end
424
442
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActionMailbox
4
4
  module Resend
5
- VERSION = "1.0.1"
5
+ VERSION = "1.0.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailbox-resend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - rcoenen
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.7.2
106
+ rubygems_version: 3.6.9
107
107
  specification_version: 4
108
108
  summary: Resend email ingress for ActionMailbox
109
109
  test_files: []