<?xml version="1.0"?>
<?xml-stylesheet href="/transform" type="text/xsl"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:bibo="http://purl.org/ontology/bibo/" xmlns:bs="http://purl.org/ontology/bibo/status/" xmlns:ci="https://vocab.methodandstructure.com/content-inventory#" xmlns:dct="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xhv="http://www.w3.org/1999/xhtml/vocab#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" lang="en" prefix="bibo: http://purl.org/ontology/bibo/ bs: http://purl.org/ontology/bibo/status/ ci: https://vocab.methodandstructure.com/content-inventory# dct: http://purl.org/dc/terms/ foaf: http://xmlns.com/foaf/0.1/ rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# xhv: http://www.w3.org/1999/xhtml/vocab# xsd: http://www.w3.org/2001/XMLSchema#" vocab="http://www.w3.org/1999/xhtml/vocab#" xml:lang="en">
  <head>
    <title property="dct:title">Something I'd Like to Do</title>
    <base href="https://doriantaylor.com/something-i-would-like-to-do"/>
    <link href="document-stats#E86TBnXnyKgMeDfX9oQkRK" rev="ci:document"/>
    <link href="elsewhere" rel="alternate bookmark" title="Elsewhere"/>
    <link href="this-site" rel="alternate index" title="This Site"/>
    <link href="http://purl.org/ontology/bibo/status/published" rel="bibo:status"/>
    <link href="" rel="ci:canonical" title="Something I'd Like to Do"/>
    <link href="lexicon/#EzqXIsriaILFcWjXdS7FbI" rel="dct:audience" title="Software Developer"/>
    <link href="person/dorian-taylor#me" rel="dct:creator" title="Dorian Taylor"/>
    <link href="http://www.w3.org/2005/Talks/0511-keynote-tbl/#%5B13%5D" rel="dct:references"/>
    <link href="person/dorian-taylor" rel="meta" title="Who I Am"/>
    <link about="./" href="3f36c30c-6096-454a-8a22-c062100ae41f" rel="alternate" type="application/atom+xml"/>
    <link about="./" href="f07f5044-01bc-472d-9079-9b07771b731c" rel="alternate" type="application/atom+xml"/>
    <link about="./" href="this-site" rel="alternate"/>
    <link about="./" href="elsewhere" rel="alternate"/>
    <link about="./" href="e341ca62-0387-4cea-b69a-cdabc7656871" rel="alternate" type="application/atom+xml"/>
    <link about="verso/" href="3f36c30c-6096-454a-8a22-c062100ae41f" rel="alternate" type="application/atom+xml"/>
    <link about="verso/" href="this-site" rel="alternate"/>
    <link about="verso/" href="elsewhere" rel="alternate"/>
    <meta content="something-i-would-like-to-do" datatype="xsd:token" property="ci:canonical-slug"/>
    <meta content="My roots in information security have long given me the &#x201C;no&#x201D; feeling when it comes to the increasing dependency on JavaScript to get basic things done on the Web. This is an idea to fix it." name="description" property="dct:abstract"/>
    <meta content="2012-03-28T22:18:33+00:00" datatype="xsd:dateTime" property="dct:created"/>
    <meta content="something-i-would-like-to-do" property="dct:identifier"/>
    <meta content="2012-03-28T22:21:47+00:00" datatype="xsd:dateTime" property="dct:issued"/>
    <meta content="2012-04-09T19:11:15+00:00" datatype="xsd:dateTime" property="dct:modified"/>
    <meta content="2022-05-31T04:18:52+00:00" datatype="xsd:dateTime" property="dct:modified"/>
    <meta content="2022-05-31T15:10:50+00:00" datatype="xsd:dateTime" property="dct:modified"/>
    <meta about="person/dorian-taylor#me" content="Dorian Taylor" name="author" property="foaf:name"/>
    <meta content="summary" name="twitter:card"/>
    <meta content="@doriantaylor" name="twitter:site"/>
    <meta content="Something I'd Like to Do" name="twitter:title"/>
    <meta content="My roots in information security have long given me the &#x201C;no&#x201D; feeling when it comes to the increasing dependency on JavaScript to get basic things done on the Web. This is an idea to fix it." name="twitter:description"/>
    <object>
      <nav>
        <ul>
          <li>
            <a href="document-stats#E86TBnXnyKgMeDfX9oQkRK" rev="ci:document" typeof="qb:Observation">
              <span>urn:uuid:f3a4c19d-79f2-42a0-a31e-0df5fda10911</span>
            </a>
          </li>
        </ul>
      </nav>
    </object>
  </head>
  <body about="" id="EgtwoCrYSYKqHSx5-UbsIL" typeof="bibo:Article">
    <p>I don't really <em>do</em> projects. I know it says <a href="projects/" title="Projects" rel="dct:references">projects</a> at the bottom of the screen but if you go there it's just a total head-fake. That's because what I typically do is more like agglomerates of little project-lings without the big contiguous membrane that makes a project what it is. <em>But</em>, I'm not averse to using the model when it fits. So what follows is a bona fide, almost scary-ambitious project I would like to take on in the not-too-distant future:</p>
    <section id="ECbgQZR0B3aYRYGWgEAN0I">
      <h2>Total-Functional Client-Side Web Scripting</h2>
      <p>This endeavour is to solve a problem that makes me genuinely angry: The increasing dependency on JavaScript for even the barest functionality on the Web. What makes it such an affront is that the site's owner is effectively coercing me into handing control of my device over to them and implicitly trusting them to behave. This is because JavaScript is <a href="http://en.wikipedia.org/wiki/Turing_completeness" title="Turing completeness &#x2014; Wikipedia" rel="dct:references">Turing-complete</a>, which <span class="parenthesis" title="I can put you in touch with a few">any antivirus researcher can tell you</span> is why they still have a job. It is a <a href="http://en.wikipedia.org/wiki/Halting_problem" title="Halting problem &#x2014; Wikipedia" rel="dct:references">mathematical impossibility</a> for the behaviour of Turing-complete code to be <a href="http://www.lel.ed.ac.uk/~gpullum/loopsnoop.html" title="Scooping the Loop Snooper &#x2014; Geoffrey K. Pullum" rel="dct:references">analyzed by machine</a>. What that means is that if your site depends on JavaScript to work, I have to either take your word that not only the behaviour of <em>your</em> code meets my approval, but that you have also secured it from anybody <em>else</em> adding malicious code of their own. That, or viewing your website means I have to pore over every line. Oh, and signing only certifies that the code <span class="parenthesis" title="Or rather, your KEY signed. That distinction is significant.">you signed</span> is the same code I got. It doesn't say anything about behaviour.</p>
      <p>Now, people will undoubtedly remind me that JavaScript is contained in a sandbox, and can't <span class="parenthesis" title="at least, until it actually does leap out of said sandbox, which happens often enough.">cause the same kind of damage a conventional virus can</span>. But the facet of JavaScript's behaviour I'm interested in preventing is in the family of cross-site scripting and request forgeries, wherein the code hooks your browser into doing things on other sites you're logged into without your knowledge or permission. There's a new one of those every other day, and they aren't going away anytime soon. And that's just malicious <em>third</em> parties exploiting sites with user-generated content. The site owners <em>themselves</em> can still do things like subject you to invasive behavioural analysis, or coerce you into sharing information with other parties. <span class="parenthesis" title="but I totally don't remember where ">I hear tell</span> that there's even a company that brokers distributed computing tasks, taking money on one end from customers and paying website owners on the other end to pass on to their users to execute for free. That is super-<em>super</em> lame.</p>
      <p>My concern here is as much political as it is about security. I can block cross-site scripting on my own just fine, but I can't say thanks-but-no-thanks to you turning my computer into a finger puppet. Moreover, if you link to JQuery, YUI or whatever Google's thing is, then you're making my relationship with <em>you</em> conditional on a relationship with <em>them</em>. What if for whatever reason I don't <em>want</em> to deal with them? My only options are whole hog or total boycott. And that just isn't satisfactory.</p>
      <p>The way to get what I want would be to look into the code before running it and selectively disable certain behaviour. Too bad the Turing-completeness of JavaScript makes any such analysis asymptotically approach worthless! But if we got rid of Turing-completeness, any code would be amenable to reliable, automated static analysis. Now, what would a non-Turing complete language look like?</p>
      <p>Turns out it would probably be <span class="parenthesis" title="Haskell. So hot right now. Haskell.">a lot like Haskell</span>. Or rather a lot like Miranda, Haskell's intellectual predecessor. How do I know this? Because <a href="http://www.eis.mdx.ac.uk/staffpages/dat/" title="David Turner homepage" rel="dct:references">the guy who wrote Miranda</a> also conceived <a href="http://en.wikipedia.org/wiki/Total_functional_programming" title="Total functional programming &#x2014; Wikipedia" rel="dct:references">total functional programming</a>, which has an expressive range that is <a href="http://en.wikipedia.org/wiki/Machine_that_always_halts" title="Machine that always halts &#x2014; Wikipedia" rel="dct:references">one meager rung below</a> Turing-complete. His name is David Turner, and I asked him about this idea. His response was <em>probably</em>, but I'd still have the problem of proving code correctness&#x2014;a perfectly legitimate concern.</p>
      <p>However, I'm not so much looking for what the code <em>does</em>, but rather what it <em>doesn't</em> do. What makes predicting the behaviour of Turing-complete code uncomputable is that the code is expressive enough to rewrite its own semantics. It could be as straight-forward as having a function like <code>eval</code>, which takes a string and executes it in situ. If one of those is present, all bets are off.</p>
      <p>But scanning over a length of total-functional language, if I understand correctly, we would be able to tell with certitude if it does or does not execute certain behaviour. That's why a total-functional client-side Web scripting language makes so much sense. If we were particularly concerned about the site absconding with data, or creepy behavioural tracking, or running a <a href="http://en.wikipedia.org/wiki/MapReduce" title="MapReduce &#x2014; Wikipedia" rel="dct:references">MapReduce</a> job, or whatever, we <em>should</em> be able to spot it up front and disable it.</p>
      <p>Do people even see a need for something like this? I sure do. Apparently <a href="http://www.w3.org/2005/Talks/0511-keynote-tbl/#%5B13%5D" title="Berners-Lee - WWW2005 Keynote [13]" rel="dct:references">so does Tim Berners-Lee</a>, who, you know, kinda invented the whole shebang. Web developers would be happy to use it because functional programming is more succinct than imperative, and because functional languages like Haskell are <a href="http://www.youtube.com/watch?v=CV_hDyfmEw4" rel="dct:references"><em>so</em> hot right now</a>. There is also a <acronym title="Public Relations">PR</acronym> halo effect from being able to say your code doesn't pull any dirty tricks, and that there's no need to take your word for it.</p>
      <p>The million-dollar question is, of course, how much of the everyday client-side scripting tasks genuinely depend on the full range of JavaScript's linguistic expressivity? That would have to be tested, but my gut says virtually none of them. In the <span class="parenthesis" title="holy crap that sounds weird to say">15 years</span> I've been using JavaScript, I don't think I've once written anything crazier than completely deterministic <acronym title="Document Object Model">DOM</acronym>-schlepping. That could be replaced easily with a total-functional language, in fact it could be replaced with something even <em>more</em> restrictive.</p>
      <p>The next big question is how computationally expensive would the code analysis be? If it's cheap, it could be done &#xE0; la carte, but if it's costly, we'd have to figure out some sort of resource pooling, some interchange format for the proofs (which would probably be useful anyway), and some sort of crypto signature thingy (of which there are plenty, it's just a matter of ironing out the details). The predicates themselves&#x2014;the questions <em>does this code do only this or that</em>&#x2014;should also be shareable just like ad-blocking profiles are today.</p>
      <p>But the point is, this is totally doable. The theory is sound, there's high-profile demand for it, and one could <span class="parenthesis" title="This is a BIG &quot;just&quot;.">just</span> write the reference implementation as a patch against both WebKit and Gecko, obviating any excuses not to immediately put it into no fewer than three major browsers right off the bat. So, <a href="javascript:sendMail('gmail.com',%20'dorian.taylor',%20'yo%20dawg%20i%20herd%20u%20like%20TFP');" rel="dct:references">who's with me</a>?</p>
      <aside role="note" id="EfcoOrdLFa5B6R-kpQyAnJ">
        <p>Note: I'm not suggesting <em>replacing</em> JavaScript outright, but rather complementing it. In fact, it would be useful to start out with some sort of <a href="http://coffeescript.org/" title="CoffeeScript" rel="dct:references">CoffeeScript</a>-style quasi-compiler that produced JavaScript. This would enable the development of a prototype and test harness. Likewise, the proving engine would take the <acronym title="Total Functional Programming">TFP</acronym> source as input. Once all of that is sorted out, we could move to a native engine that would live in the browser alongside the JavaScript one, which would be triggered by a MIME type, just like Microsoft did with VBScript.</p>
      </aside>
    </section>
  </body>
</html>
