Skip to content

fix: restore local PFS authentication by adding WSGI loopback identity middleware#4131

Open
YizukiAme wants to merge 2 commits into
microsoft:mainfrom
YizukiAme:fix/pfs-local-user-auth
Open

fix: restore local PFS authentication by adding WSGI loopback identity middleware#4131
YizukiAme wants to merge 2 commits into
microsoft:mainfrom
YizukiAme:fix/pfs-local-user-auth

Conversation

@YizukiAme

Copy link
Copy Markdown

Fixes #4130

Problem

PR #4090 correctly removed the trust of client-supplied X-Remote-User headers to prevent identity spoofing. However, it did not provide an alternative mechanism for the local Prompt Flow Service (PFS) to identify the local user. Since waitress (the WSGI server used by PFS) never sets REMOTE_USER in the WSGI environ, all local calls to @local_user_only endpoints (/Connections/{name}/listsecrets, /Telemetries/) are now rejected with 403.

Fix

Add a LocalUserMiddleware WSGI middleware that:

  1. Sets REMOTE_USER = getpass.getuser() only when REMOTE_ADDR is 127.0.0.1 or ::1 (loopback)
  2. Strips client-supplied HTTP_REMOTE_USER / HTTP_X_REMOTE_USER headers to prevent spoofing
  3. Leaves non-loopback connections without REMOTE_USER — external connections are correctly rejected

The middleware is applied in create_app() via app.wsgi_app = LocalUserMiddleware(app.wsgi_app).

The existing local_user_only decorator is unchanged — it continues to check only request.environ["REMOTE_USER"], which is now properly populated by the server-side middleware rather than trusting any client header.

Security Properties

  • ✅ Loopback-only: only 127.0.0.1 and ::1 get identity injection
  • ✅ Header stripping: client-supplied Remote-User / X-Remote-User are removed before reaching the app
  • ✅ No new trust surface: the fix adds server-side identity, not client-side
  • ✅ Backwards compatible: @local_user_only behavior is preserved exactly

Tests

4 regression tests in test_local_user_auth_middleware.py:

  • IPv4 loopback → REMOTE_USER injected
  • IPv6 loopback → REMOTE_USER injected
  • Non-loopback → no REMOTE_USER (403 expected)
  • Spoofed headers → stripped, real OS user used

This fix was developed with AI assistance and reviewed by a human.

@YizukiAme

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue/pull request label May 6, 2026
@YizukiAme YizukiAme force-pushed the fix/pfs-local-user-auth branch from 0fd5b88 to a8a971f Compare May 7, 2026 10:28
@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue/pull request label May 7, 2026
@github-actions

Copy link
Copy Markdown

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue/pull request label May 21, 2026
YizukiAme and others added 2 commits May 22, 2026 12:11
Defensively remove HTTP_REMOTE_USER and HTTP_X_REMOTE_USER from the
WSGI environ before checking REMOTE_ADDR, preventing any client from
injecting identity headers that could be trusted by future code paths.
@YizukiAme YizukiAme force-pushed the fix/pfs-local-user-auth branch from a8a971f to abbd94e Compare May 22, 2026 04:11
@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue/pull request label May 22, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue/pull request label Jun 5, 2026
@YizukiAme

Copy link
Copy Markdown
Author

:-)

@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue/pull request label Jun 6, 2026
@github-actions

Copy link
Copy Markdown

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue/pull request label Jun 20, 2026
@YizukiAme

Copy link
Copy Markdown
Author

cmt

@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue/pull request label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local PFS locks legitimate callers out of /listsecrets and /Telemetries/ after auth fix in #4090

1 participant