ChatGPT解决这个技术问题 Extra ChatGPT

Is a HTTPS query string secure?

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?


3
3 revs, 2 users 89%

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.


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 yes it'll, it doesn't make sense but that's how it's designed.
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 @volka
To complete that answer with up to date infos : securitynewspaper.com/2016/08/01/… ( Proxy PAC hack allows for intercept of HTTPS URLS )
@Arthur it never says server to server. API's are called all the time from browser.
V
VolkA

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.


M
Matthias Braun

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)

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. 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). Now, the server at example.com will send its certificates to your client. Your client will verify the certificates and start exchanging a shared secret key for your session. 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.


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.
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.
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).
@RuchiraRandana hashing on client is pointless because the private key is then easily retrieved from the front end.
@JamesW "the private key is then easily retrieved from the front end" What key?
R
Ry-

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.


There's more to security than just the communication between browser & server
A
Aaron Digulla

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.


"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.
A
Ali Afshar

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


C
Community

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.


There's that word 'should' again. Would you trust every version of every browser with your password?
How exactly is this related to GET vs POST? Would "every version of every browser" be safe if you're using POST over HTTPS?
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...
@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.
W
Wim

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


A
Amareswar

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


MD5 is not suitable hash function for passwords.
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...
"not suitable hash function for passwords" Still better than sending passwords in cleartext to the server, lol