Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Added a document describing how to do a security audit. (CVS 673) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
cff271837796d84471b09147c59cb760 |
User & Date: | drh 2002-07-13 16:52:35.000 |
Context
2002-07-13
| ||
17:18 | Fix for ticket #99: Added documentation on the sqlite_mprintf() API. (CVS 674) (check-in: d918de5f06 user: drh tags: trunk) | |
16:52 | Added a document describing how to do a security audit. (CVS 673) (check-in: cff2718377 user: drh tags: trunk) | |
14:41 | Fix for ticket #54: Export additional APIs to the Win32 DLL. (CVS 672) (check-in: 072fd2ad58 user: drh tags: trunk) | |
Changes
Added www/audit.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | # # Run this Tcl script to generate the audit.html file. # set rcsid {$Id: audit.tcl,v 1.1 2002/07/13 16:52:35 drh Exp $} puts {<html> <head> <title>SQLite Security Audit Procedure</title> </head> <body bgcolor=white> <h1 align=center> SQLite Security Audit Procedure </h1>} puts "<p align=center> (This page was last modified on [lrange $rcsid 3 4] UTC) </p>" puts { <p> A security audit for SQLite consists of two components. First, there is a check for common errors that often lead to security problems. Second, an attempt is made to construct a proof that SQLite has certain desirable security properties. </p> <h2>Part I: Things to check</h2> <p> Scan all source code and check for the following common errors: </p> <ol> <li><p> Verify that the destination buffer is large enough to hold its result in every call to the following routines: <ul> <li> <b>strcpy()</b> </li> <li> <b>strncpy()</b> </li> <li> <b>strcat()</b> </li> <li> <b>memcpy()</b> </li> <li> <b>memset()</b> </li> <li> <b>memmove()</b> </li> <li> <b>bcopy()</b> </li> <li> <b>sprintf()</b> </li> <li> <b>scanf()</b> </li> </ul> </p></li> <li><p> Verify that pointers returned by subroutines are not NULL before using the pointers. In particular, make sure the return values for the following routines are checked before they are used: <ul> <li> <b>malloc()</b> </li> <li> <b>realloc()</b> </li> <li> <b>sqliteMalloc()</b> </li> <li> <b>sqliteRealloc()</b> </li> <li> <b>sqliteStrDup()</b> </li> <li> <b>sqliteStrNDup()</b> </li> <li> <b>sqliteExpr()</b> </li> <li> <b>sqliteExprFunction()</b> </li> <li> <b>sqliteExprListAppend()</b> </li> <li> <b>sqliteResultSetOfSelect()</b> </li> <li> <b>sqliteIdListAppend()</b> </li> <li> <b>sqliteSrcListAppend()</b> </li> <li> <b>sqliteSelectNew()</b> </li> <li> <b>sqliteTableNameToTable()</b> </li> <li> <b>sqliteTableTokenToSrcList()</b> </li> <li> <b>sqliteWhereBegin()</b> </li> <li> <b>sqliteFindTable()</b> </li> <li> <b>sqliteFindIndex()</b> </li> <li> <b>sqliteTableNameFromToken()</b> </li> <li> <b>sqliteGetVdbe()</b> </li> <li> <b>sqlite_mprintf()</b> </li> <li> <b>sqliteExprDup()</b> </li> <li> <b>sqliteExprListDup()</b> </li> <li> <b>sqliteSrcListDup()</b> </li> <li> <b>sqliteIdListDup()</b> </li> <li> <b>sqliteSelectDup()</b> </li> <li> <b>sqliteFindFunction()</b> </li> <li> <b>sqliteTriggerSelectStep()</b> </li> <li> <b>sqliteTriggerInsertStep()</b> </li> <li> <b>sqliteTriggerUpdateStep()</b> </li> <li> <b>sqliteTriggerDeleteStep()</b> </li> </ul> </p></li> <li><p> On all functions and procedures, verify that pointer parameters are not NULL before dereferencing those parameters. </p></li> <li><p> Check to make sure that temporary files are opened safely: that the process will not overwrite an existing file when opening the temp file and that another process is unable to substitute a file for the temp file being opened. </p></li> </ol> <h2>Part II: Things to prove</h2> <p> Prove that SQLite exhibits the characteristics outlined below: </p> <ol> <li><p> The following are preconditions:</p> <p><ul> <li><b>Z</b> is an arbitrary-length NUL-terminated string.</li> <li>An existing SQLite database has been opened. The return value from the call to <b>sqlite_open()</b> is stored in the variable <b>db</b>.</li> <li>The database contains at least one table of the form: <blockquote><pre> CREATE TABLE t1(a CLOB); </pre></blockquote></li> <li>There are no user-defined functions other than the standard build-in functions.</li> </ul></p> <p>The following statement of C code is executed:</p> <blockquote><pre> sqlite_exec_printf( db, "INSERT INTO t1(a) VALUES('%q');", 0, 0, 0, Z ); </pre></blockquote> <p>Prove the following are true for all possible values of string <b>Z</b>:</p> <ol type="a"> <li><p> The call to <b>sqlite_exec_printf()</b> will return in a length of time that is a polynomial in <b>strlen(Z)</b>. It might return an error code but it will not crash. </p></li> <li><p> At most one new row will be inserted into table t1. </p></li> <li><p> No preexisting rows of t1 will be deleted or modified. </p></li> <li><p> No tables other than t1 will be altered in any way. </p></li> <li><p> No preexisting files on the host computers filesystem, other than the database file itself, will be deleted or modified. </p></li> <li><p> For some constants <b>K1</b> and <b>K2</b>, if at least <b>K1*strlen(Z) + K2</b> bytes of contiguous memory are available to <b>malloc()</b>, then the call to <b>sqlite_exec_printf()</b> will not return SQLITE_NOMEM. </p></li> </ol> </p></li> <li><p> The following are preconditions: <p><ul> <li><b>Z</b> is an arbitrary-length NUL-terminated string.</li> <li>An existing SQLite database has been opened. The return value from the call to <b>sqlite_open()</b> is stored in the variable <b>db</b>.</li> <li>There exists a callback function <b>cb()</b> that appends all information passed in through its parameters into a single data buffer called <b>Y</b>.</li> <li>There are no user-defined functions other than the standard build-in functions.</li> </ul></p> <p>The following statement of C code is executed:</p> <blockquote><pre> sqlite_exec(db, Z, cb, 0, 0); </pre></blockquote> <p>Prove the following are true for all possible values of string <b>Z</b>:</p> <ol type="a"> <li><p> The call to <b>sqlite_exec()</b> will return in a length of time which is a polynomial in <b>strlen(Z)</b>. It might return an error code but it will not crash. </p></li> <li><p> After <b>sqlite_exec()</b> returns, the buffer <b>Y</b> will not contain any content from any preexisting file on the host computers file system, except for the database file. </p></li> <li><p> After the call to <b>sqlite_exec()</b> returns, the database file will still be well-formed. It might not contain the same data, but it will still be a properly constructed SQLite database file. </p></li> <li><p> No preexisting files on the host computers filesystem, other than the database file itself, will be deleted or modified. </p></li> <li><p> For some constants <b>K1</b> and <b>K2</b>, if at least <b>K1*strlen(Z) + K2</b> bytes of contiguous memory are available to <b>malloc()</b>, then the call to <b>sqlite_exec()</b> will not return SQLITE_NOMEM. </p></li> </ol> </p></li> </ol> } puts { <p><hr /></p> <p><a href="index.html"><img src="/goback.jpg" border=0 /> Back to the SQLite Home Page</a> </p> </body></html>} |