Skip to content

Split security review rules by path and add audit prompt - #6068

Open
Brendan Kowitz (brendankowitz) wants to merge 13 commits into
mainfrom
personal/bkowitz/security-review-rules
Open

Brendan Kowitz (brendankowitz) wants to merge 13 commits into
mainfrom
personal/bkowitz/security-review-rules

Conversation

@brendankowitz

@brendankowitz Brendan Kowitz (brendankowitz) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Description

Reworks the Copilot code review security rules so that they are more likely to be applied, and adds an audit prompt for existing code, which review cannot cover.

Why. The existing security profile is one file of about thirty dense, multi-sentence bullets that loads for every path. GitHub's guidance for code review instructions is short, imperative, specific rules, and it warns that long files are partly overlooked. The profile also describes boundaries in general terms and names few of the types a reviewer sees in a diff.

What changes.

  • .github/instructions/fhir-security.instructions.md becomes a short core file: the authorization invariant, ten change patterns to flag, a do-not-flag list, input/output limits, and how to write an actionable finding. It still applies to every path.
  • Four new path-specific files load only for matching code: search, bulk and background operations, bundles and conditional operations, and SMART scopes with the request surface. Each rule names the trigger in the code, for example a new ISearchService consumer, a new FhirRequestContext { IsBackgroundTask = true }, a branch on KnownResourceTypes.All, or CheckAccess(DataActions.All) used as authorization.
  • .github/prompts/securityVariantSweep.prompt.md is an agent prompt for auditing existing code against the same rules. Pull request review only sees changed lines.
  • .github/REVIEWING.md documents the file split and a close-out process for security fixes: fix and test, sweep for siblings, update the rules.
  • .github/labeler.yml adds Area-Authorization to pull requests that touch the core authorization paths.

Not changed. No runtime behavior. No workflow, trigger, or merge requirement. REVIEW.md and copilot-instructions.md only have their pointers updated. Every topic in the previous profile is carried into one of the five files.

Affected layers. Review instructions and repository configuration only. No product or test code. Providers and FHIR versions: N/A.

Related issues

Relates to AB#213099, the original code-review guidance story used by #6023.

Testing

Acceptance criterion Implemented in Evidence and result
Copilot code review loads the new path-specific files .github/instructions/security-*.instructions.md Review run 44212418564 at 1b9970c logged [customInstructions] Built 7 custom instruction(s): copilot-instructions.md, fhir-security.instructions.md, security-bundles-conditional.instructions.md, security-smart-scopes.instructions.md, AGENTS.md, CLAUDE.md, REVIEW.md. At that commit the PR still contained a unit test under Features/Security/Authorization/, since removed, and those two path-specific files are the ones whose selectors matched it. The search and background files were not loaded because no changed file matched them, so their selectors are still unexercised. With the test removed, this PR changes no file under src/, so later runs load only the core file.
The new rules catch more than the old profile Instruction files none. Needs the controlled comparison described in REVIEWING.md against known pre-fix commits
Area-Authorization label is applied by path .github/labeler.yml none. The labeler reads its configuration from the base branch, so this can only be observed after merge

Assumptions and limits: the applyTo globs were written against the current directory layout. Only the two selectors noted above have been exercised by a review run. No tests were run, because the PR changes no product or test code.

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)

Skip

🤖 Generated with Claude Code

Copilot AI and others added 2 commits November 17, 2026 16:07
Replace the single all-paths security profile with a short core file and
four path-specific files, so each review loads rules that match the code
being changed. Rules are short, imperative, and tied to types and
patterns a reviewer can find in a diff.

Add a variant sweep prompt for auditing existing code, a close-out
process for security fixes, and an Area-Authorization path label.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Fail the build when a new type is constructed with ISearchService, so a
new path to stored resources that bypasses SearchResourceHandler gets a
deliberate authorization review.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>

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.

🟡 Changes recommended

The split drops existing security checks, excludes relevant implementation paths from rule selectors, and incorrectly requires claims that some supported authorization modes do not need.

4 open issues
What changed in this PR

This PR reorganizes security review guidance for the FHIR server into core and path-specific rules, adds a guard test for new search-service consumers, and documents follow-up audits. It does not change runtime behavior.

Changes:

  • Splits security guidance into five instruction files and updates review documentation.
  • Adds a shared unit test that checks core-assembly ISearchService consumers against a 27-type baseline.
  • Adds a security audit prompt and path-based authorization labeling.
File Description
src/​Microsoft.Health.Fhir.Shared.Core.UnitTests/​Microsoft.Health.Fhir.Shared.Core.UnitTests.projitems Includes the guard test in shared test projects.
src/​Microsoft.Health.Fhir.Shared.Core.UnitTests/​Features/​Security/​Authorization/​SearchServiceConsumerGuardTests.cs Detects new constructor-based search-service consumers and stale baseline entries.
REVIEW.md Updates pointers to split security guidance.
.github/​REVIEWING.md Documents instruction coverage and security-fix follow-up.
.github/​prompts/​securityVariantSweep.prompt.md Adds a prompt for auditing related authorization gaps.
.github/​labeler.yml Adds authorization-area labels for matching paths.
.github/​instructions/​security-smart-scopes.instructions.md Adds identity, scope, and request-surface rules.
.github/​instructions/​security-search.instructions.md Adds search authorization and filtering rules.
.github/​instructions/​security-bundles-conditional.instructions.md Adds bundle, conditional-operation, and write rules.
.github/​instructions/​security-background-operations.instructions.md Adds bulk-operation and background-job rules.
.github/​instructions/​fhir-security.instructions.md Replaces the broad profile with core security checks.
.github/​copilot-instructions.md Updates references to the split instruction files.

