Is a HTTPS query string secure?
Asked Answered
T

9

435

I am creating a secure web based API that uses HTTPS; however, if I allow the users to configure it (include sending password) using a query string will this also be secure or should I force it to be done via a POST?

Thrombin answered 27/11, 2008 at 8:18 Comment(0)
D
534

Yes, it is. But using GET for sensitive data is a bad idea for several reasons:

  • Mostly HTTP referrer leakage (an external image in the target page might leak the password[1])
  • Password will be stored in server logs (which is obviously bad)
  • History caches in browsers

Therefore, even though Querystring is secured it's not recommended to transfer sensitive data over querystring.

[1] Although I need to note that RFC states that browser should not send referrers from HTTPS to HTTP. But that doesn't mean a bad 3rd party browser toolbar or an external image/flash from an HTTPS site won't leak it.

Dublin answered 27/11, 2008 at 8:19 Comment(13)
What about https to https referrers? If I am getting an image from a 3rd party site using https? Will the browser send the entire query string from my previous request to the 3rd party server?Blizzard
@Blizzard yes it'll, it doesn't make sense but that's how it's designed.Dublin
Then why is that OAuth2 specification isn't recommend to send sensitive data in query parameters (in the URL) ? Even though it's recommend to use TLS (HTTPS) always. Refer to the last point in tools.ietf.org/html/draft-ietf-oauth-v2-bearer-16#section-4.3 CC @volkaJerry
@dr.evil Could you please elaborate what is the issue with History caches in browsers or add some reference for ir?Bellerophon
To complete that answer with up to date infos : securitynewspaper.com/2016/08/01/… ( Proxy PAC hack allows for intercept of HTTPS URLS )Curule
I believe most platforms require all resources on a page to use https if the page is requested using https (at least in .NET)Electrician
The original question states he is creating an API. So server-to-server calls. How is referrer leakage or browser history even relevant here? Regarding server-side logging of GET parameters; a server admin may just as well (accidentally) have enabled logging of POST parameters; so one can argue if that really makes much of a difference? I would advise in general to be in control of your server environment, whether that means disabling logging of GET parameters for certain requests, or making sure logging of POST parameters is disabled.Sessler
@Sessler it never says server to server. API's are called all the time from browser.Millner
@Millner it doesn't literally say that in the question; however he is talking about including a password in the calls. To me that doesn't sound like an API to be used from the client browser; otherwise you are exposing the API password to all clients.. (then it doesn't matter if it is included as GET or POST parameter)Sessler
I see. Sending password to the API server is such a thing of the past that I didn't comprehend that that was the intent. You're right. For others reading this, the question is good for understanding URL visibility, but the overall approach should be reconsidered.Millner
Does the same also hold true for WSS connections? ie, can I securely send a key along with the connection URL?Map
You can turn off referrer. developer.mozilla.org/en-US/docs/Web/HTTP/Headers/… The cache can be disabled too. developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control developer.mozilla.org/en-US/docs/Web/HTTP/Headers/… Only the history is an issue. We might be able to trick with that using location.replace. https://mcmap.net/q/81890/-how-to-clear-browsers-ie-firefox-opera-chrome-history-using-javascript-or-java-except-from-browser-itselfUlmer
is it secure if post contains query string? I mean like how about the data passed through query string? can someone get the query string data from tampering / sniffing like wireshark or burp suite?Pes
R
95

From a "sniff the network packet" point of view a GET request is safe, as the browser will first establish the secure connection and then send the request containing the GET parameters. But GET url's will be stored in the users browser history / autocomplete, which is not a good place to store e.g. password data in. Of course this only applies if you take the broader "Webservice" definition that might access the service from a browser, if you access it only from your custom application this should not be a problem.

So using post at least for password dialogs should be preferred. Also as pointed out in the link littlegeek posted a GET URL is more likely to be written to your server logs.

Rathbone answered 27/11, 2008 at 8:29 Comment(0)
L
81

Yes, your query strings will be encrypted.

The reason behind is that query strings are part of the HTTP protocol which is an application layer protocol, while the security (SSL/TLS) part comes from the transport layer. The SSL connection is established first and then the query parameters (which belong to the HTTP protocol) are sent to the server.

When establishing an SSL connection, your client will perform the following steps in order. Suppose you're trying to log in to a site named example.com and want to send your credentials using query parameters. Your complete URL may look like the following:

https://example.com/login?username=alice&password=12345)
  1. Your client (e.g., browser/mobile app) will first resolve your domain name example.com to an IP address (124.21.12.31) using a DNS request. When querying that information, only domain specific information is used, i.e., only example.com will be used.
  2. Now, your client will try to connect to the server with the IP address 124.21.12.31 and will attempt to connect to port 443 (SSL service port not the default HTTP port 80).
  3. Now, the server at example.com will send its certificates to your client.
  4. Your client will verify the certificates and start exchanging a shared secret key for your session.
  5. After successfully establishing a secure connection, only then will your query parameters be sent via the secure connection.

Therefore, you won't expose sensitive data. However, sending your credentials over an HTTPS session using this method is not the best way. You should go for a different approach.

Lollis answered 28/3, 2016 at 6:52 Comment(6)
But see the answer by @dr. evil, the quarry string may end up in log files and caches so it is may not secure on the server.Petrifaction
Hi zaph, in terms of HTTPS security, the objective is to send data securely to the server without anyone in the middle being able to sniff out the data. While that is possible, and answers the question, it's really difficult to control what the server does afterwards. That's why I've also mentioned this is not the correct way. Adding to that, you should never send ur password from the client. You should always hash it on the device and send the hash value to the server.Lollis
From a security standpoint sending confidential information in the quarry string is not secure, it is best to send it in a POST. Also the password is generally hashed on the server, not by the client. The statement "you should never send ur password from the client" is in conflict with the answer: (e.g http://example.com/login?username=alice&password=12345).Petrifaction
@RuchiraRandana hashing on client is pointless because the private key is then easily retrieved from the front end.Ragin
@JamesW "the private key is then easily retrieved from the front end" What key?Khotan
@Khotan yeah good point. And having the hasing algorithm doens't enable the "unhash" of the thing itself. And hashing it on the front end limits MITM attacks. My Mistake for some reason i had hash and encrypt on the brain mixed upRagin
A
33

Yes. The entire text of an HTTPS session is secured by SSL. That includes the query and the headers. In that respect, a POST and a GET would be exactly the same.

As to the security of your method, there's no real way to say without proper inspection.

Amyloid answered 27/11, 2008 at 8:24 Comment(2)
There's more to security than just the communication between browser & serverDubious
Yeah, but in my browser history it will say: https : //www.google.com?query=mySecretQueryMaren
E
29

SSL first connects to the host, so the host name and port number are transferred as clear text. When the host responds and the challenge succeeds, the client will encrypt the HTTP request with the actual URL (i.e. anything after the third slash) and and send it to the server.

There are several ways to break this security.

It is possible to configure a proxy to act as a "man in the middle". Basically, the browser sends the request to connect to the real server to the proxy. If the proxy is configured this way, it will connect via SSL to the real server but the browser will still talk to the proxy. So if an attacker can gain access of the proxy, he can see all the data that flows through it in clear text.

Your requests will also be visible in the browser history. Users might be tempted to bookmark the site. Some users have bookmark sync tools installed, so the password could end up on deli.ci.us or some other place.

Lastly, someone might have hacked your computer and installed a keyboard logger or a screen scraper (and a lot of Trojan Horse type viruses do). Since the password is visible directly on the screen (as opposed to "*" in a password dialog), this is another security hole.

Conclusion: When it comes to security, always rely on the beaten path. There is just too much that you don't know, won't think of and which will break your neck.

Espousal answered 27/11, 2008 at 8:45 Comment(1)
"the browser will still talk to the proxy" not quite true, it will need to present the browser with a valid certificate that the proxy can only generate if it has control over a CA the browser trusts.Vaduz
C
14

Yes, as long as no one is looking over your shoulder at the monitor.

Chainsmoke answered 27/11, 2008 at 11:17 Comment(0)
Z
12

I don't agree with the statement about [...] HTTP referrer leakage (an external image in the target page might leak the password) in Slough's response.

The HTTP 1.1 RFC explicitly states:

Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.

Anyway, server logs and browser history are more than sufficient reasons not to put sensitive data in the query string.

Zaccaria answered 27/11, 2008 at 9:40 Comment(4)
There's that word 'should' again. Would you trust every version of every browser with your password?Dubious
How exactly is this related to GET vs POST? Would "every version of every browser" be safe if you're using POST over HTTPS?Zaccaria
Besides, the HTTPS web page might be retreiving an external image over HTTPS - in which case, the browser SHOULD include the referer header, and thus expose your password...Olivo
@Arnout: Please read this RFC which tells you what SHOULD NOT means: ietf.org/rfc/rfc2119.txt Its NOT the same as MUST NOT, so the part you quoted isn't really relevent and browser agents might still include a referer to HTTP.Potassium
P
10

Yes, from the moment on you establish a HTTPS connection everyting is secure. The query string (GET) as the POST is sent over SSL.

Phosphorite answered 27/11, 2008 at 8:24 Comment(1)
Using GET for transferring sensitive information is a well known security vulnerability, should be avoided. Also see @Rathbone post below for some reasons why it shouldn't be done.Double
G
-7

You can send password as MD5 hash param with some salt added. Compare it on the server side for auth.

Gouache answered 8/11, 2012 at 2:0 Comment(3)
MD5 is not suitable hash function for passwords.Tempietempla
Whether hashed or in cleartext, it is bad practice to send passwords within GET parameters. Please refer to the top voted answer for explanations. Aaaand... MD5 should not be used anywhere anymore...Caesarean
"not suitable hash function for passwords" Still better than sending passwords in cleartext to the server, lolKhotan

© 2022 - 2024 — McMap. All rights reserved.