380

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?

Dave Jarvis
  • 28,853
  • 37
  • 164
  • 291
John
  • 27,040
  • 17
  • 82
  • 121

9 Answers9

487

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.

dr. evil
  • 25,988
  • 28
  • 126
  • 198
  • 4
    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? – Jus12 Oct 29 '13 at 08:12
  • 4
    @Jus12 yes it'll, it doesn't make sense but that's how it's designed. – dr. evil Nov 12 '13 at 13:21
  • 2
    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 http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-16#section-4.3 CC @volka – gihanchanuka Oct 02 '15 at 07:31
  • @dr.evil Could you please elaborate what is the issue with `History caches in browsers` or add some reference for ir? – LCJ Aug 18 '16 at 02:55
  • 1
    To complete that answer with up to date infos : http://www.securitynewspaper.com/2016/08/01/proxy-pac-hack-allows-intercept-https-urls/ ( Proxy PAC hack allows for intercept of HTTPS URLS ) – Tom Aug 20 '16 at 22:25
  • I believe most platforms require all resources on a page to use https if the page is requested using https (at least in .NET) – James Wierzba Feb 13 '17 at 22:14
  • 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. – Arthur Jun 05 '18 at 00:08
  • @Arthur it never says server to server. API's are called all the time from browser. – GaTechThomas Mar 29 '19 at 17:11
  • @GaTechThomas 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) – Arthur Mar 29 '19 at 18:54
  • 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. – GaTechThomas Mar 30 '19 at 13:38
  • Does the same also hold true for WSS connections? ie, can I securely send a key along with the connection URL? – MacroMan Nov 12 '19 at 09:43
  • You can turn off referrer. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy The cache can be disabled too. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data Only the history is an issue. We might be able to trick with that using location.replace. https://stackoverflow.com/a/2196109/607033 – inf3rno Jan 09 '20 at 02:24
84

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.

VolkA
  • 30,233
  • 7
  • 34
  • 36
56

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.

Matthias Braun
  • 24,493
  • 16
  • 114
  • 144
Ruchira Randana
  • 3,525
  • 1
  • 24
  • 23
  • 2
    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. – zaph Mar 28 '16 at 12:11
  • 3
    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. – Ruchira Randana Mar 28 '16 at 12:18
  • 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)`. – zaph Mar 28 '16 at 12:25
  • @RuchiraRandana hashing on client is pointless because the private key is then easily retrieved from the front end. – James W May 23 '18 at 03:42
  • @JamesW "_the private key is then easily retrieved from the front end_" What key? – curiousguy Jul 18 '18 at 13:54
  • @curiousguy 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 up – James W Jul 27 '18 at 02:58
28

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.

Ry-
  • 199,309
  • 51
  • 404
  • 420
shoosh
  • 70,450
  • 50
  • 199
  • 310
26

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.

Aaron Digulla
  • 297,790
  • 101
  • 558
  • 777
  • 3
    "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. – Pieter Nov 17 '15 at 15:18
11

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

Ali Afshar
  • 38,455
  • 12
  • 89
  • 108
10

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.

Community
  • 1
  • 1
Arnout
  • 2,700
  • 13
  • 12
  • 2
    There's that word 'should' again. Would you trust every version of every browser with your password? – JoeBloggs Nov 27 '08 at 11:04
  • 1
    How exactly is this related to GET vs POST? Would "every version of every browser" be safe if you're using POST over HTTPS? – Arnout Nov 27 '08 at 14:59
  • 3
    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... – AviD Apr 04 '09 at 21:36
  • 3
    @Arnout: Please read this RFC which tells you what SHOULD NOT means: http://www.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. – Andy Oct 25 '11 at 13:59
8

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

Wim Hollebrandse
  • 11,657
  • 1
  • 32
  • 56
Drejc
  • 13,466
  • 15
  • 65
  • 101
-5

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

Amareswar
  • 2,061
  • 19
  • 33
  • 11
    MD5 is not suitable hash function for passwords. – slawek Nov 28 '14 at 17:10
  • 1
    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... – Thomas Apr 26 '16 at 09:29
  • 1
    "_not suitable hash function for passwords_" Still better than sending passwords in cleartext to the server, lol – curiousguy Jul 18 '18 at 13:55