Sidecar: add loopback-only access#3897
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens the Sidecar’s network exposure by replacing host-header filtering with a loopback-only caller restriction (while keeping the health probe endpoint reachable from non-loopback addresses).
Changes:
- Add a loopback-only middleware (
UseLocalCallerRestriction) that blocks non-loopback callers with 403, exempting the health endpoint. - Update Sidecar startup pipeline to apply the loopback restriction in non-development environments and explicitly register auth middleware after it.
- Replace prior host-filtering E2E coverage with new E2E tests validating loopback vs non-loopback behavior (including health endpoint exemption).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/E2E Tests/Sidecar.Tests/LocalCallerRestrictionTests.cs | Adds E2E coverage for loopback-only enforcement and health endpoint exemption. |
| tests/E2E Tests/Sidecar.Tests/HostFilteringTests.cs | Removes E2E coverage for the previous host filtering approach. |
| src/Microsoft.Identity.Web.Sidecar/Program.cs | Switches from host filtering to loopback restriction and adjusts middleware ordering. |
| src/Microsoft.Identity.Web.Sidecar/LocalCallerRestriction.cs | Introduces loopback-only restriction middleware and loopback detection helper. |
iNinja
reviewed
Jun 30, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
iNinja
approved these changes
Jun 30, 2026
iarekk
approved these changes
Jul 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sidecar: add loopback-only access
Summary of the changes (Less than 80 chars)
Description
Restrict sidecar endpoints to loopback callers
Fixes #{bug number} (in this specific format)