line-bot-api 2.2.0 → 2.3.0

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: 44ce823e0e9998cc204a39d55321ec85e6b7903adcf7ed1630b222c69116566a
4
- data.tar.gz: 9a8119c82379fe431bc8ccaa4526e4647256f41179d3edd4022643712911ddc8
3
+ metadata.gz: 32bc05debf174d2fd40d7fe9b39eca826829773b732cd622b75025c8119806ef
4
+ data.tar.gz: 2755c22b1b43d31e3747f0523996b6ce2591e731b0b87e2b0a493c5697eec8a4
5
5
  SHA512:
6
- metadata.gz: 6999af99e5f87523518756b29690f4036762924037cf38cc1c11c614c8d2721a125b8c4b8046c9095f2efd38db5d6ceb2430f6e91de775f3e9f7d66c5a2a33c7
7
- data.tar.gz: a3dd071068394ed5dfd5f565f8dd1bdf1a306b8be83c99d10c503d704b9839b3df168b77a2ef0b5bb9fa14b1cdc5c6dfd92833663dbc6e227e4e0e91a5d94f27
6
+ metadata.gz: '06943b31d09d0a9833316c30b35711a66be1446c529a254b2a230ca05758b2e1402fd79986a6c1d3226adb9f58d6ebccb6c68953ff41f765529edfcd2c0e871d'
7
+ data.tar.gz: 50faa1171d680adabd94ffa8d610d05105082ee8d866fe63da04ecd1100131b3d0d95d6a2b603d505ba69eeefa0994d4c39fbbbe9d460520851aaa9f09113239
@@ -11,8 +11,20 @@ module Line
11
11
  class WebhookParser
12
12
  class InvalidSignatureError < StandardError; end
13
13
 
14
- def initialize(channel_secret:)
14
+ # Initialize webhook parser
15
+ #
16
+ # @param channel_secret [String]
17
+ # The channel secret used for signature verification.
18
+ # @param skip_signature_verification [() -> bool, nil]
19
+ # A callable object with type `() -> bool` that determines whether to skip
20
+ # webhook signature verification. Signature verification is skipped if and
21
+ # only if this callable is provided and returns `true`.
22
+ # This can be useful in scenarios such as when you're in the process of
23
+ # updating the channel secret and need to temporarily bypass verification
24
+ # to avoid disruptions.
25
+ def initialize(channel_secret:, skip_signature_verification: nil)
15
26
  @channel_secret = channel_secret
27
+ @skip_signature_verification = skip_signature_verification
16
28
  end
17
29
 
18
30
  # Parse events from the raw request body and validate the signature.
@@ -31,7 +43,10 @@ module Line
31
43
  #
32
44
  # @example Sinatra usage
33
45
  # def parser
34
- # @parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
46
+ # @parser ||= Line::Bot::V2::WebhookParser.new(
47
+ # channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"),
48
+ # skip_signature_verification: -> { ENV['SKIP_SIGNATURE_VERIFICATION'] == 'true' }
49
+ # )
35
50
  # end
36
51
  #
37
52
  # post '/callback' do
@@ -54,7 +69,11 @@ module Line
54
69
  # "OK"
55
70
  # end
56
71
  def parse(body:, signature:)
57
- raise InvalidSignatureError.new("Invalid signature: #{signature}") unless verify_signature(body: body, signature: signature)
72
+ should_skip = @skip_signature_verification&.call || false
73
+
74
+ unless should_skip == true || verify_signature(body: body, signature: signature)
75
+ raise InvalidSignatureError.new("Invalid signature: #{signature}")
76
+ end
58
77
 
59
78
  data = JSON.parse(body.chomp, symbolize_names: true)
60
79
  data = Line::Bot::V2::Utils.deep_underscore(data)
@@ -66,14 +85,14 @@ module Line
66
85
  end
67
86
  end
68
87
 
69
- private
70
-
71
88
  def verify_signature(body:, signature:)
72
89
  hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), @channel_secret, body)
73
90
  expected = Base64.strict_encode64(hash)
74
91
  variable_secure_compare(signature, expected)
75
92
  end
76
93
 
94
+ private
95
+
77
96
  # To avoid timing attacks
78
97
  def variable_secure_compare(a, b)
79
98
  secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))
@@ -2,6 +2,6 @@ module Line
2
2
  module Bot
3
3
  # This version is updated before releasing a new version in the release process.
4
4
  # You don't have to update this version manually.
5
- VERSION = "2.2.0"
5
+ VERSION = "2.3.0"
6
6
  end
7
7
  end
@@ -5,18 +5,19 @@ module Line
5
5
  class InvalidSignatureError < ::StandardError
6
6
  end
7
7
  @channel_secret: String
8
+ @skip_signature_verification: (^() -> bool) | nil
8
9
 
9
- def initialize: (channel_secret: String) -> void
10
+ def initialize: (channel_secret: String, ?skip_signature_verification: (^() -> bool) | nil) -> void
10
11
 
11
12
  def parse: (
12
13
  body: String,
13
14
  signature: String
14
15
  ) -> Array[Webhook::Event]
16
+
17
+ def verify_signature: (body: String, signature: String) -> bool
15
18
 
16
19
  private
17
20
 
18
- def verify_signature: (body: String, signature: String) -> bool
19
-
20
21
  def variable_secure_compare: (String, String) -> bool
21
22
 
22
23
  def secure_compare: (String, String) -> bool
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-bot-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LINE Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-26 00:00:00.000000000 Z
11
+ date: 2025-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post