title: Safe read-only sqlite3 database
body: <p>I want to give my website users arbitrary read-only access to an
  SQLite3 database, without letting them write to the database or do any
  other damage. How?</p>
  
  <p>Making the db file read-only helps a little, but commands like
  "ATTACH", ".load" and ".output" allow people to read/write other
  files, which may not be protected.</p>
  
  <p>Of course, if I knew all such commands, I'd just filter against them,
  but I'm mostly worried about commands I haven't thought of.</p>
  
  <p>I tried briefly to alter sqlite3's source code to disallow writes, but
  this is harder than it looks: even the SELECT statement appears to do
  some internal INSERTS/etc.</p>
  
  <p><strong>Note :</strong> <em>I've considered DOS attacks, and will ulimit cputime to 5s or
  something. My main concern is damage to files/"hacking", not DOS.</em></p>
  
  <p>chroot() may work, but seems extreme.</p>
  
  <p>Thoughts?</p>
  
  <p><strong>EDIT :</strong> Wow, did I really ask this 3+ years ago? </p>
  
  <p>Since then, <a href="https://github.com/barrycarter/bcapps/blob/master/bc-run-sqlite3-query2.pl" rel="nofollow noreferrer">I've actually written a program to do this.</a></p>
  
  <p>which I think is reasonably secure (but I could be wrong). </p>
  
  <p><a href="http://4c6747383f0418dce674932beeefbf87.metarnew.db.bcinfo3.barrycarter.info/" rel="nofollow noreferrer">Here is a sample query.</a></p>