Review effort: Balanced

…lectors

Limit claim refusal to what the active scope kind requires. Restore the file/archive containment and output encoding checks. Add definition, schema, module, and conformance paths to the rule selectors. Add a do-not-flag list and guidance for writing an actionable finding.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>

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.

🔵 Needs a closer look

The instruction globs omit middleware registration, $everything, and historical-read implementation paths, so changes confined to those files would bypass previously global security review checks.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Include $everything and version-read paths in the selector

.github/​instructions/​security-search.instructions.md:2

Please include the $everything and version-read implementation paths in this selector. src/Microsoft.Health.Fhir.Shared.Core/Features/Operations/Everything/PatientEverythingService.cs implements expansion and continuation handling, and src/Microsoft.Health.Fhir.Shared.Core/Features/Resources/Get/GetResourceHandler.cs handles historical version reads, but neither matches these globs. A PR changing only either file therefore won't load the corresponding search rules (4, 9, and 10), which previously applied through the all-path profile. The background/bundle rules selected for those paths do not retain those checks.

Medium severity Include middleware-registration path in the glob

.github/​instructions/​security-smart-scopes.instructions.md:2

Please include the middleware-registration path in this glob. src/Microsoft.Health.Fhir.Shared.Api/Registration/FhirServerServiceCollectionExtensions.cs:282–350 composes the request pipeline, including UseFhirRequestContextAuthentication(), but matches none of these patterns. A PR that only changes that ordering therefore will not load this file's authentication and middleware-order checks. Those checks previously applied globally.

4 resolved since last review

Review effort: Balanced

Load the search rules for $everything, $member-match, resource reads, and Cosmos query and storage code. Load the identity rules for pipeline registration and the development identity provider.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@brendankowitz
Brendan Kowitz (brendankowitz) marked this pull request as ready for review November 18, 2026 00:53
Copilot AI balanced review requested due to automatic review settings November 18, 2026 00:53

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.

🔵 Needs a closer look

Human assessment is needed because selector gaps leave policy definitions, Azure storage connections, and conditional authorization helpers outside their targeted security-review guidance.

No open issues 🎉

Review effort: Balanced

…ion helpers

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 01:00

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.

🔵 Needs a closer look

The security-review control changes need maintainer verification of instruction loading and a controlled detection comparison, neither of which is established by the supplied evidence.

No open issues 🎉

Review effort: Balanced

Non-clinical scopes are correctly ignored; the rule flags widening of clinical scopes. Restore the synthetic-data, no-live-probe, and untrusted-code safeguards from the previous profile.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 01:31
The test only caught a new type taking ISearchService in its constructor.
It did not cover new calls inside existing consumers, and the core review
rules already ask the same question of a new consumer.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 18:17

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.

🔵 Needs a closer look

Human assessment is needed to weigh an overbroad profile-edit permission requirement and a labeling gap that leaves SMART scope authorization changes unclassified.

No open issues 🎉

Review effort: Balanced

@brendankowitz Brendan Kowitz (brendankowitz) changed the title Split security review rules by path and add guard test Split security review rules by path and add audit prompt Nov 18, 2026
Read-only exports are authorized with read and export access; EditProfileDefinitions only covers creating, updating, or deleting profile-defining resources.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:44

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.

🔵 Needs a closer look

Human assessment is needed to evaluate a selector gap that leaves changes to the SMART export authorization boundary without the expected Area-Authorization label.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:49

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.

🔵 Needs a closer look

Human assessment is needed because the split security-instruction selectors omit previously covered shared conditional lookups and search-parameter disabling operations, leaving relevant security rules unloaded.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:56

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.

🔵 Needs a closer look

Human assessment is needed because the scope-rejection guidance conflicts with documented and tested behavior permitting withdrawal of an unenforceable scope when another scope still authorizes access.

No open issues 🎉

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 23:03

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.

🟢 Approval recommended

No active review issues remain for the security-guidance and repository-labeling changes.

No open issues 🎉

Review effort: Balanced

SmartScopeFhirAuthorizationService is a static helper that
RoleBasedFhirAuthorizationService intersects with role actions, not a
parallel service, so the rule now describes the intersection. The scope
rejection rule is split into malformed input and unenforceable scopes.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 00:49

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.

🔵 Needs a closer look

Human assessment is needed because the split’s rule selectors omit relevant authentication and scope-handling implementations, leaving security guidance coverage incomplete.

No open issues 🎉

Review effort: Balanced

Startup.cs configures JWT bearer validation, ExportSmartScopeAuthorizer
evaluates SMART scopes for export, and SearchOptionsFactory withdraws
unenforceable scopes. None matched the identity and scope rule selector.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 05:21

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.

🟢 Approval recommended

No active review issues block approval of the security-guidance reorganization.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Requires documentation. No-ADR ADR not needed No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants