fix: restore local PFS authentication by adding WSGI loopback identity middleware#4131
fix: restore local PFS authentication by adding WSGI loopback identity middleware#4131YizukiAme wants to merge 2 commits into
Conversation
|
@microsoft-github-policy-service agree |
371e7f2 to
9a4d51d
Compare
641a980 to
0fd5b88
Compare
|
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. |
0fd5b88 to
a8a971f
Compare
|
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. |
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.
a8a971f to
abbd94e
Compare
|
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. |
|
:-) |
|
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. |
|
cmt |
Fixes #4130
Problem
PR #4090 correctly removed the trust of client-supplied
X-Remote-Userheaders to prevent identity spoofing. However, it did not provide an alternative mechanism for the local Prompt Flow Service (PFS) to identify the local user. Sincewaitress(the WSGI server used by PFS) never setsREMOTE_USERin the WSGI environ, all local calls to@local_user_onlyendpoints (/Connections/{name}/listsecrets,/Telemetries/) are now rejected with 403.Fix
Add a
LocalUserMiddlewareWSGI middleware that:REMOTE_USER = getpass.getuser()only whenREMOTE_ADDRis127.0.0.1or::1(loopback)HTTP_REMOTE_USER/HTTP_X_REMOTE_USERheaders to prevent spoofingREMOTE_USER— external connections are correctly rejectedThe middleware is applied in
create_app()viaapp.wsgi_app = LocalUserMiddleware(app.wsgi_app).The existing
local_user_onlydecorator is unchanged — it continues to check onlyrequest.environ["REMOTE_USER"], which is now properly populated by the server-side middleware rather than trusting any client header.Security Properties
127.0.0.1and::1get identity injectionRemote-User/X-Remote-Userare removed before reaching the app@local_user_onlybehavior is preserved exactlyTests
4 regression tests in
test_local_user_auth_middleware.py:This fix was developed with AI assistance and reviewed by a human.