hanami-action 3.0.2 → 3.0.3

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: ead66d07305c1ab423774ef35b1aba0d6f280aa0d0921299f8daca4e4130e09e
4
- data.tar.gz: 0ce91d088d253b5daa993c768ecb633bf128e411fb0257b2594dd8cefdd80b23
3
+ metadata.gz: 50013e29010b3035dd73368ab42ca9e1348478cb876200dd7379ecca324041f2
4
+ data.tar.gz: 34f4e51c7349d35d3c5888766f14e1ebb09ac48091c34803b47aac7be22aac08
5
5
  SHA512:
6
- metadata.gz: a48f8dac73391046b11a1236b98020c555f49d73251af2bb34a84198709e8e9365d80f1044a2f5089d9ba7656d479627a187fabaf094c045bb4325cad5d9e09a
7
- data.tar.gz: a09c190e05396f4cf7ca9747109f961714ca164ff1cb7594319ff28b014278152ae0ac1ae319ca26e1726a7fb1abcaa8bbf355df24afc9eada5b453bb96a62a6
6
+ metadata.gz: 78cd680b7f07b09cb4b2bc350202c2335e53402c5b6dd48bac04c6e80c220ced8a8f7d6e5d605029d72d4cd5e0383a39d4a0850c97eb80b949dd70ecf3804750
7
+ data.tar.gz: eedf3f7cbab7b5be7b11d52f602b383197de698f9396220c85093305e03869e0dee007f6e1089fd8255372b3aceb7a5cdb648b8eb94d8eb7a20d829b09bff134
data/CHANGELOG.md CHANGED
@@ -19,7 +19,19 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
19
19
 
20
20
  ### Security
21
21
 
22
- [Unreleased]: https://github.com/hanami/hanami-action/compare/v3.0.2...HEAD
22
+ [Unreleased]: https://github.com/hanami/hanami-action/compare/v3.0.3...HEAD
23
+
24
+ ## [3.0.3] - 2026-11-25
25
+
26
+ ### Fixed
27
+
28
+ - Accept the CSRF token from a form body in routed requests again. Since 3.0.2, the String keys of query string and form body params were dropped from `params.raw` when Hanami Router also gave them as route params, so CSRF protection could not find `_csrf_token` and rejected every form submission. Both keys are now kept, with the same value. (@parndt in #537)
29
+
30
+ ### Security
31
+
32
+ - Give route params precedence over request body params with the same name, such as a JSON or multipart body sending `id=2` to `/users/1`. This completes the fix for GHSA-55j2-5pph-56mv, which covered only the query string and form body. As a result, when the same flat param is in both the query string and the body, the query string value is now used; previously the body value was. Nested params in the body still take precedence over the query string. (@parndt in GHSA-55j2-5pph-56mv)
33
+
34
+ [3.0.2]: https://github.com/hanami/hanami-action/compare/v3.0.2...v3.0.3
23
35
 
24
36
  ## [3.0.2] - 2026-11-24
25
37
 
@@ -324,29 +324,47 @@ module Hanami
324
324
  result = {}
325
325
  rack_request = ::Rack::Request.new(env) if has_query || has_form_body
326
326
 
327
- _merge_params(result, rack_request.GET) if has_query
328
- _merge_params(result, rack_request.POST) if has_form_body
327
+ result.merge!(rack_request.GET) if has_query
328
+ result.merge!(rack_request.POST) if has_form_body
329
329
  _merge_params(result, env[ROUTER_PARAMS]) if has_router_params
330
- _merge_params(result, env[ACTION_BODY_PARAMS]) if has_body_params
330
+
331
+ if has_body_params
332
+ _merge_params(result, env[ACTION_BODY_PARAMS])
333
+ _merge_router_string_params(result, env[ROUTER_PARAMS]) if has_router_params
334
+ end
331
335
 
332
336
  result
333
337
  end
334
338
 
335
- # Merges params, replacing any existing value for the same key, whether it was stored with
336
- # a String or a Symbol key. Route params have Symbol keys while the others have String keys,
337
- # so without this a query or form param could sit alongside the route param it was meant to
338
- # be overridden by, and a contract would read the query or form value instead.
339
+ # Query string, form body, and body params have String keys, while route params have Symbol
340
+ # keys. Hanami Router also copies query and form params into the route params, so the same
341
+ # param is often present under both keys. Both must hold the value merged last, or a route
342
+ # param would not override a query or form param of the same name wherever it is read.
339
343
  def _merge_params(result, params)
340
- params.each do |key, value|
341
- if key.is_a?(Symbol)
342
- result.delete(key.name)
343
- elsif key.valid_encoding?
344
- result.delete(key.to_sym)
345
- end
346
- result[key] = value
344
+ params.each { |key, value| _merge_param(result, key, value) }
345
+ end
346
+
347
+ # Hanami Router gives no way to tell path params apart from the query and form params it
348
+ # copies alongside them, so a body merged after the route params could override a path param.
349
+ # Path params are always Strings (or nil for an optional segment that did not match, which
350
+ # leaves no value to protect), so merging the String values again puts them back on top.
351
+ def _merge_router_string_params(result, router_params)
352
+ router_params.each do |key, value|
353
+ _merge_param(result, key, value) if value.is_a?(String)
347
354
  end
348
355
  end
349
356
 
357
+ def _merge_param(result, key, value)
358
+ case key
359
+ when Symbol
360
+ result[key.name] = value if result.key?(key.name)
361
+ when String
362
+ result[key.to_sym] = value if key.valid_encoding? && result.key?(key.to_sym)
363
+ end
364
+
365
+ result[key] = value
366
+ end
367
+
350
368
  def _form_content_type?(content_type)
351
369
  return false unless content_type
352
370
 
@@ -8,6 +8,6 @@ module Hanami
8
8
  #
9
9
  # @since 3.0.0
10
10
  # @api public
11
- VERSION = "3.0.2"
11
+ VERSION = "3.0.3"
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-action
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hanakai team