Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
An unmatched trailing backslash can alter merged scope values, allowing chained or _has searches to match related resources excluded by both granted scopes.
1 open issue
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
What changed in this PR
This PR extends SMART v2 scope filtering to chained and _has searches, aligning related-resource searches with direct search and include behavior.
Changes:
- Applies scope filters inside chains, merges compatible alternatives, and rejects combinations that cannot be enforced.
- Updates SQL chain rewriting to evaluate resource-level predicates on the chain target.
- Adds unit and integration coverage plus a localized authorization error message.
| File | Description |
|---|---|
test/Microsoft.Health.Fhir.Shared.Tests.Integration/Features/Smart/SmartSearchTests.cs |
Tests filtered forward chains, _id chains, and _has. |
src/Microsoft.Health.Fhir.SqlServer/Features/Search/Expressions/Visitors/ChainFlatteningRewriter.cs |
Places resource-level predicates on the chain target. |
src/Microsoft.Health.Fhir.SqlServer.UnitTests/Features/Search/Expressions/ChainFlatteningRewriterTests.cs |
Tests combined resource and search-parameter predicates. |
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/SearchOptionsFactory.cs |
Enforces scope filters and validates supported chain combinations. |
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchOptionsFactorySmartScopeTests.cs |
Covers filter application, merging, rejection, and unchanged behavior. |
src/Microsoft.Health.Fhir.Core/Resources.resx |
Adds the unenforceable-chain authorization message. |
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs |
Exposes the new localized message. |
Review effort: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
A critical SQL binding defect applies the chain target’s scope filter to the primary resource when both resource types have filtered scopes, dropping valid search matches.
1 open issue
1 resolved since last review
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6089 +/- ##
==========================================
+ Coverage 81.51% 82.18% +0.66%
==========================================
Files 1036 1037 +1
Lines 40497 40672 +175
Branches 6611 6668 +57
==========================================
+ Hits 33013 33427 +414
+ Misses 5916 5666 -250
- Partials 1568 1579 +11 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
f56fb0a to
8d1dffa
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Authorization-sensitive changes span SQL and Cosmos, but provider-backed results are unavailable and new tests cover only R4/R4B, requiring maintainer validation of enforcement and compatibility.
No open issues 🎉
1 resolved since last review
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
Mikael Weaver (mikaelweave)
left a comment
There was a problem hiding this comment.
Inline findings from my review of 8d1dffa6, grouped by priority. The two must-fix items are based on static traces; I did not run them against a database.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Two critical issues remain: decoded scope-key collisions can silently drop grants and make results scope-order dependent, while nested-chain predecessor handling can exclude matching range-only records.
2 open issues
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Ambiguous wildcard authorization semantics and missing storage-backed validation for security-sensitive chained-search and CTE-binding changes require maintainer clarification and runtime verification.
No open issues 🎉
2 resolved since last review
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
…ope logic Wildcard SMART scope filters are now always applied to chain and _has targets, even when an unfiltered typed scope also grants the type. Move chain scope helpers into SearchOptionsFactory.SmartChainScopes.cs.
…move duplicate tests
There was a problem hiding this comment.
🟡 Changes recommended
A critical chain-query bug after a SMART union can skip the preceding _id restriction and return unrelated patients, requiring corrected CTE selection and a SQL-backed regression test.
1 open issue
2 resolved since last review
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Authorization-boundary and SQL CTE binding changes need maintainer confirmation of storage-backed SQL/Cosmos CI results, since nested split-predicate tests assert SQL text without verifying execution behavior.
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because inconsistent wildcard scope handling between direct and chained searches may allow matches through resources that the same token excludes from direct searches.
No open issues 🎉
1 resolved since last review
1 file not reviewed
src/Microsoft.Health.Fhir.Core/Resources.Designer.cs: Generated file
Review effort: Balanced

Description
Makes SMART v2 scope search-parameter filters (e.g.
Condition.rs?category=problem-list-item) apply consistently to chained and_hassearches, aligning them with direct search and_include/_revinclude.Changes in
SearchOptionsFactory:_hasportion of the query (the chain target for forward chains, the referencing type for_has). When multiple filtered scopes cover that type and each filters on the same single parameter, their values are combined as one comma-separated (OR) value, e.g.category=a,b. Identical duplicate scopes are treated as one.*.rs?...) scope always refuses the request. Unusable cases: multiple filtered scopes that cannot be combined (different or multiple parameters, or comparator values such asge2020), modified or chained scope parameters (e.g.:not), chains resolving to multiple target types, a nested chain under a filtered link, unsupported scope parameters, and_id/_lastUpdated/_typeor vector filters.*.rs?...) is always applied in the chained /_hasportion, even when a resource-specific scope also grants that type (ADR 2609). Resource-specific scopes are used only when no wildcard scope applies.Supporting SQL changes:
ChainFlatteningRewriter: predicates on a chain link that have no search-parameter table (e.g._id) are now evaluated on the target resource, so a user's_idpredicate can be combined with an appended scope filter.SqlExpressionRewriter/SqlQueryGenerator: chain-link predicates keep their chain level. After a union, chain predicates and nested chain links join to the preceding CTE on the chain target. The second half of a split (concatenated) predicate reuses the first half's input.Applies to SQL and Cosmos, all FHIR versions. No schema changes.
Related issues
Addresses AB#214773.
Testing
SearchOptionsFactorySmartScopeTestscover filter application in chains and_has, same-parameter scope merging, wildcard filters combined with resource-specific scopes, the refused (403) cases above, and unchanged behavior for unfiltered scopes.ChainFlatteningRewriterTestscovers a chain link combining_idwith a search-parameter predicate.SqlQueryGeneratorTestscover chain predicates and nested chains following a SMART union, including split predicates.dotnet test --project <R4 Core / SqlServer unit test project> --filter-class ...).SmartSearchTestscover filtered scopes applied to forward chains (by name and by_id) and_hasagainst SQL and Cosmos; these run in CI.FHIR Team Checklist
Semver Change (docs)
Patch