<p>I know next to nothing when it comes to the how and why of https connections.  Obviously, when I'm transmitting secure data like passwords or especially credit card information, https is a critical tool.  What do I need to know about it, though?  What are the most common mistakes you see developers making when they implement it in their projects?  Are there times when https is just a bad idea?  Thanks!</p>

[{'answer_id': 64708, 'author': 'Lucas Oman', 'author_id': 6726, 'author_profile': 'https://Stackoverflow.com/users/6726', 'pm_score': 1, 'selected': False, 'text': '<p>Be sure that, when on an HTTPS page, all elements on the page come from an HTTPS address. This means that elements should have relative paths (e.g. "/images/banner.jpg") so that the protocol is inherited, or that you need to do a check on every page to find the protocol, and use that for all elements.</p>\n\n<p>NB: This includes all outside resources (like Google Analytics javascript files)!</p>\n\n<p>The only down-side I can think of is that it adds (nearly negligible) processing time for the browser and your server. I would suggest encrypting only the transfers that need to be.</p>\n'}, {'answer_id': 64719, 'author': 'Doug T.', 'author_id': 8123, 'author_profile': 'https://Stackoverflow.com/users/8123', 'pm_score': 0, 'selected': False, 'text': '<p>I would suggest any time <em>any</em> user data is stored in a database and communicated, use https. Consider this requirement even if the user data is mundane, because even many of these mundane details are used by that user to identify themselves on other websites. Consider all the random security questions your bank asks you (like what street do you live on?). This can be taken from address fields really easily. In this case, the data is not what you consider a password, but it might as well be. Furthermore, you can never anticipate what user data will be used for a security question elsewhere. You can also expect that with the intelligence of the average web user (think your grandmother) that that tidbit of information might make up part of that user\'s password somewhere else.</p>\n\n<p>One pointer if you use https</p>\n\n<p>make it so that if the user types\n<a href="http://www.website-that-needs-https.com/etc/yadda.php" rel="nofollow noreferrer">http://www.website-that-needs-https.com/etc/yadda.php</a>\nthey will automatically get redirected to \n<a href="https://www.website-that-needs-https.com/etc/yadda.php" rel="nofollow noreferrer">https://www.website-that-needs-https.com/etc/yadda.php</a>\n(personal pet peeve)</p>\n\n<p>However, if you\'re just doing a plain html webpage, that will be essentially a one-way transmission of information from the server to the user, don\'t worry about it. </p>\n'}, {'answer_id': 64722, 'author': 'Peter Bailey', 'author_id': 8815, 'author_profile': 'https://Stackoverflow.com/users/8815', 'pm_score': 1, 'selected': False, 'text': "<p>I would say the most common mistakes when working with an SSL-enabled site are </p>\n\n<ol>\n<li>The site erroneously redirects users to http from a page as https</li>\n<li>The site doesn't automatically switch to https when it's necessary</li>\n<li>Images and other assets on an https page are being loading via http, which will trigger a security alert from the browser. Make sure all assets are using fully-qualified URIs that specify https.</li>\n<li>The security certificate only works for one subdomain (such as www) but your site actually uses multiple subdomains. Make sure to get a wildcard certificate if you will need it.</li>\n</ol>\n"}, {'answer_id': 67714, 'author': 'gregmac', 'author_id': 7913, 'author_profile': 'https://Stackoverflow.com/users/7913', 'pm_score': 6, 'selected': True, 'text': '<p>An HTTPS, or Secure Sockets Layer (SSL) certificate is served for a site, and is typically signed by a Certificate Authority (CA), which is effectively a trusted 3rd party that verifies some basic details about your site, and certifies it for use in browsers. If your browser trusts the CA, then it trusts any certificates signed by that CA (this is known as the trust chain). </p>\n\n<p>Each HTTP (or HTTPS) request consists of two parts: a request, and a response. When you request something through HTTPS, there are actually a few things happening in the background:</p>\n\n<ul>\n<li>The client (browser) does a "handshake", where it requests the server\'s public key and identification. \n\n<ul>\n<li>At this point, the browser can check for validity (does the site name match? is the date range current? is it signed by a CA it trusts?). It can even contact the CA and make sure the certificate is valid. </li>\n</ul></li>\n<li>The client creates a new pre-master secret, which is encrypted using the servers\'s public key (so only the server can decrypt it) and sent to the server</li>\n<li>The server and client both use this pre-master secret to generate the master secret, which is then used to create a symmetric session key for the actual data exchange</li>\n<li>Both sides send a message saying they\'re done the handshake</li>\n<li>The server then processes the request normally, and then encrypts the response using the session key</li>\n</ul>\n\n<p>If the connection is kept open, the same symmetric key will be used for each.</p>\n\n<p>If a new connection is established, and both sides still have the master secret, new session keys can be generated in an \'abbreviated handshake\'. Typically a browser will store a master secret until it\'s closed, while a server will store it for a few minutes or several hours (depending on configuration).</p>\n\n<p>For more on the length of sessions see <a href="https://security.stackexchange.com/a/55477/27894">How long does an HTTPS symmetric key last?</a></p>\n\n<p><strong>Certificates and Hostnames</strong></p>\n\n<p>Certificates are assigned a Common Name (CN), which for HTTPS is the domain name. The CN has to match exactly, eg, a certificate with a CN of "example.com" will NOT match the domain "www.example.com", and users will get a warning in their browser.</p>\n\n<p>Before <a href="https://en.wikipedia.org/wiki/Server_Name_Indication" rel="nofollow noreferrer">SNI</a>, it was not possible to host multiple domain names on one IP. Because the certificate is fetched before the client even sends the actual HTTP request, and the HTTP request contains the Host: header line that tells the server what URL to use, there is no way for the server to know what certificate to serve for a given request. SNI adds the hostname to part of the TLS handshake, and so as long as it\'s supported on both client and server (and in 2015, it is widely supported) then the server can choose the correct certificate. </p>\n\n<p>Even without SNI, one way to serve multiple hostnames is with certificates that include Subject Alternative Names (SANs), which are essentially additional domains the certificate is valid for. Google uses a single certificate to secure many of it\'s sites, for example.</p>\n\n<p><a href="https://i.stack.imgur.com/3Tniz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Tniz.png" alt="Google SSL certificate"></a></p>\n\n<p>Another way is to use wildcard certificates. It is possible to get a certificate like "<em>.example.com" in which case "www.example.com" and "foo.example.com" will both be valid for that certificate. However, note that "example.com" does not match "</em>.example.com", and neither does "foo.bar.example.com". If you use "www.example.com" for your certificate, you should redirect anyone at "example.com" to the "www." site. If they request <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>, unless you host it on a separate IP and have two certificates, the will get a certificate error. </p>\n\n<p>Of course, you can mix both wildcard and SANs (as long as your CA lets you do this) and get a certificate for both "example.com" and with SANs "<em>.example.com", "example.net", and "</em>.example.net", for example.</p>\n\n<p><strong>Forms</strong></p>\n\n<p>Strictly speaking, if you are submitting a form, it doesn\'t matter if the form page itself is not encrypted, as long as the submit URL goes to an https:// URL. In reality, users have been trained (at least in theory) not to submit pages unless they see the little "lock icon", so even the form itself should be served via HTTPS to get this. </p>\n\n<p><strong>Traffic and Server Load</strong></p>\n\n<p>HTTPS traffic is much bigger than its equivalent HTTP traffic (due to encryption and certificate overhead), and it also puts a bigger strain on the server (encrypting and decrypting). If you have a heavily-loaded server, it may be desirable to be very selective about what content is served using HTTPS. </p>\n\n<p><strong>Best Practices</strong></p>\n\n<ul>\n<li><p>If you\'re not just using HTTPS for the entire site, it should automatically redirect to HTTPS as required. Whenever a user is logged in, they should be using HTTPS, and if you\'re using session cookies, the cookie should have the <a href="http://php.net/manual/en/function.session-set-cookie-params.php" rel="nofollow noreferrer">secure flag set</a>. This prevents interception of the session cookie, which is especially important given the popularity of open (unencrypted) wifi networks. </p></li>\n<li><p>Any resources on the page should come from the same scheme being used for the page. If you try to fetch images from http:// when the page is loaded with HTTPS, the user will get security warnings. You should either use fully-qualified URLs, or another easy way is to use absolute URLs that do not include the hostname (eg, src="/images/foo.png") because they work for both. </p>\n\n<ul>\n<li>This includes external resources (eg, Google Analytics)</li>\n</ul></li>\n<li><p>Don\'t do POSTs (form submits) when changing from HTTPS to HTTP. Most browsers will flag this as a security warning.</p></li>\n</ul>\n'}, {'answer_id': 67739, 'author': 'paan', 'author_id': 2976, 'author_profile': 'https://Stackoverflow.com/users/2976', 'pm_score': 0, 'selected': False, 'text': '<p>All very good tip here... but I just want to add something..<br>\nIve seen some sites that gives you a http login page and only redirect you to https after you post your username/pass.. This means the username is transmitted in the clear before the https connection is established.. </p>\n\n<p>In short make the page where you login from ssl, instead of posting to an ssl page.</p>\n'}, {'answer_id': 70447, 'author': 'AviD', 'author_id': 10080, 'author_profile': 'https://Stackoverflow.com/users/10080', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m not going to go in depth on SSL in general, gregmac did a great job on that, see below ;-).</p>\n\n<p>However, some of the most common (and critical) mistakes made (not specifically PHP) with regards to use of SSL/TLS: </p>\n\n<ol>\n<li>Allowing HTTP when you should be enforcing HTTPS </li>\n<li>Retrieving some resources over HTTP from an HTTPS page (e.g. images, IFRAMEs, etc) </li>\n<li><p>Directing to HTTP page from HTTPS page unintentionally - note that this includes "fake" pages, such as "about:blank" (I\'ve seen this used as IFRAME placeholders), this will needlessly and unpleasantly popup a warning.</p></li>\n<li><p>Web server configured to support old, unsecure versions of SSL (e.g. SSL v2 is common, yet horribly broken) \n(okay, this isn\'t exactly the programmer\'s issue, but sometimes noone else will handle it...)</p></li>\n<li><p>Web server configured to support unsecure cipher suites (I\'ve seen NULL ciphers only in use, which basically provides absolutely NO encryption) \n(ditto)</p></li>\n<li><p>Self-signed certificates - prevents users from verifying the site\'s identity.</p></li>\n<li><p>Requesting the user\'s credentials from an HTTP page, even if submitting to an HTTPS page. Again, this prevents a user from validating the server\'s identity BEFORE giving it his password... Even if the password is transmitted encrypted, the user has no way of knowing if he\'s on a bogus site - or even if it WILL be encrypted.</p></li>\n<li><p>Non-secure cookie - security-related cookies (such as sessionId, authentication token, access token, etc.) <strong>MUST</strong> be set with the "secure" attribute set. This is important! If it\'s not set to secure, the security cookie, e.g. SessionId, can be transmitted over HTTP (!) - and attackers can ensure this will happen - and thus allowing session hijacking etc. While you\'re at it (tho this is not directly related), set the HttpOnly attribute on your cookies, too (helps mitigate some XSS).</p></li>\n<li><p>Overly permissive certificates - say you have several subdomains, but not all of them are at the same trust level. For instance, you have www.yourdomain.com, dowload.yourdomain.com, and publicaccess.yourdomain.com. So you might think about going with a wildcard certificate.... BUT you also have secure.yourdomain.com, or finance.yourdomain.com - even on a different server. publicaccess.yourdomain.com will then be able to impersonate secure.yourdomain.com.... \nWhile there may be instances where this is okay, usually you\'d want some separation of privileges...</p></li>\n</ol>\n\n<p>That\'s all I can remember right now, might re-edit it later...</p>\n\n<p>As far as when is it a BAD idea to use SSL/TLS - if you have public information which is NOT intended for a specific audience (either a single user or registered members), AND you\'re not particular about them retrieving it specifically from the proper source (e.g. stock ticker values MUST come from an authenticated source...) - then there is no real reason to incur the overhead (and not just performance... dev/test/cert/etc).</p>\n\n<p>However, if you have shared resources (e.g. same server) between your site and another MORE SENSITIVE site, then the more sensitive site should be setting the rules here. </p>\n\n<p>Also, passwords (and other credentials), credit card info, etc should ALWAYS be over SSL/TLS.</p>\n'}, {'answer_id': 210279, 'author': 'JSchaefer', 'author_id': 3676, 'author_profile': 'https://Stackoverflow.com/users/3676', 'pm_score': 0, 'selected': False, 'text': '<p>I found that trying to <code>&lt;link&gt;</code> to a non-existent style sheet also caused security warnings.  When I used the correct path, the lock icon appeared.</p>\n'}]
['https://Stackoverflow.com/questions/64631', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']