altcha 3.0.0 → 3.1.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: f3f8c54a53e1c95984a1f46cc9420708fce3a3564b727ac3439c12da1dc922f3
4
- data.tar.gz: f036c9affe9baebe5d23a2b9146ac967bb1482b604bc6db0d71c95b7b07b0605
3
+ metadata.gz: 849b1a649c7c8fc56f3a0c0ceedff029c6632e3f786706bc3de683f2ee1870bb
4
+ data.tar.gz: 969fb0744d694a25ebcea42a7e9ad9205d9d860c9d6c464d3158e768276e46bc
5
5
  SHA512:
6
- metadata.gz: 34e5b230a973ad0b4e90da5389b45bd1ef383f8329ad38747e961a98b49f525c4262a9d51f13be7026afc74ce6340188d47f6b2f94233bca751116cbab900ad3
7
- data.tar.gz: 25c5a676ab422049e48185cb12ada7332194bbbe13dd2688a77b54cbfbc0be65a7b0afdf258af0aa2a8e91aeec5da97b3ebfe9515a1a199a3d365ff54d1f53b5
6
+ metadata.gz: ba85431ed8e3808efe6cceba2b86cd5ecbaf4aa1f1cfeb83f53ab80e3344a8dc7c469f61a610360afd546b64e4ca4601ef6b63c20d1dc7f791a581f2917e01f0
7
+ data.tar.gz: f5123c5a9ecac589791fd8df2eb9cf347538db36051a285924235a4e4116ce2ec41d6f1e8d096f45664a9f8e55b232bcdf2c47ba8cbafc910af20fe05f3693ad
data/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project are documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
+ ## [3.1.0] - 2026-11-21
7
+
8
+ ### Security
9
+
10
+ - `Altcha::V1.verify_solution` returns `false` when `number` is not an `Integer`. Before, a String `number` could carry the tail of the signed salt across the `&` delimiter: the challenge and signature still matched, but the expiry check and `extract_params` only saw the shortened salt. This hid trailing signed params when `check_expires` was `false`, or when they came after `expires` in a custom `salt`. Together with the fix below, it would also have let an expired challenge verify. `Altcha::V1.create_challenge` raises `ArgumentError` for a `number` that is not an `Integer`.
11
+
12
+ ### Fixed
13
+
14
+ - `Altcha::V1.verify_solution` with `check_expires = true` verifies a challenge whose salt has a query but no `expires`, such as one created with `params` and without `expires`. Before, a missing `expires` was read as `0` and the challenge was rejected as expired. A present `expires` that is not a number is still rejected.
15
+
6
16
  ## [3.0.0] - 2026-10-04
7
17
 
8
18
  Brings `Altcha::V2` in line with the reference JS implementation: challenges, solutions and signatures now interoperate in both directions.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- altcha (3.0.0)
4
+ altcha (3.1.0)
5
5
  base64
6
6
 
7
7
  GEM
data/lib/altcha/v1.rb CHANGED
@@ -205,6 +205,10 @@ module Altcha
205
205
  salt += salt.end_with?('&') ? '' : '&'
206
206
 
207
207
  number = options.number || random_int(max_number)
208
+ # A non-Integer number (e.g. a String containing '&') could carry part of
209
+ # the signed salt, moving the salt/number boundary past the delimiter.
210
+ raise ArgumentError, "number must be an Integer, got #{number.class}" unless number.is_a?(Integer)
211
+
208
212
  challenge = hash_hex(algorithm, "#{salt}#{number}")
209
213
  signature = hmac_hex(algorithm, challenge, options.hmac_key)
210
214
 
@@ -237,9 +241,12 @@ module Altcha
237
241
  return false if value.nil? || value.to_s.strip.empty?
238
242
  end
239
243
 
244
+ # Reject before hashing; see create_challenge.
245
+ return false unless payload.number.is_a?(Integer)
246
+
240
247
  if check_expires && payload.salt.include?('?')
241
- expires = URI.decode_www_form(payload.salt.split('?').last).to_h['expires'].to_i
242
- return false if expires && Time.now.to_i > expires
248
+ expires = URI.decode_www_form(payload.salt.split('?').last).to_h['expires']
249
+ return false if expires && Time.now.to_i > expires.to_i
243
250
  end
244
251
 
245
252
  expected = create_challenge(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Altcha
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: altcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Regeci
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-04 00:00:00.000000000 Z
11
+ date: 2026-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64