remotion_lambda 4.0.537 → 4.0.538

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: 6b36ee099eb8262e376138e3e4a495fac351e7ea349fa7b3f32c4b31afd4063e
4
- data.tar.gz: 14313742f7e352704e9bfa99c85ea5ea6c089c09f8ee85f70e6eaa3def4ac50b
3
+ metadata.gz: 45759df0fd53af971ef1e706655f36975e8ca436d281dfee927901a65c8c8df7
4
+ data.tar.gz: ceef2060641769982f71e75b4b440b26bc70160c560fd79cc7c68d56baf1316c
5
5
  SHA512:
6
- metadata.gz: 638fb0c155eef435cc3c20d6a7a6f7a6bfe5cad7d9b1737555000b1f20ec55e300740f4a9795f9ebb04047773ecf1f109a96ee1a0b64a798ded9f78bd6365711
7
- data.tar.gz: ff7b770403134c6372ab99cad0aacd1d7a8989eb84a1070fbb2ac417f937fa35cb99b56ba113041d26f0d5e2ed2a067455611e2ecc0d0ce38f0409f8d0a7331c
6
+ metadata.gz: c650d48456a61d127bd534b8097f53d11e43e24a9dd03216bdfccd8f0021caef5a4ad466412e032b3b3a650f386f4f12da8e4cb78b1e40d9c5b1e23337c76830
7
+ data.tar.gz: 980729ecb7eccdcf9f71ec4f2fe3b864cfafb4e59f90e14020e50fa6abd15268f52144bab86289dc93d40289247a0ba115e9e6401decd42bd894ad3181a468e4
@@ -1 +1 @@
1
- VERSION = "4.0.537"
1
+ VERSION = "4.0.538"
@@ -0,0 +1,50 @@
1
+ require 'openssl'
2
+
3
+ module RemotionLambda
4
+ # Validates that an incoming webhook request was sent by Remotion and that its
5
+ # body was not modified in transit.
6
+ #
7
+ # Pass the webhook secret that was configured when the render was started, the
8
+ # raw request body exactly as it was received, and the value of the
9
+ # X-Remotion-Signature header. Raises if the request cannot be verified and
10
+ # returns nil if it is authentic.
11
+ #
12
+ # The signature covers the raw JSON bytes, so pass the body as it arrived
13
+ # (request.body.read in Sinatra, request.raw_post in Rails) and parse it only
14
+ # after this method returns. Parsing and regenerating the JSON first can change
15
+ # whitespace and how numbers are formatted, which would break the comparison
16
+ # even for a genuine request.
17
+ #
18
+ # This mirrors validateWebhookSignature() from @remotion/lambda/client and uses
19
+ # the same scheme: "sha512=" followed by the hex digest of an HMAC-SHA512 over
20
+ # the request body, keyed with the webhook secret.
21
+ def self.validate_webhook_signature(secret, body, signature_header)
22
+ if secret.nil? || secret.empty?
23
+ raise ArgumentError, "No 'secret' was provided to validate_webhook_signature()."
24
+ end
25
+
26
+ if body.nil? || body.empty?
27
+ raise ArgumentError, "No 'body' was provided to validate_webhook_signature()."
28
+ end
29
+
30
+ if signature_header.nil? || signature_header.empty? ||
31
+ signature_header == 'NO_SECRET_PROVIDED'
32
+ raise 'No webhook signature was provided'
33
+ end
34
+
35
+ expected = "sha512=#{OpenSSL::HMAC.hexdigest('SHA512', secret, body)}"
36
+
37
+ # The header is attacker-controlled, so force both sides to binary before
38
+ # comparing: fixed_length_secure_compare() compares bytes and must fail the
39
+ # check instead of raising when the header has an unexpected encoding.
40
+ signature = signature_header.b
41
+
42
+ matches =
43
+ expected.bytesize == signature.bytesize &&
44
+ OpenSSL.fixed_length_secure_compare(expected.b, signature)
45
+
46
+ raise 'Signatures do not match' unless matches
47
+
48
+ nil
49
+ end
50
+ end
@@ -7,6 +7,7 @@ require_relative 'remotion_lambda/render_frames_on_lambda_payload'
7
7
  require_relative 'remotion_lambda/render_progress_payload'
8
8
  require_relative 'remotion_lambda/render_still_on_lambda_payload'
9
9
  require_relative 'remotion_lambda/s3_output_provider'
10
+ require_relative 'remotion_lambda/webhook'
10
11
  require_relative 'remotion_lambda/sdk'
11
12
 
12
13
  module RemotionLambda
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotion_lambda
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.537
4
+ version: 4.0.538
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonny Burger
@@ -98,6 +98,7 @@ files:
98
98
  - lib/remotion_lambda/s3_output_provider.rb
99
99
  - lib/remotion_lambda/sdk.rb
100
100
  - lib/remotion_lambda/version.rb
101
+ - lib/remotion_lambda/webhook.rb
101
102
  - lib/render_media_on_lambda_payload.rb
102
103
  - lib/render_media_on_lambda_payload_spec.rb
103
104
  - lib/render_progress_payload.rb