taler-merchant-demos

Python-based Frontends for the Demonstration Web site
Log | Files | Refs | Submodules | README | LICENSE

javascript-trap.html (15482B)


      1 <!--#include virtual="/server/header.html" -->
      2 <!-- Parent-Version: 1.96 -->
      3 <!-- This page is derived from /server/standards/boilerplate.html -->
      4 <!--#set var="TAGS" value="essays licensing traps" -->
      5 <!--#set var="DISABLE_TOP_ADDENDUM" value="yes" -->
      6 <title>The JavaScript Trap - GNU Project - Free Software Foundation</title>
      7 <!--#include virtual="/philosophy/po/javascript-trap.translist" -->
      8 <!--#include virtual="/server/banner.html" -->
      9 <!--#include virtual="/philosophy/ph-breadcrumb.html" -->
     10 <!--GNUN: OUT-OF-DATE NOTICE-->
     11 <!--#include virtual="/server/top-addendum.html" -->
     12 <div class="article reduced-width">
     13 <h2>The JavaScript Trap</h2>
     14 
     15 <address class="byline">by <a href="https://www.stallman.org/">Richard
     16 Stallman</a></address>
     17 
     18 <p><strong>You may be running nonfree programs on your computer every
     19 day without realizing it&mdash;through your web browser.</strong></p>
     20 
     21 <!-- any links that used to point to the appendices should point to
     22      free-your-javascript.html instead.  -->
     23 
     24 <div class="announcement">
     25 <hr class="no-display" />
     26 <p>Webmasters: there are
     27 <a href="/software/librejs/free-your-javascript.html">several ways</a>
     28 to indicate the license of JavaScript programs in a web site.</p>
     29 <hr class="no-display" />
     30 </div>
     31 
     32 <p>In the free software community, the idea that
     33 <a href="/philosophy/free-software-even-more-important.html">
     34 any nonfree program mistreats its users</a> is familiar.  Some of us
     35 defend our freedom by rejecting all proprietary software on our
     36 computers.  Many others recognize nonfreeness as a strike against the
     37 program.</p>
     38 
     39 <p>Many users are aware that this issue applies to the plug-ins that
     40 browsers offer to install, since they can be free or nonfree.  But
     41 browsers run other nonfree programs which they don't ask you about, or
     42 even tell you about&mdash;programs that web pages contain or link to.
     43 These programs are most often written in JavaScript, though other
     44 languages are also used.</p>
     45 
     46 <p>JavaScript (officially called ECMAScript, but few use that name)
     47 was once used for minor frills in web pages, such as cute but
     48 inessential navigation and display features.  It was acceptable to
     49 consider these as mere extensions of HTML markup, rather than as true
     50 software, and disregard the issue.</p>
     51 
     52 <p>Some sites still use JavaScript that way, but many use it for major
     53 programs that do large jobs.  For instance, Google Docs tries to
     54 install into your browser a JavaScript program which measures half a
     55 megabyte, in a compacted form that we could call Obfuscript.  This
     56 compacted form is made from the source code, by deleting the extra
     57 spaces that make the code readable and the explanatory remarks that
     58 make it comprehensible, and replacing each meaningful name in the code
     59 with an arbitrary short name so we can't tell what it is supposed to
     60 mean.</p>
     61 
     62 <p>Part of the <a href="/philosophy/free-sw.html">meaning of free
     63 software</a> is that users have access to the program's source code
     64 (its plan).  The source code of a program means the preferred form for
     65 programmers to modify&mdash;including helpful spacing, explanatory
     66 remarks, and meaningful names.  Compacted code is a bogus, useless
     67 substitute for source code; the real source code of these programs is
     68 not available to the users, so users cannot understand it; therefore
     69 the programs are nonfree.</p>
     70 
     71 <p>In addition to being nonfree, many of these programs
     72 are <em>malware</em> because
     73 they <a href="https://github.com/w3c/fingerprinting-guidance/issues/8">snoop
     74 on the user</a>.  Even nastier, some sites use services which record
     75 <a href="https://freedom-to-tinker.com/2017/11/15/no-boundaries-exfiltration-of-personal-data-by-session-replay-scripts/">all
     76 the user's actions while looking at the page</a>.  The services
     77 supposedly &ldquo;redact&rdquo; the recordings to exclude some
     78 sensitive data that the web site shouldn't get.  But even if that
     79 works reliably, the whole purpose of these services is to give the web
     80 site other personal data that it shouldn't get.</p>
     81 
     82 <p>Browsers don't normally tell you when they load JavaScript
     83 programs.  Some browsers have a way to turn off JavaScript entirely,
     84 but even if you're aware of this issue, it would take you considerable
     85 trouble to identify the nontrivial nonfree programs and block them.
     86 However, even in the free software community most users are not aware
     87 of this issue; the browsers' silence tends to conceal it.</p>
     88 
     89 <p>To be clear, the language JavaScript is not inherently better or worse 
     90 for users' freedom than any other language.
     91 It is possible to release a JavaScript program as free software, by
     92 distributing the source code under a free software license.  If the
     93 program is self-contained&mdash;if its functioning and purpose are
     94 independent of the page it came in&mdash;that is fine; you can copy it
     95 to a file on your machine, modify it, and visit that file with a
     96 browser to run it.  It's even possible to package it for installation
     97 just like other free programs and invocation with a shell command.
     98 These programs present no special moral issue different from those
     99 of C programs.</p>
    100 
    101 <p>The issue of the JavaScript trap applies when the JavaScript
    102 program comes along with a web page that users visit.
    103 Those JavaScript programs are written to work with a
    104 particular page or site, and the page or site depends on them to
    105 function.</p>
    106 
    107 <p>Suppose you copy and modify the page's JavaScript code.
    108 Then another problem arises: even if the program's source
    109 is available, browsers do not offer a way to run your modified version
    110 instead of the original when visiting that page or site.  The effect
    111 is comparable to tivoization, although in principle not quite so hard
    112 to overcome.</p>
    113 
    114 <p>JavaScript is not the only language web sites use for programs sent
    115 to the user.  Flash supported programming through an extended variant
    116 of JavaScript, but that is a thing of the past.  Microsoft Silverlight
    117 seems likely to create a problem similar to Flash, except worse, since
    118 Microsoft uses it as a platform for nonfree codecs.  A free
    119 replacement for Silverlight does not do the job adequately for the
    120 free world unless it normally comes with free replacement codecs.</p>
    121 
    122 <p>Java applets also run in the browser, and raise similar issues.  In
    123 general, any sort of applet system poses this sort of problem.  Having
    124 a free execution environment for an applet only brings us far enough
    125 to encounter the problem.</p>
    126 
    127 <p>It is theoretically possible to program in HTML and CSS, but in
    128 practice this capability is limited and inconvenient; merely to make
    129 it do something is an impressive hack.  Such programs ought to be
    130 free, but CSS is not a serious problem for users' freedom as of
    131 2019.</p>
    132 
    133 <p>A strong movement has developed that calls for web sites to
    134 communicate only through formats and protocols that are free (some say
    135 &ldquo;open&rdquo;); that is to say, whose documentation is published and which
    136 anyone is free to implement.  However, the presence of JavaScript programs
    137 in web pages makes that criterion insufficient.  The JavaScript language
    138 itself, as a format, is free, and use of JavaScript in a web site is
    139 not necessarily bad.  However, as we've seen above, it can be bad&mdash;if
    140 the JavaScript program is nonfree.  When the site transmits a program
    141 to the user, it is
    142 not enough for the program to be written in a documented and
    143 unencumbered language; that program must be free, too.  &ldquo;Transmits only free
    144 programs to the user&rdquo; must become part of the criterion
    145 for an ethical web site.</p>
    146 
    147 <p>Silently loading and running nonfree programs is one among several
    148 issues raised by &ldquo;web applications.&rdquo;  The term &ldquo;web
    149 application&rdquo; was designed to disregard the fundamental
    150 distinction between software delivered to users and software running
    151 on a server.  It can refer to a specialized client program running
    152 in a browser; it can refer to specialized server software; it can
    153 refer to a specialized client program that works hand in hand with
    154 specialized server software.  The client and server sides raise
    155 different ethical issues, even if they are so closely integrated that
    156 they arguably form parts of a single program.  This article addresses
    157 only the issue of the client-side software.  We are addressing the
    158 server issue separately.</p>
    159 
    160 <p>In practical terms, how can we deal with the problem of nontrivial nonfree
    161 JavaScript programs in web sites?  The first step is to avoid running
    162 it.</p>
    163 
    164 <p>What do we mean by &ldquo;nontrivial&rdquo;?  It is a matter of
    165 degree, so this is a matter of designing a simple criterion that gives
    166 good results, rather than finding the one correct answer.</p>
    167 <p>
    168 Our current criterion is to consider a JavaScript program nontrivial
    169 if any of these conditions is met:</p>
    170 
    171 <ul>
    172   <li>it is referred to as an external script (from another page).</li>
    173 
    174   <li>it declares an array more than 50 elements long.</li>
    175 
    176   <li>it defines a named entity (function or method) that calls anything other
    177       than a primitive.</li>
    178 
    179   <li>it defines a named entity with more than three conditional
    180       constructs and loop construction.</li>
    181 
    182   <li>code outside of named definitions calls anything but primitives and
    183       functions defined further up in the page.</li>
    184 
    185   <li>code outside of named definitions contains more than three
    186       conditional constructs and loop construction, total.</li>
    187 
    188   <li>it calls <b>eval</b>.</li>
    189 
    190   <li>it does Ajax calls.</li>
    191 
    192   <li>it uses bracket notation for dynamic object property access,
    193 which looks like <b><em>object</em>[<em>property</em>]</b>.</li>
    194 
    195   <li>it alters the DOM.</li>
    196   
    197   <li>it uses dynamic JavaScript constructs that are difficult to
    198     analyze without interpreting the program, or is loaded along with
    199     scripts that use such constructs.  Specifically, using any other
    200     construct than a string literal with certain methods
    201     (<b>Obj.write</b>, <b>Obj.createElement</b>, and others).</li>
    202 </ul>
    203 
    204 <p>How do we tell whether the JavaScript code is free?  In a <a 
    205 href="/licenses/javascript-labels.html">separate article</a>,
    206 we propose a method by which a nontrivial JavaScript
    207 program in a web page can state the URL where its source code is
    208 located, and can state its license too, using stylized comments.</p>
    209 
    210 <p>Finally, we need to change free browsers to detect and block
    211 nontrivial nonfree JavaScript in web pages.  The program
    212 <a href="/software/librejs/">LibreJS</a> detects nonfree,
    213 nontrivial JavaScript in pages you visit, and blocks it.  LibreJS is
    214 included in IceCat, and available as an add-on for Firefox.</p>
    215 
    216 <p>Browser users also need a convenient facility to specify JavaScript
    217 code to use <em>instead</em> of the JavaScript in a certain page.
    218 (The specified code might be total replacement, or a modified version
    219 of the free JavaScript program in that page.)  Greasemonkey comes close
    220 to being able to do this, but not quite, since it doesn't guarantee to
    221 modify the JavaScript code in a page before that program starts to
    222 execute.  Using a local proxy works, but is too inconvenient now to be
    223 a real solution.  We need to construct a solution that is reliable and
    224 convenient, as well as sites for sharing changes.  The GNU Project
    225 would like to recommend sites which are dedicated to free changes
    226 only.</p>
    227 
    228 <p>These features will make it possible for a JavaScript program included
    229 in a web page to be free in a real and practical sense.  JavaScript
    230 will no longer be a particular obstacle to our freedom&mdash;no more than
    231 C and Java are now.  We will be able to reject and even replace the
    232 nonfree nontrivial JavaScript programs, just as we reject and replace
    233 nonfree packages that are offered for installation in the usual way.
    234 Our campaign for web sites to free their JavaScript can then begin.</p>
    235 
    236 <p>In the mean time, there's one case where it is acceptable to run a
    237 nonfree JavaScript program: to send a complaint to the website
    238 operators saying they should free or remove the JavaScript code in the
    239 site.  Please don't hesitate to enable JavaScript temporarily to do
    240 that&mdash;but remember to disable it again afterwards.</p>
    241 
    242 <!-- any links that used to point to the appendices should point to
    243      free-your-javascript.html instead.  -->
    244 
    245 <div class="announcement">
    246 <hr class="no-display" />
    247 <p>Webmasters: there are
    248 <a href="/software/librejs/free-your-javascript.html">several ways</a>
    249 to indicate the license of JavaScript programs in a web site.</p>
    250 <hr class="no-display" />
    251 </div>
    252 
    253 <p><strong>Acknowledgements:</strong> I thank <a href="/people/people.html#mattlee">Matt Lee</a>
    254 and <a href="https://johnresig.com/">John Resig</a> for their help in
    255 defining our proposed criterion, and David Parunakian for
    256 bringing the problem to my attention.</p>
    257 </div>
    258 
    259 </div><!-- for id="content", starts in the include above -->
    260 <!--#include virtual="/server/footer.html" -->
    261 <div id="footer" role="contentinfo">
    262 <div class="unprintable">
    263 
    264 <p>Please send general FSF &amp; GNU inquiries to
    265 <a href="mailto:gnu@gnu.org">&lt;gnu@gnu.org&gt;</a>.
    266 There are also <a href="/contact/">other ways to contact</a>
    267 the FSF.  Broken links and other corrections or suggestions can be sent
    268 to <a href="mailto:webmasters@gnu.org">&lt;webmasters@gnu.org&gt;</a>.</p>
    269 
    270 <p><!-- TRANSLATORS: Ignore the original text in this paragraph,
    271         replace it with the translation of these two:
    272 
    273         We work hard and do our best to provide accurate, good quality
    274         translations.  However, we are not exempt from imperfection.
    275         Please send your comments and general suggestions in this regard
    276         to <a href="mailto:web-translators@gnu.org">
    277         &lt;web-translators@gnu.org&gt;</a>.</p>
    278 
    279         <p>For information on coordinating and contributing translations of
    280         our web pages, see <a
    281         href="/server/standards/README.translations.html">Translations
    282         README</a>. -->
    283 Please see the <a
    284 href="/server/standards/README.translations.html">Translations
    285 README</a> for information on coordinating and contributing translations
    286 of this article.</p>
    287 </div>
    288 
    289 <!-- Regarding copyright, in general, standalone pages (as opposed to
    290      files generated as part of manuals) on the GNU web server should
    291      be under CC BY-ND 4.0.  Please do NOT change or remove this
    292      without talking with the webmasters or licensing team first.
    293      Please make sure the copyright date is consistent with the
    294      document.  For web pages, it is ok to list just the latest year the
    295      document was modified, or published.
    296      
    297      If you wish to list earlier years, that is ok too.
    298      Either "2001, 2002, 2003" or "2001-2003" are ok for specifying
    299      years, as long as each year in the range is in fact a copyrightable
    300      year, i.e., a year in which the document was published (including
    301      being publicly visible on the web or in a revision control system).
    302      
    303      There is more detail about copyright years in the GNU Maintainers
    304      Information document, www.gnu.org/prep/maintain. -->
    305 
    306 <p>Copyright &copy; 2009-2013, 2016-2019, 2021 Richard Stallman</p>
    307 
    308 <p>This page is licensed under a <a rel="license"
    309 href="http://creativecommons.org/licenses/by-nd/4.0/">Creative
    310 Commons Attribution-NoDerivatives 4.0 International License</a>.</p>
    311 
    312 <!--#include virtual="/server/bottom-notes.html" -->
    313 
    314 <p class="unprintable">Updated:
    315 <!-- timestamp start -->
    316 $Date: 2021/10/11 08:59:13 $
    317 <!-- timestamp end -->
    318 </p>
    319 </div>
    320 </div><!-- for class="inner", starts in the banner include -->
    321 </body>
    322 </html>