Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add login credentials to URL

I tried https://myserver.com/~username=username&password=mypassword but it doesn't work.

Can you confirm that it's possible to pass the user/pass via HTTPs parameters (GET or POST)?

Basically, I want to access this link https://www.globalnorm.net/gn/doc.php?name=ASTM%20F%202638:2012-00&erx=0 (but I need to authenticate ) How can pass my username and password in URL?

like image 568
MokiNex Avatar asked May 25 '18 11:05

MokiNex


People also ask

How do I pass a domain name with a URL?

Try this: driver. get("http://mydomainname%5cUserName:[email protected]"); Ensure that the 'url.com' here in this example is the url that appears on the browser when the authentication pop-up turns up.

Can you ever safely include credentials in a URL?

To summarise my recommendations for securely including credentials in a URL: Always use a limited-scope token such as a capability token (key) or limited scope OAuth access token. Ideally the token should only provide access to the one resource named in the URL. Never ever ever put a username and password in a URL.

How do I encrypt a URL with a password?

Once the server is restarted, log into the server to generate the static key. Open the following URL: http://example.com:8080/jasperserver/encrypt.html. Enter the password that you want to encrypt then click Encrypt. The script on this page will use the public key to encrypt the password.


2 Answers

The standard method to pass basic authentication to web servers is to use a url of the form:

http://user:[email protected]/

Web servers do not expect basic authentication in the query parameters. You can, of course, implement your own authentication using query parameters / HTTP headers or any other method.

Update

The specific URL you had supplied redirects to https://www.globalnorm.net/login.php?ecd=S&info=nosessionorcookie&doc=....

The login path does not return the header WWW-Authenticate which is used to indicate that basic authentication is supported. So no point in trying HTTP basic authentication.

This specific login page seems to expect a POST request to /login.php with USR, PAS parameters. The answer will probably include a cookie which is later used to authenticate with the server.

like image 115
nimrodm Avatar answered Oct 22 '22 00:10

nimrodm


There seems to be some controversy about whether or not browsers have dropped the feature, and/or whether the feature is deprecated. But unless your browser has in fact dropped the feature, then as noted in @nimrodm's answer above, you can specify a url with basic authentication as

http://user:[email protected]/

However, you really should not use http protocol, since that will send the credentials in clear text. Instead, just use:

https://user:[email protected]/

Note that you must urlencode special characters in the user or password fields (I frequently use '@' in my passwords, so those must be written as '%40').

The browser extracts the credentials, and passes them to the server in an Authorization header:

Authorization: Basic credentials

where the credentials are simply the (url-decoded) string "username:password" as written in the url, but base64-encoded. But since the https connection is encrypted, the header is encrypted and the credentials are not exposed outside the browser.

I think the whole issue about removing support or deprecating the feature was based on the security implications of specifying the credentials using http protocol. But with the availability of free ssl certificates, and the push for "ssl everywhere", that no longer seems like much of a problem these days.

Of course there's also the issue of how much good passing credentials this way does you. Many or most applications that require login expect to get the credentials from a form the user fills out and sends with a POST request. The application would have to be written to check each request for an Authorization header, and if present, process the credentials the same way they would if they had been specified by a POST of a filled-out login form.

Applications that expect HTTP basic authentication generally are built with that requirement built into the server configuration, e.g. using Apache directives along theses lines:

<Directory "/htdocs/protected">
    AuthName "Registered User"
    AuthType Basic
    AuthUserFile /lib/protected.users
    require valid-user
</Directory>

Where the file /lib/protected.users is a file of encrypted usernames and passwords generated by the Apache utility program htpasswd. With this configuration, any request for resources below /htdocs/protected is automatically checked by Apache for an Authentication header. If the request has no such header, or the credentials specified in the header do not match one of the pairs of usernames and passwords in /lib/protected.users, then the server responds with a 401 Unauthorized status and a header:

WWW-Authenticate    Basic realm="Registered User"

Note that the realm value "Registered User" is the AuthName value from the Apache configuration. The browser handles this response by displaying a prompt requesting username and password, with the value of the realm contained in the prompt to give the user a hint as to what particular username and password is required.

Browsers have to treat the credentials specially anyway to convert them to an Authorization header, and so they also cache them and send them each time with requests to the same endpoint, like sending cookies. If they didn't do this, then the user would have to supply them on each subsequent url specifying that endpoint to avoid getting prompted.

Hope this helps.

like image 44
sootsnoot Avatar answered Oct 22 '22 01:10

sootsnoot