Skip to content

Apply the existing feature filter so EnableAadSmartOnFhirProxy - #5865

Merged
Richa Bansal (rbans96) merged 6 commits into
mainfrom
fix/gate-smart-proxy-endpoints-on-feature-flag
Sep 22, 2026
Merged

Richa Bansal (rbans96) merged 6 commits into
mainfrom
fix/gate-smart-proxy-endpoints-on-feature-flag

Conversation

@rbans96

Copy link
Copy Markdown
Contributor

Description

AadSmartOnFhirProxyFeatureFilterAttribute already exists and does the right thing — it returns 401 when Security:EnableAadSmartOnFhirProxy is false. However, it is never applied to any controller, so it has no effect today.

The consequence is that EnableAadSmartOnFhirProxy does not actually control the feature. It only changes what the discovery documents advertise:

Related issues

Address https://microsofthealth.visualstudio.com/Health/_workitems/edit/197109

Testing

Unit tests are added

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.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

…proxy controller

AadSmartOnFhirProxyFeatureFilterAttribute already exists and correctly
returns 401 when Security:EnableAadSmartOnFhirProxy is false, but it was
never applied to any controller, so it has no effect.

As a result the /AadSmartOnFhirProxy endpoints (authorize, callback,
token) stay fully functional even when the feature is turned off. The
flag currently only changes what /metadata and
/.well-known/smart-configuration advertise; it does not disable the
feature itself.

This applies the existing filter to AadSmartOnFhirProxyController so the
configuration setting actually controls the endpoints. The filter is
ordered after the audit logging filter so that calls made while the
feature is disabled are still audited before being rejected.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The filter had no test coverage. These cover both its behaviour and,
importantly, the fact that it is actually applied to the controller --
the latter being what was missing and what allowed the setting to be
silently ignored.

- Disabled feature returns UnauthorizedResult.
- Enabled feature does not short-circuit the request.
- The filter is present in AadSmartOnFhirProxyController's attributes.
- Audit logging is ordered ahead of it, so calls made while the feature
  is disabled are still recorded before being rejected.

Verified that the two wiring tests fail when the attribute is removed
from the controller, while the two behaviour tests continue to pass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@rbans96
Richa Bansal (rbans96) requested a review from a team as a code owner September 21, 2026 20:58
@rbans96 Richa Bansal (rbans96) changed the title Apply the existing feature filter so EnableAadSmartOnFhirProxy actually disables the SMART proxy endpoints Apply the existing feature filter so EnableAadSmartOnFhirProxy Sep 21, 2026
@rbans96 Richa Bansal (rbans96) added Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug-Security Security related bugs. No-PaaS-breaking-change No-ADR ADR not needed labels Sep 21, 2026
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.83%. Comparing base (038ce87) to head (2abf1be).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5865      +/-   ##
==========================================
+ Coverage   78.71%   78.83%   +0.12%     
==========================================
  Files        1018     1018              
  Lines       37126    37127       +1     
  Branches     5680     5679       -1     
==========================================
+ Hits        29222    29268      +46     
+ Misses       6498     6459      -39     
+ Partials     1406     1400       -6     

see 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The controller performs OpenID discovery before action filters execute, so disabled requests may fail with a 5xx instead of returning 401.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Applies the existing SMART-on-FHIR proxy feature filter to the proxy controller and adds unit coverage.

Changes:

  • Adds the feature filter to AadSmartOnFhirProxyController.
  • Adds behavior and attribute-order tests.
  • Includes the new test in the shared test project.
File Description
AadSmartOnFhirProxyController.cs Applies feature gating to proxy endpoints.
AadSmartOnFhirProxyFeatureFilterAttributeTests.cs Tests filter behavior and registration.
Microsoft.Health.Fhir.Shared.Api.UnitTests.projitems Compiles the new tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Keep the MVC action filters responsible for auditing and returning 401 without requiring authority configuration or outbound discovery. Cover disabled routes, enabled actions and error handling through TestServer.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover enabled authorization-code exchange and launch context propagation, and verify disabled invalid requests are audited as 401 before action validation. No production behavior changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Give the test handler ownership of discovery and token responses and release them during cleanup. Verify content stays readable until the client disposes the handler. Addresses both CodeQL review comments without changing production behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move repeated discovery client and factory wiring into CreateHost. Let the host own the client while each test retains ownership of its handler and responses. Addresses the image-only review suggestion without production changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@rbans96
Richa Bansal (rbans96) enabled auto-merge (squash) September 22, 2026 18:57
@rbans96
Richa Bansal (rbans96) merged commit 9025477 into main Sep 22, 2026
49 checks passed
@rbans96
Richa Bansal (rbans96) deleted the fix/gate-smart-proxy-endpoints-on-feature-flag branch September 22, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug-Security Security related bugs. No-ADR ADR not needed No-PaaS-breaking-change Schema Version unchanged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants