Repository navigation
fix(agent): apply the scope of collections reached through a relation - #421
ShohanRahman wants to merge 1 commit into
Conversation
Read routes only fetched the scope of the collection they serve, so the columns a projection pulls from to-one relations ignored the scope set on those related collections, and a leaderboard aggregated its related collection under the root scope only. show, list, csv, list_related and csv_related now fetch the scope of every collection the projection reaches, and empty a related record that falls outside it, keeping the root row. The leaderboard intersects the aggregated collection's scope (and, for a many-to-many, the foreign collection's through the target relation) into its filter. Refs: PRD-907 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 new issue
|
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (8) 🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
| @scopes.filter_map do |relation_scope| | ||
| related = ForestAdminDatasourceToolkit::Utils::Record.field_value(stringified, relation_scope.path) | ||
|
|
||
| relation_scope.path if related && !relation_scope.scope.match(related, relation_scope.collection, timezone) |
There was a problem hiding this comment.
🟠 High utils/relation_scopes.rb:47
A related record with a NULL value for a scoped comparison field crashes the read or export request instead of being redacted; for example, balance > 0 reaches nil > 0 in scope.match. The related check only excludes an absent relation, so handle null comparison operands before invoking the matcher.
Also found in 1 other location(s)
packages/forest_admin_agent/lib/forest_admin_agent/services/permissions.rb:299
The scopes collected here expose a crash in the unchanged toolkit matcher (
components/query/condition_tree/nodes/condition_tree_leaf.rb,match): itsless_than/greater_thanbranches comparefield_valuedirectly, without handling nulls. For example, a related account scoped bybalance > 0with a null balance now reachesnil > 0viaRelationScopes#redact. The latter only guards against the entire related record being absent, so one such account crashes the whole list/show request or aborts the CSV export rather than redacting the account. Handle nullable comparison operands before using this matcher for related scopes.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/forest_admin_agent/lib/forest_admin_agent/utils/relation_scopes.rb around line 47:
A related record with a `NULL` value for a scoped comparison field crashes the read or export request instead of being redacted; for example, `balance > 0` reaches `nil > 0` in `scope.match`. The `related` check only excludes an absent relation, so handle null comparison operands before invoking the matcher.
Also found in 1 other location(s):
- packages/forest_admin_agent/lib/forest_admin_agent/services/permissions.rb:299 -- The scopes collected here expose a crash in the unchanged toolkit matcher (`components/query/condition_tree/nodes/condition_tree_leaf.rb`, `match`): its `less_than`/`greater_than` branches compare `field_value` directly, without handling nulls. For example, a related account scoped by `balance > 0` with a null balance now reaches `nil > 0` via `RelationScopes#redact`. The latter only guards against the entire related record being absent, so one such account crashes the whole list/show request or aborts the CSV export rather than redacting the account. Handle nullable comparison operands before using this matcher for related scopes.

fixes PRD-907
This is the agent-ruby counterpart of ForestAdmin/agent-nodejs#2051. Read routes apply the scope of every collection they reach through a to-one relation, as well as the scope of the collection they serve. A related record outside its collection's scope is served empty, and the record it hangs off stays in the response.
What changes
Permissions#relation_scopesfetches the scope of each collection the projection reaches through a to-one relation. The columns it reads are added to the query, each related record is checked withConditionTree#match, and a record outside its scope is served asnil. The added columns are stripped before serialization.showstatus are the same as before. An out-of-scope related record looks the same as an unassigned relation.Notes for review
relation_scopesskips them.spec_helper's shared contextwith readable related collectionsstubsrelation_scopeswith an emptyRelationScopes, so the route specs keep their permission doubles.spec/lib/forest_admin_agent/security/related_collection_scopes_spec.rbruns the real path.Tests
forest_admin_agentsuite passes: 1,435 examples. Rubocop is clean.Squash message
Definition of Done
General
Security
🤖 Generated with Claude Code