You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Restrain sending http credentials on a specific hostname #20464
Let's consider doing a navigation on a page that requires HTTP authentication. From the browser, this would typically show a dialog prompting for user credentials.
With Playwright, this pair of string "username" and "password" can be set on the browser context with the code below:
That allows Playwright to use these credentials when any servers respond with HTTP 401 unauthorized, in order to secure the connection. This works fine regardless of the HTTP authentication mecanism: basic, ntlm, kerberos...
However, we have a concern in terms of security, about these credentials being sent to any servers, other than the one we specified the credentials for.
In order to restrain sending HTTP credential to only the expected server, we would like to have the ability to specify a hostname, additionaly to the current pair username/password set on the browser context. So when an authorization response is received from servers, the credentials are sent only if the server hostname in the request matches case insensitive the specified hostname. Otherwise, if the hostname does not match, then the credentials wouldn't be sent, same as if no credentials were configured (likely causing the server to fail the authorization and return 401 HTTP status).
Also, in order to not break the compatibility with previous project, that additional parameter for the hostname needs to be optional. When not present, it should behave exactly the same way as before, namely always sending the credentials to any server.
We submitted a PR for that matter: #20374. We could also consider a more advance matching algorighm if you prefer (such as regexp on full request path), but we thought doing a simple string compare of the full hostname could be enough as a first step. Later, we are also interested into improving the Java wrapper.
We should do the same with our API - specify origin instead of hostname. If it is easy to add optional realm/scheme fields for all browsers, we can also do that.
Activity
dgozman commentedon Feb 15, 2023
Chromium caches http credentials per
origin + realm + scheme, where:originis scheme+host+port of the request;realmis the auth realm;schemeis the auth scheme.See WWW-Authenticate for realm/scheme descriptions.
We should do the same with our API - specify
origininstead ofhostname. If it is easy to add optionalrealm/schemefields for all browsers, we can also do that.pavelfeldman commentedon Feb 27, 2023
Sébastien Richert (@SebastienRichert): looks like we need to use origin instead of the hostname as per Dmitry Gozman (@dgozman) , please ack!
SebastienRichert commentedon Feb 28, 2023
Pavel Feldman (@pavelfeldman): Completely agree ! We'll update the PR to have the parameter "origin" as optional string (instead of hostname only.