A place to cache linked articles (think custom and personal wayback machine)
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.md 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. title: Plaintext HTTP in a Modern World
  2. url: https://jcs.org/2021/01/06/plaintext
  3. hash_url: 9e5d68c7459c77716c44dd1463be36d8
  4. <p>On the modern web, everything must be encrypted.
  5. Unencrypted websites are treated as relics of the past with browsers declaring
  6. them toxic waste not to be touched (or
  7. <a href="//blog.mozilla.org/security/2020/11/17/firefox-83-introduces-https-only-mode/">even looked at</a>)
  8. and search engines de-prioritizing their content.</p>
  9. <p>While this push for security is good for protecting modern communication, there
  10. is a whole web full of information and services that don’t <em>need</em> to be secured
  11. and those trying to access them from older vintage computers or even through
  12. modern embedded devices are increasingly being left behind.</p>
  13. <p class="alert">Note: This article is mostly directed at those serving personal websites, like
  14. this one, with no expectation of privacy or security by most readers of the
  15. content.
  16. If you are running a commercial website, collecting personal information from
  17. users, or transmitting sensitive data that users would expect to be done
  18. privately, disregard everything here and don’t bother offering your website over
  19. plaintext.</p>
  20. <h2 id="http-upgrading">HTTP Upgrading</h2>
  21. <p>Though it’s less common these days, users may still type in your website URL
  22. manually as opposed to clicking on a link that already includes the <code class="language-plaintext highlighter-rouge">https</code>
  23. scheme.
  24. (Imagine a user hearing your website mentioned on a podcast and they have to
  25. type it into their browser.)</p>
  26. <p>For a URL entered with an <code class="language-plaintext highlighter-rouge">http</code> scheme or, more commonly, no scheme specified,
  27. unless your domain is listed in the
  28. <a href="//www.chromium.org/hsts"><abbr title="Strict Transport Security">STS</abbr> preload list</a>
  29. of the user’s browser or they are using a plugin like
  30. <a href="//www.eff.org/https-everywhere">HTTPS Everywhere</a>, the browser will
  31. default to loading your website over plaintext HTTP.
  32. For this reason, even if your website is only served over HTTPS, it’s still
  33. necessary to configure your server to respond to plaintext HTTP requests with a
  34. 301 or 302 redirect to the HTTPS version of the URL.</p>
  35. <p>If your server is properly configured to send a <code class="language-plaintext highlighter-rouge">Strict-Transport-Security</code>
  36. header, once the user’s browser loads your website’s HTTPS version, the browser
  37. will cache that information for days or months and future attempts to load your
  38. site will default to the HTTPS scheme instead of HTTP even if the user manually
  39. types in an <code class="language-plaintext highlighter-rouge">http://</code> URL.</p>
  40. <h2 id="avoid-forced-upgrading-by-default">Avoid Forced Upgrading by Default</h2>
  41. <p>This forced redirection is a major cause of websites becoming inaccessible on
  42. vintage computers.
  43. Your server responds to the HTTP request with a 301 or 302 status and no
  44. content, and either a) the browser follows the redirection and tries to
  45. negotiate an SSL connection, but your server doesn’t offer legacy SSL versions
  46. or old ciphers so the negotiation fails, or b) the browser just doesn’t support
  47. SSL/TLS at all and fails to follow the redirection.</p>
  48. <p>A real-life example of this is that I recently purchased a Powerbook G4 and
  49. updated it to MacOS X 10.5.8 from 2009.
  50. It has a 1.5Ghz processor and 1.25Gb of RAM, and can connect to my modern WiFi
  51. network and use most of my USB peripherals.
  52. It includes a Mail client that can talk to my IMAP and SMTP servers, and a
  53. Safari web browser which can render fairly modern CSS layouts.
  54. However, it’s unable to view any content at all on Wikipedia simply because it
  55. can’t negotiate TLS 1.2 with the ciphers Wikipedia requires.
  56. Why is a decade-old computer too old to view encyclopedia articles?</p>
  57. <p>A solution to this problem is for websites to continue offering their full
  58. content over plaintext HTTP in addition to HTTPS.
  59. If you’re using Nginx, instead of creating two <code class="language-plaintext highlighter-rouge">server</code> blocks with the <code class="language-plaintext highlighter-rouge">listen
  60. *:80</code> version redirecting to the <code class="language-plaintext highlighter-rouge">listen *:443 ssl</code> version, use a single
  61. <code class="language-plaintext highlighter-rouge">server</code> block with multiple <code class="language-plaintext highlighter-rouge">listen</code> lines, like so:</p>
  62. <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>server {
  63. server_name jcs.org;
  64. listen *:80;
  65. listen *:443 ssl http2;
  66. ssl_certificate ...;
  67. ssl_certificate_key ...;
  68. ...
  69. ssl_protocols TLSv1.2;
  70. }
  71. </code></pre></div></div>
  72. <p>While it may seem counter to the point of this article, I recommend <strong>not</strong>
  73. serving legacy SSL/TLS ciphers like SSLv3 to try to help older browsers.
  74. These old protocols and ciphers are insecure and broken, and I feel it’s better
  75. to make it clear to the user they’re connecting to a website in cleartext than
  76. to offer a false sense of security by having the browser indicate a “secure
  77. connection” when it’s being done over an old, broken protocol.
  78. Also, while it may not be practical anymore, modern browsers might be
  79. <a href="//en.wikipedia.org/wiki/Downgrade_attack">tricked into negotiating</a>
  80. an old, broken cipher if your server still offers it.</p>
  81. <p>Even if you do offer legacy protocols and ciphers to older browsers, your TLS
  82. certificate might be signed by a certificate authority whose root certificate is
  83. not trusted by older browsers.</p>
  84. <h2 id="continue-upgrading-modern-browsers">Continue Upgrading Modern Browsers</h2>
  85. <p>Now that your entire website is being offered to legacy browsers over HTTP,
  86. modern browsers can still be directed to connect over HTTPS for added privacy by
  87. responding to the
  88. <a href="//developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests"><code class="language-plaintext highlighter-rouge">Upgrade-Insecure-Requests</code></a>
  89. header.
  90. This header is only sent by modern browsers that support
  91. <a href="//developer.mozilla.org/en-US/docs/Web/HTTP/CSP">CSP</a>
  92. when making an HTTP request, so it’s a reasonable indicator that the client is
  93. sufficiently modern and robust that it will be able to negotiate a TLS 1.2
  94. connection if redirected to your site’s HTTPS version.</p>
  95. <p>For Nginx, this can be done inside a <code class="language-plaintext highlighter-rouge">server</code> block by defining a variable
  96. per-request that includes whether it was made over plaintext HTTP and whether it
  97. included an <code class="language-plaintext highlighter-rouge">Upgrade-Insecure-Requests: 1</code> header:</p>
  98. <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>server {
  99. ...
  100. set $need_http_upgrade "$https$http_upgrade_insecure_requests";
  101. location / {
  102. if ($need_http_upgrade = "1") {
  103. add_header Vary Upgrade-Insecure-Requests;
  104. return 301 https://$host$request_uri;
  105. }
  106. ...
  107. }
  108. }
  109. </code></pre></div></div>
  110. <p>This <code class="language-plaintext highlighter-rouge">location</code> block will respond for any request and, for those made over
  111. plaintext HTTP where <code class="language-plaintext highlighter-rouge">$https</code> will be blank and which included an
  112. <code class="language-plaintext highlighter-rouge">Upgrade-Insecure-Requests: 1</code> header, they will be offered a 301 redirection to
  113. the HTTPS version.
  114. The <code class="language-plaintext highlighter-rouge">Vary</code> header is sent so that any caching proxies in the middle won’t cache
  115. the redirect.</p>
  116. <h2 id="content-concessions">Content Concessions</h2>
  117. <p>With legacy browsers now able to access your site, you may want to make some
  118. changes to your HTML and CSS to allow your site to render with some degree of
  119. readability.
  120. I don’t recommend giving it the full IE6 treatment catering to the lowest common
  121. denominator, but at least make the main text of your site readable.</p>
  122. <p>Obviously avoid JavaScript unless it is used progressively, though many older
  123. browsers raise error dialogs at the mere presence of modern JavaScript that
  124. can’t be parsed even if it’s never executed.</p>
  125. <p>Modern CSS and complex layouts can also be a problem even for browsers just a
  126. few years old, so it’s probably best to use them sparingly.
  127. For any <code class="language-plaintext highlighter-rouge">&lt;a&gt;</code> or <code class="language-plaintext highlighter-rouge">&lt;img&gt;</code> tags that are local to your site, use relative links to
  128. avoid specifying a particular scheme.</p>
  129. <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;a href="/posts/blah"&gt;
  130. &lt;img src="/images/..."&gt;
  131. &lt;/a&gt;
  132. </code></pre></div></div>
  133. <p>If you have to specify an absolute URL to another site that is also available
  134. over both HTTP and HTTPS, you can specify it without a scheme or colon and the
  135. browser will use the same <code class="language-plaintext highlighter-rouge">http:</code> or <code class="language-plaintext highlighter-rouge">https:</code> that the document is being viewed
  136. over:</p>
  137. <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;a href="//other.example.com/"&gt;My other site&lt;/a&gt;
  138. </code></pre></div></div>
  139. <h2 id="a-rant-about-gemini">A Rant About Gemini</h2>
  140. <p>Tangentially related,
  141. <a href="//gemini.circumlunar.space/">Gemini</a>
  142. is a modern document transfer protocol that aims to fit between the ancient
  143. <a href="//en.wikipedia.org/wiki/Gopher_(protocol)">Gopher</a>
  144. protocol and the too-modern HTTP web.
  145. Its document markup language is based on
  146. <a href="//en.wikipedia.org/wiki/Markdown">Markdown</a>
  147. so it’s very lightweight and simple to parse without complex HTML/CSS parsers.</p>
  148. <p>It sounds like the perfect thing to bring modern content to vintage computers,
  149. except that its
  150. <a href="//gemini.circumlunar.space/docs/specification.html">protocol</a>
  151. requires all content to be transferred over TLS 1.2 or higher which makes it
  152. nearly impossible to access from a vintage computer or even a modern embedded
  153. system with limited CPU power.</p>
  154. <p>This requirement seems poorly thought out, especially considering the Gemini
  155. protocol doesn’t even support forms (other than a single text box on a search
  156. form) so there’s no chance of users submitting private data, and there’s no
  157. mechanism for client-server sessions so clients can’t be authenticated, meaning
  158. everything served pretty much has to be public anyway.</p>
  159. <p>Its protocol author argues that TLS is just a simple dependency no different
  160. than a TCP server module, so it should be trivial to implement in any client or
  161. server.
  162. But if your computer’s CPU is so slow that a modern TLS negotiation would take
  163. so long as to be unusable, or its
  164. <a href="http://tenfourfox.blogspot.com/2018/02/the-tls-apocalypse-reaches-power-macs.html">platform doesn’t have a TLS 1.2 library</a>
  165. available, that makes it difficult to write a client without depending on an
  166. <a href="//github.com/jcs/sockhole">external system</a>
  167. [<a href="https://oldvcr.blogspot.com/2020/11/fun-with-crypto-ancienne-tls-for.html">2</a>].</p>
  168. <p>In my opinion, the protocol should <em>recommend</em> that servers offer both plaintext
  169. and TLS encrypted versions and <em>recommend</em> that clients prefer TLS, but <em>may</em>
  170. use plaintext if needed.
  171. Clients for modern operating systems can continue enforcing a TLS requirement so
  172. their users aren’t feeling any less secure.</p>
  173. <p>Perhaps just sending actual Markdown text over plaintext HTTP to clients that
  174. ask for it can be the new, old web.</p>
  175. <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Accept: text/markdown,text/plain;q=0.9,*/*;q=0.1
  176. </code></pre></div></div>
  177. <hr />
  178. <p><em>Please don’t contact me to “well ackchyually” me and explain
  179. <a href="/2011/08/17/a_man-in-the-middle_attack_in_the_wild">MITM attacks</a>
  180. and how your terrible ISP inserts ads into your unencrypted web pages and how
  181. you were able to make a Gemini client out of a whistle and some shoelaces.
  182. If you don’t want to make your website content available to stupid old
  183. computers, then don’t.</em></p>