<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Tom Moertel's Weblog: Tag capabilities</title>
    <link>http://blog.moertel.com/articles/tag/capabilities?tag=capabilities</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Quality rants on programming theory and stuff geeks like</description>
    <item>
      <title>A bright future: security and modern type systems</title>
      <description>&lt;p&gt;The &lt;a href="http://it.slashdot.org/it/07/08/12/1550254.shtml"&gt;recent defacement of the United Nations web
site&lt;/a&gt; is a prime
example of why we programmers shouldn&amp;#8217;t trust ourselves to write
secure code &amp;#8211; at least not without our computers&amp;#8217; help.  The U.N. web
site, according to Slashdot&amp;#8217;s coverage of the incident, was defaced by
way of a common, well-known attack: &lt;a href="http://en.wikipedia.org/wiki/SQL_injection"&gt;&lt;span class="caps"&gt;SQL&lt;/span&gt;
injection&lt;/a&gt;.  What&amp;#8217;s
interesting is that programmers can render this attack harmless by
employing simple, readily available programming tools such as
placeholders and prepared statements.  Why, then, are so many web sites,
including the UN site apparently, still vulnerable?&lt;/p&gt;


	&lt;p&gt;Some say it&amp;#8217;s because the programmers of these sites are incompetent,
but that argument ignores that programmers are
human, while the security tools we give them offer meaningful
protection only if wielded with inhuman perfection.  Having the tools
to plug security holes, even if the tools are simple to use and
readily available, is not enough to ensure that every single security
hole will be identified, let alone plugged.  Even the most experienced
programmer can be expected to overlook a hole now and then.
Unfortunately, one hole is all it takes.&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s because security is not like other software-quality challenges:
its costs are fundamentally asymmetric.  For the attacker, the bad
guy, the challenge is to find just a single exploitable hole.  For
us, the good guys, the challenge is to achieve perfection: to plug
&lt;em&gt;all&lt;/em&gt; of the holes in our code, every single one.  That&amp;#8217;s because
attackers, unlike regular users, can be expected to probe our code
until they find a hole to exploit.&lt;/p&gt;


	&lt;p&gt;How then do we ensure that we have plugged every single hole in our
code?  Testing isn&amp;#8217;t sufficient: we can easily overlook holes
when writing tests &amp;#8211; a perfectly human error.  We could supplement
testing with code reviews, painstakingly searching for remaining holes
while enforcing the use of hole-preventing best practices, but reviews
are expensive and, again, subject to human error.  A better approach,
both less costly and more reliable, is to delegate this burden to our
computers, which can do the job correctly, every single time.&lt;/p&gt;


	&lt;p&gt;This kind of delegation is possible today with modern static type systems.
For example, in &lt;a href="http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem"&gt;A Type-Based Solution to the Strings
Problem&lt;/a&gt;,
I offered a tiny &amp;#8220;safe strings&amp;#8221; library for the &lt;a href="http://haskell.org/"&gt;Haskell programming
language&lt;/a&gt;.  The library takes advantage of
Haskell&amp;#8217;s powerful type system to detect unsafe string interactions at
compile time. If we faithfully build our code on top of the library, and our
code compiles without error, we can be assured that our code is
free &amp;#8211; completely free &amp;#8211; of &lt;span class="caps"&gt;SQL&lt;/span&gt;-injection (and &lt;a href="http://en.wikipedia.org/wiki/Cross-site_scripting"&gt;&lt;span class="caps"&gt;XSS&lt;/span&gt;&lt;/a&gt;) holes.&lt;/p&gt;


	&lt;p&gt;While this result is indeed quite beautiful, it certainly isn&amp;#8217;t novel.
Researchers have been proving interesting
properties via type systems for a long time.  As Oleg Kiselyov and Chung-chieh Shan pointed out in &lt;a href="http://blog.moertel.com/articles/2006/10/18/a-type-based-solution-to-the-strings-problem#comment-204"&gt;a comment on my earlier article&lt;/a&gt;, the foundational idea is over three decades old.&lt;/p&gt;


	&lt;p&gt;More recently, Kiselyov and Shan have extended the
