| 1 |
<?xml version="1.0" ?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 |
<head> |
| 5 |
<title>DBIx::Safe - Safer access to your database through a DBI database handle</title> |
| 6 |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
| 7 |
|
| 8 |
</head> |
| 9 |
|
| 10 |
<body style="background-color: white"> |
| 11 |
|
| 12 |
<p><a name="__index__"></a></p> |
| 13 |
<!-- INDEX BEGIN --> |
| 14 |
|
| 15 |
<ul> |
| 16 |
|
| 17 |
<li><a href="#name">NAME</a></li> |
| 18 |
<li><a href="#version">VERSION</a></li> |
| 19 |
<li><a href="#synopsis">SYNOPSIS</a></li> |
| 20 |
<li><a href="#description">DESCRIPTION</a></li> |
| 21 |
<ul> |
| 22 |
|
| 23 |
<li><a href="#deciding_what_statements_to_allow">Deciding what statements to allow</a></li> |
| 24 |
<li><a href="#deciding_what_attributes_to_allow">Deciding what attributes to allow</a></li> |
| 25 |
<li><a href="#methods">Methods</a></li> |
| 26 |
<ul> |
| 27 |
|
| 28 |
<li><a href="#new__"><code>new()</code></a></li> |
| 29 |
<li><a href="#allow_command__"><code>allow_command()</code></a></li> |
| 30 |
<li><a href="#unallow_command__"><code>unallow_command()</code></a></li> |
| 31 |
<li><a href="#allow_regex__"><code>allow_regex()</code></a></li> |
| 32 |
<li><a href="#unallow_regex__"><code>unallow_regex()</code></a></li> |
| 33 |
<li><a href="#deny_regex__"><code>deny_regex()</code></a></li> |
| 34 |
<li><a href="#undeny_regex__">undeny <code>regex()</code></a></li> |
| 35 |
<li><a href="#allow_attribute__"><code>allow_attribute()</code></a></li> |
| 36 |
<li><a href="#unallow_attribute__"><code>unallow_attribute()</code></a></li> |
| 37 |
</ul> |
| 38 |
|
| 39 |
<li><a href="#testing">Testing</a></li> |
| 40 |
<li><a href="#supported_databases">Supported Databases</a></li> |
| 41 |
</ul> |
| 42 |
|
| 43 |
<li><a href="#website">WEBSITE</a></li> |
| 44 |
<li><a href="#development">DEVELOPMENT</a></li> |
| 45 |
<li><a href="#bugs">BUGS</a></li> |
| 46 |
<li><a href="#author">AUTHOR</a></li> |
| 47 |
<li><a href="#license_and_copyright">LICENSE AND COPYRIGHT</a></li> |
| 48 |
</ul> |
| 49 |
<!-- INDEX END --> |
| 50 |
|
| 51 |
<hr /> |
| 52 |
<p> |
| 53 |
</p> |
| 54 |
<hr /> |
| 55 |
<h1><a name="name">NAME</a></h1> |
| 56 |
<p>DBIx::Safe - Safer access to your database through a DBI database handle</p> |
| 57 |
<p> |
| 58 |
</p> |
| 59 |
<hr /> |
| 60 |
<h1><a name="version">VERSION</a></h1> |
| 61 |
<p>This documents version 1.2.5 of the DBIx::Safe module</p> |
| 62 |
<p> |
| 63 |
</p> |
| 64 |
<hr /> |
| 65 |
<h1><a name="synopsis">SYNOPSIS</a></h1> |
| 66 |
<pre> |
| 67 |
use DBIx::Safe;</pre> |
| 68 |
<pre> |
| 69 |
$dbh = DBI->connect($dbn, $user, $pass, {AutoCommit => 0});</pre> |
| 70 |
<pre> |
| 71 |
my $safedbh = DBIx::Safe->new({ dbh => $dbh });</pre> |
| 72 |
<pre> |
| 73 |
$safedbh->allow_command('SELECT INSERT UPDATE');</pre> |
| 74 |
<pre> |
| 75 |
$safedbh->allow_regex(qr{LOCK TABLE \w+ IN EXCLUSIVE MODE});</pre> |
| 76 |
<pre> |
| 77 |
$safedbh->deny_regex(qr{LOCK TABLE pg_});</pre> |
| 78 |
<pre> |
| 79 |
$safedbh->allow_attribute('PrintError RaiseError');</pre> |
| 80 |
<p> |
| 81 |
</p> |
| 82 |
<hr /> |
| 83 |
<h1><a name="description">DESCRIPTION</a></h1> |
| 84 |
<p>The purpose of this module is to give controlled, limited access to an application, |
| 85 |
rather than simply passing it a raw database handle through DBI. DBIx::Safe acts as |
| 86 |
a wrapper to the database, by only allowing through the commands you tell it to. It |
| 87 |
filters all things related to the database handle - methods and attributes.</p> |
| 88 |
<p>The typical usage is for your application to create a database handle via a normal |
| 89 |
DBI call to new(), then pass that to DBIx::Safe->new(), which will return you a |
| 90 |
DBIx::Safe object. After specifying exactly what is and what is not allowed, you can |
| 91 |
pass the object to the untrusted application. The object will act very similar to a |
| 92 |
DBI database handle, and in most cases can be used interchangeably.</p> |
| 93 |
<p>By default, nothing is allowed to run at all. There are many things you can control. |
| 94 |
You can specify which SQL commands are allowed, by indicating the first word in the |
| 95 |
SQL statement (e.g. 'SELECT'). You can specify which database methods are allowed to |
| 96 |
run (e.g. 'ping'). You can specify a regular expression that allows matching SQL |
| 97 |
statements to run (e.g. 'qr{SET TIMEZONE}'). You can specify a regular expression |
| 98 |
that is NOT allowed to run (e.g. qr(UPDATE xxx}). Finally, you can indicate which |
| 99 |
database attributes are allowed to be read and changed (e.g. 'PrintError'). For all |
| 100 |
of the above, there are matching methods to remove them as well.</p> |
| 101 |
<p> |
| 102 |
</p> |
| 103 |
<h2><a name="deciding_what_statements_to_allow">Deciding what statements to allow</a></h2> |
| 104 |
<p>Anytime a statement is sent to the server via the DBIx::Safe database handle, it is first |
| 105 |
examined to see if it is allowed to run or not. There are three major checks that occur |
| 106 |
when a statement is sent. First, the initial word of the statement, known as the command, |
| 107 |
is extracted. Next, the entire statement is checked against the list of denied regular expressions. |
| 108 |
Next, the command is checked against the list of allowed commands. If there is no match, |
| 109 |
the statement is checked against the list of allowed regular expressions.</p> |
| 110 |
<p>Each DBD may implement additional or slightly different checks. For example, if using |
| 111 |
Postgres, no semi-colons are allowed unless the command is one of SELECT, INSERT, |
| 112 |
UPDATE, or DELETE, to prevent multiple commands from running. (The four listed commands |
| 113 |
can be checked in another way for multiple commands, so they are allowed to have |
| 114 |
semicolons).</p> |
| 115 |
<p> |
| 116 |
</p> |
| 117 |
<h2><a name="deciding_what_attributes_to_allow">Deciding what attributes to allow</a></h2> |
| 118 |
<p>Database handle attributes are controlled by a single list of allowed keys. If the |
| 119 |
key is allowed, the underlying database handle value is returned or changed (or both). |
| 120 |
Note that the attribute ``AutoCommit'' is never allowed to be changed.</p> |
| 121 |
<p> |
| 122 |
</p> |
| 123 |
<h2><a name="methods">Methods</a></h2> |
| 124 |
<p> |
| 125 |
</p> |
| 126 |
<h3><a name="new__"><code>new()</code></a></h3> |
| 127 |
<p>Creates a new DBIx::Safe object. Requires a mandatory ``dbh'' argument containing an active database |
| 128 |
handle. Optional arguments are ``allow_command'', ``allow_regex'', ``deny_regex'', and ``allow_attribute''.</p> |
| 129 |
<p> |
| 130 |
</p> |
| 131 |
<h3><a name="allow_command__"><code>allow_command()</code></a></h3> |
| 132 |
<p>Specifies which commands are allowed to be used. Can be a whitespace-separated list of words in a string, |
| 133 |
or an arrayref of such strings. Returns the current list of allowed commands. Duplicate commands will |
| 134 |
throw an error.</p> |
| 135 |
<p> |
| 136 |
</p> |
| 137 |
<h3><a name="unallow_command__"><code>unallow_command()</code></a></h3> |
| 138 |
<p>Same as allow_command, but will remove words from the list.</p> |
| 139 |
<p> |
| 140 |
</p> |
| 141 |
<h3><a name="allow_regex__"><code>allow_regex()</code></a></h3> |
| 142 |
<p>Specifies regular expressions which are allowed to run. Argument must be a regular expression, |
| 143 |
or an arrayref of regular expressions. Returns the current list.</p> |
| 144 |
<p> |
| 145 |
</p> |
| 146 |
<h3><a name="unallow_regex__"><code>unallow_regex()</code></a></h3> |
| 147 |
<p>Same as allow_regex, but will remove regexes from the list.</p> |
| 148 |
<p> |
| 149 |
</p> |
| 150 |
<h3><a name="deny_regex__"><code>deny_regex()</code></a></h3> |
| 151 |
<p>Specifies regular expressions which are NOT allowed to run. Arguments and return the same as allow_regex().</p> |
| 152 |
<p> |
| 153 |
</p> |
| 154 |
<h3><a name="undeny_regex__">undeny <code>regex()</code></a></h3> |
| 155 |
<p>Same as deny_regex, but will remove regexes from the list.</p> |
| 156 |
<p> |
| 157 |
</p> |
| 158 |
<h3><a name="allow_attribute__"><code>allow_attribute()</code></a></h3> |
| 159 |
<p>Specifies database handle attributes that are allowed to be changed. By default, nothing can be read. |
| 160 |
Argument is a whitespace-separated list of words in a string, or an arrayref of such strings. Returns |
| 161 |
the current list.</p> |
| 162 |
<p> |
| 163 |
</p> |
| 164 |
<h3><a name="unallow_attribute__"><code>unallow_attribute()</code></a></h3> |
| 165 |
<p>Same as allow_attributes, but removes attributes from the list.</p> |
| 166 |
<p> |
| 167 |
</p> |
| 168 |
<h2><a name="testing">Testing</a></h2> |
| 169 |
<p>DBIx::Safe has a very comprehensive test suite, so please use it! The only thing you should need is a |
| 170 |
database connection, by setting the environment variables DBI_DSN and DBI_USER (and DBI_PASS if needed).</p> |
| 171 |
<p>You can optionally run the module through Perl::Critic by setting the TEST_AUTHOR environment variable. |
| 172 |
You will need to have the modules Perl::Critic and Test::Perl::Critic installed.</p> |
| 173 |
<p>Please report any test failures to the author or <a href="mailto:[email protected].">[email protected].</a></p> |
| 174 |
<p> |
| 175 |
</p> |
| 176 |
<h2><a name="supported_databases">Supported Databases</a></h2> |
| 177 |
<p>Due to the difficulty of ensuring safe access to the database, each type of database must be specifically |
| 178 |
written into DBIx::Safe. Current databases supported are: Postgres (DBD::Pg).</p> |
| 179 |
<p> |
| 180 |
</p> |
| 181 |
<hr /> |
| 182 |
<h1><a name="website">WEBSITE</a></h1> |
| 183 |
<p>The latest version and other information about DBIx::Safe can be found at: |
| 184 |
<a href="http://bucardo.org/dbix_safe/">http://bucardo.org/dbix_safe/</a></p> |
| 185 |
<p> |
| 186 |
</p> |
| 187 |
<hr /> |
| 188 |
<h1><a name="development">DEVELOPMENT</a></h1> |
| 189 |
<p>The latest development version can be checked out by using git:</p> |
| 190 |
<pre> |
| 191 |
git clone <a href="http://bucardo.org/dbixsafe.git/">http://bucardo.org/dbixsafe.git/</a></pre> |
| 192 |
<p> |
| 193 |
</p> |
| 194 |
<hr /> |
| 195 |
<h1><a name="bugs">BUGS</a></h1> |
| 196 |
<p>Bugs should be reported to the author or <a href="mailto:[email protected].">[email protected].</a></p> |
| 197 |
<p> |
| 198 |
</p> |
| 199 |
<hr /> |
| 200 |
<h1><a name="author">AUTHOR</a></h1> |
| 201 |
<p>Greg Sabino Mullane <<a href="mailto:[email protected]">[email protected]</a>></p> |
| 202 |
<p> |
| 203 |
</p> |
| 204 |
<hr /> |
| 205 |
<h1><a name="license_and_copyright">LICENSE AND COPYRIGHT</a></h1> |
| 206 |
<p>Copyright 2006-2007 Greg Sabino Mullane <<a href="mailto:[email protected]">[email protected]</a>>.</p> |
| 207 |
<p>This software is free to use: see the LICENSE file for details.</p> |
| 208 |
|
| 209 |
</body> |
| 210 |
|
| 211 |
</html> |