jpie 4.1.9 → 4.1.10

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: 315aaaaed71bdf4807a63a407205327316ad7739e269c1179a27e0d801b51483
4
- data.tar.gz: 829e98cab64b8b6794a3fa389f62d1a179746685f2af3803efd40e215e15024e
3
+ metadata.gz: d8d3c11476bf4a2516d2e4284a6b65ebee79e077f6cf03a77b04af05cd1e8a62
4
+ data.tar.gz: 6a2ebc8fae87604a7e046419b2a29423ade4d6fcc6cfd8bf6c42eaf7f7c9f3f0
5
5
  SHA512:
6
- metadata.gz: aa206b22a633084e2b8585bcc1f7154e6753bb9f46cd2439b703df8451eb51e2de7db1fc70120fa65f1c7293054d751f6ea5694f7e247ded43f1b6cc33250629
7
- data.tar.gz: 025d1cef8a720347a0f453f5ec2c73c785c276996b92574f1785bed0316b22d77c9077b5aaa24dad78ceb08b0bdda4465ffb242eb9f0c99e6cb5053e62863e8b
6
+ metadata.gz: 9c67a26c087d7e291a2880b0a60b922274e4403fa95f20b4d6b4611597500c43ce2c186ffd8476925d2e9572c6db4c6e667b268fb0cb88d48707ba9838989c1d
7
+ data.tar.gz: 1cc10806f7c34d36dc64124c90ebe821f7ae50b031b293b1eede2e6162cdf274fc3b5b889ffece5cee3a6d1b9656b99cad6088b74c1b22067ef1e9b11c03c6da
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ at release time.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.1.10] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - **Check only the targets a write body names as relationships.** 4.1.9 also
15
+ checked a foreign key that a body sent as an attribute. A resource can expose a
16
+ foreign key as a creatable attribute on purpose, and its policy then decides who
17
+ may name the target. The check now covers only a target named under
18
+ `relationships`. Regression spec: `authorization_scope_body_write_target_spec.rb`.
19
+
10
20
  ## [4.1.9] - 2026-11-20
11
21
 
12
22
  ### Fixed
@@ -64,7 +64,8 @@ module JSONAPI
64
64
  target = model_class || self.model_class
65
65
  payload = data.nil? ? raw_jsonapi_data : symbolize_data(data)
66
66
  attrs = JSONAPI::Deserializer.new(payload, model_class: target, action:, definition:).to_model_attributes
67
- JSONAPI::ResourceIdentifier.reject_hidden_targets(attrs, target, self)
67
+ named = (payload[:relationships] || {}).keys.map { it.to_s.underscore }
68
+ JSONAPI::ResourceIdentifier.reject_hidden_targets(attrs, target, self, named:)
68
69
  end
69
70
 
70
71
  def resource_url(resource)
@@ -37,12 +37,12 @@ module JSONAPI
37
37
  # A write body assigns the raw foreign key and leaves the lookup to the model. A target the
38
38
  # caller's scope hides must fail like a target that does not exist, as it does on a
39
39
  # relationship route. The write stops, so it never clears the stored relationship.
40
- def reject_hidden_targets(attrs, model_class, controller)
40
+ # `named` lists the relationships the body names. A resource can expose a foreign key as a
41
+ # creatable attribute on purpose, and its policy then decides who may name the target.
42
+ def reject_hidden_targets(attrs, model_class, controller, named:)
41
43
  return attrs unless controller && JSONAPI.configuration.authorization_scope
42
44
 
43
- model_class.reflect_on_all_associations(:belongs_to).each do |association|
44
- next if association.polymorphic?
45
-
45
+ named_associations(model_class, named).each do |association|
46
46
  id = attrs[association.foreign_key.to_s]
47
47
  next if id.nil? || visible_target?(association, id, controller)
48
48
 
@@ -51,6 +51,11 @@ module JSONAPI
51
51
  attrs
52
52
  end
53
53
 
54
+ def named_associations(model_class, named)
55
+ associations = model_class.reflect_on_all_associations(:belongs_to)
56
+ associations.select { named.include?(it.name.to_s) && !it.polymorphic? }
57
+ end
58
+
54
59
  def visible_target?(association, id, controller)
55
60
  related_class = association.klass
56
61
  scope = authorized_related_scope(target_records(related_class), related_class, controller)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "4.1.9"
4
+ VERSION = "4.1.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpie
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.9
4
+ version: 4.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp