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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8d3c11476bf4a2516d2e4284a6b65ebee79e077f6cf03a77b04af05cd1e8a62
|
|
4
|
+
data.tar.gz: 6a2ebc8fae87604a7e046419b2a29423ade4d6fcc6cfd8bf6c42eaf7f7c9f3f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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)
|
data/lib/json_api/version.rb
CHANGED