by fatzombi_ · 9y ago · 0 comments
<script src="https://cdn.example.com/awesome.js">
By doing so, I am requiring the script to be served securely. If we allow self-signed certificates, anyone could generate a self-signed certificate for example.com and serve a malicious script to my users.Automatically generated self-signed certificates should have replaced all plaintext HTTP 15-20 years ago. The big security hole was allowing passive surveillance, ISP-level page injection vandalism[1]/attacks[2].
The web could have been almost completely protected from several classes of attack a decade ago, but this stupid insistence on conflating protection from 3rd part eavesdropping or corruption during transit with the authentication of the server. These are entirely separate problems that do not need to be solved at the same time.
> I am requiring the script to be served securely
You're requiring it to be served over HTTPS, which doesn't necessarily mean "secure", because "secure" covers several different goals. You're also strongly trusting the PKI system. Do you trust all the certificate authorities your browser includes by default?
Of course, because HTTP still exists, the initial request for the HTML that contains your <script> tag could be sent plaintext and thus modified during transit in many different ways.
> serve a malicious script to my users.
That can still happen without proper pinning, or if the local browser downgrades the request back to HTTP. Unfortunately this isn't particularly uncommon with corporate/school proxy, in-flight wi-fi services that forge certificates[3], and Superfish-style junk all removing both the encryption and the authentication provided by TLS.
Regarding your specific example about loading Javascript referenced in an HTML document's <script> tag, the solution is to validate the data, not the server. The valid server can still send incorrect data. If you include hashes about a page's subresources[4], the browser can validate the integrity of the file it received.
[1] https://arstechnica.com/tech-policy/2014/09/why-comcasts-jav...
[2] https://citizenlab.ca/2015/04/chinas-great-cannon/
[3] https://arstechnica.com/information-technology/2016/02/why-y...
The client can detect changing to a new certificate. Obviously self signed certificates have problems. The main point is that it does protect against some attacks, and raises the complexity/cost. Running a MITM takes a lot more time, effort, and resources compared to simple deep packet inspection on plaintext packets.
> Without the verification by public CAs
While there isn't much support in current client software, verification doesn't have to be from a CA. In an ideal world, your bank (or whomever) could hand out some sort of dongle (or maybe as a QR (or similar) code on a card?) that had a certificate that could be used for direct verification of their internet services independent of any CA, or in combination with CA verification.
What? What kind of browser would downgrade the request to HTTP?
Unfortunately this isn't particularly uncommon with corporate/school proxy, in-flight wi-fi services that forge certificates
Which require a cert signed by a CA already in the client's machine.
Regarding your specific example about loading Javascript referenced in an HTML document's <script> tag, the solution is to validate the data, not the server. The valid server can still send incorrect data. If you include hashes about a page's subresources[4], the browser can validate the integrity of the file it received.
If you don't have HTTPS, how can you be sure that the SRI hash wasn't tampered with?
Sorry, that should be the browser's local environment, not just the browser itself. An obvious example is sslstrip:
https://moxie.org/software/sslstrip/
> Which require a cert signed by a CA already in the client's machine.
Of course. That happens.
> If you don't have HTTPS, how can you be sure that the SRI hash wasn't tampered with?
Loading static resources from other domains is very common. Especially ad networks.
In the not too distant future, they will be, though perhaps not in the way you had in mind: HTTP sites will start showing similar indications of insecurity, just like sites with broken HTTPS.