idea to guarantee more-interesting properties using a trusted kernel and types that represent
&lt;a href="http://okmij.org/ftp/papers/lightweight-static-capabilities.pdf"&gt;lightweight static
capabilities&lt;/a&gt;.
The kernel, which is small enough to be reasoned about and formally
verified, carefully hands out capabilities to untrusted application
code.  The untrusted code, in turn, presents the capabilities back to
the kernel to invoke operations, which, thanks to the kernel&amp;#8217;s
trustworthiness, are guaranteed to be safe.  (My safe-string library
can be seen as a trivial implementation of this programming style.)&lt;/p&gt;


	&lt;p&gt;When static type systems are used in this way, they don&amp;#8217;t merely catch
typos and bugs that good testing would have caught as a matter of
course, but offer programmers guarantees that would have been
impractical to obtain any other way.&lt;sup&gt;&lt;a href="#un-sql-fn1"&gt;1&lt;/a&gt;&lt;/sup&gt; If
you consider security important, you might bear this fact in mind when
choosing languages for your next project.&lt;/p&gt;


	&lt;p&gt;Going further, the security benefits of rich static type systems are only now
starting to trickle into mainstream industry.  As libraries like &amp;#8220;safe
strings&amp;#8221; and idioms like static capabilities become more familiar and
get woven into future generations of development frameworks, we can
expect marked improvements in the security and robustness of our
applications.&lt;/p&gt;


	&lt;p&gt;In the not-too-distant future, perhaps, we might look
back in amazement at the days when important security properties were
neither free nor guaranteed but expensive and uncertain, underwritten
only by the heroic efforts of individual programmers, struggling
against impossible odds to achieve inhuman perfection.&lt;/p&gt;


	&lt;p&gt;Then again, it sure took garbage collection a long time to catch on.&lt;/p&gt;


&lt;hr/&gt;

&lt;div class="footnote"&gt;

	&lt;p&gt;&lt;a name="un-sql-fn1"&gt;1.&lt;/a&gt; How, for example, could you eliminate the
possibility of &lt;span class="caps"&gt;SQL&lt;/span&gt;-injection and &lt;span class="caps"&gt;XSS&lt;/span&gt; holes via testing?&lt;/p&gt;


	&lt;p&gt;I suppose you could do it if you worked at
it hard enough. You could augment your string data
structures with run-time information about what they represent:
&lt;em&gt;this string represents &lt;span class="caps"&gt;SQL&lt;/span&gt;, this string represents plain-old
text&lt;/em&gt;, and so on.  Then you could redefine your string operations
and template interpolation systems to assert that their string inputs
were compatible.  Of course, if these assertions ever failed, they
would do so only at run time, when it would be too late to do anything
but die rather ungracefully.  So you would be forced to augment your
code-coverage tools to ensure that every string-path was covered
during testing.  That way you could catch all potential run-time
string failures &amp;#8211; indicating holes &amp;#8211; during testing and eliminate the
holes (and the subsequent need to fail at run time) before you
deployed your application for real.&lt;/p&gt;


	&lt;p&gt;So, yes, you could do it.  But to do so would require you, in effect,
to write a crude, single-purpose type system that checks types at test
time.  That says something, doesn&amp;#8217;t it?&lt;/p&gt;


&lt;/div&gt;</description>
      <pubDate>Wed, 15 Aug 2007 16:07:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fd522245-d8b7-4270-814d-5237a26bb0b9</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2007/08/15/a-bright-future-security-and-modern-type-systems</link>
      <category>programming</category>
      <category>web development</category>
      <category>security</category>
      <category>types</category>
      <category>security</category>
      <category>capabilities</category>
      <category>safestrings</category>
      <category>sqlinjection</category>
      <category>xss</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/524</trackback:ping>
    </item>
  </channel>
</rss>
