You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apply SMART v2 scope filters to chained and _has searches - #6087
Makes SMART v2 scope search-parameter filters (e.g. Condition.rs?category=problem-list-item) apply consistently to chained and _has searches, aligning them with direct search and _include/_revinclude.
Changes in SearchOptionsFactory:
Permitted: the scope's filters are applied within the chained / _has portion of the query. When multiple filtered scopes cover the target type and each filters on the same single parameter, their values are combined as one comma-separated (OR) value, e.g. category=a,b.
Refused (403): multiple filtered scopes that cannot be combined (different or multiple parameters, or comparator values such as ge2020), modified or chained scope parameters (e.g. :not), chains resolving to multiple target types, nested chains, unsupported scope parameters, and _id/_lastUpdated/_type or vector filters.
Unchanged: requests where no filtered scopes apply.
Supporting change in the SQL 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 _id predicate can be combined with an appended scope filter.
Applies to SQL and Cosmos, all FHIR versions. No schema changes.
Unit tests in SearchOptionsFactorySmartScopeTests cover filter application in chains and _has, same-parameter scope merging, the refused (403) cases above, and unchanged behavior for unfiltered scopes.
A unit test in ChainFlatteningRewriterTests covers a chain link combining _id with a search-parameter predicate.
Both pass locally (dotnet test --project <R4 Core / SqlServer unit test project> --filter-class ...).
Integration tests in SmartSearchTests cover filtered scopes applied to forward chains (by name and by _id) and _has against SQL and Cosmos; these run in CI.
FHIR Team Checklist
Update the title of the PR to be succinct and less than 65 characters
Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical scope-validation bypass can disclose Condition matches excluded by the scope, while predicate composition also causes SQL and comparator-parsing failures.
This PR extends SMART v2 scope filtering to chained and _has searches in the shared Core layer, aiming to align authorization with direct and include searches without schema changes.
Changes:
Injects scope filters into chain predicates and merges compatible same-parameter scopes.
Rejects filter combinations that cannot be enforced, with a new localized error message.
Adds unit tests for filter application, scope merging, rejection cases, and unchanged behavior.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Mocked-parser tests with invalid R4 chains leave SQL/Cosmos scope enforcement unverified, while single scopes with multiple filters bypass the documented restriction and new refusals return HTTP 403 instead of the documented 400.
A single scope containing multiple filters bypasses the single-parameter restriction here. For example, Condition.rs?category=problem-list-item&code=x is returned unchanged and both predicates are injected into _has, although the PR explicitly lists multiple filters within one scope as refused. Check each scope's parameter count before this early return so the documented restriction also applies when there is only one applicable scope.
With a Patient.rs?name=<257-character value> scope, the injected filter causes SQL searches such as Observation?subject:Patient._id=p1 to lose valid authorized matches. StringOverflowRewriter changes the name predicate, and the inherited SqlExpressionRewriter.VisitTable resets its ChainLevel from 1 to 0, so SQL intersects Patient name rows with the root Observation keys rather than the Patient target. Preserve the existing chain level when rewriting table predicates and add a SQL pipeline regression test for this case.
Reject multiple parameters before the single-scope shortcut
The single-scope branch below returns every parameter without checking their count. Consequently, a scope such as Condition.rs?category=problem-list-item&code=x is injected into _has rather than rejected, contradicting the PR's explicit 400 contract for multiple filters within one scope. Check that each applicable scope contains exactly one parameter before taking the single-scope shortcut, and cover this refusal case.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Authorization-sensitive changes span SQL and Cosmos, but runtime provider validation was unavailable and added tests cover only R4/R4B, requiring maintainer review of broader provider and cross-version CI evidence.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. When multiple filtered scopes cover the target type and each filters on the same single parameter, their values are combined as one comma-separated (OR) value, e.g.category=a,b.ge2020), modified or chained scope parameters (e.g.:not), chains resolving to multiple target types, nested chains, unsupported scope parameters, and_id/_lastUpdated/_typeor vector filters.Supporting change in the SQL
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.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, the refused (403) cases above, and unchanged behavior for unfiltered scopes.ChainFlatteningRewriterTestscovers a chain link combining_idwith a search-parameter predicate.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