(Safe-)Namespaces and opcode restrictions |
Since most web servers will contain more than one document, it is
necessary to protect the documents against each other. Embperl does
this by using Perl namespaces. By default, Embperl executes every
document in its own namespace (package). This will prevent documents
from accidentally overriding the other's data. You can change this
behavior (or simply the package name) with the configuration directive
EMBPERL_PACKAGE. NOTE: By explicitly specifying a package name, you
can access data that is used by another document. If Embperl is used by more than one person, it may be neccessary to
protect documents from each other. To do this, Embperl
gives you the option of using safe namespaces. Each document runs in
its own package and can't access anything outside of this package.
(See the documentation of Safe.pm for a more detailed discussion of
safe namespaces.) To make a document run in a safe namespace, simply add
optSafeNamespace to EMBPERL_OPTIONS. The default package name
used is the same as in normal operation and can be changed with
EMBPERL_PACKAGE. NOTE: From the perspective of the document being
executed, the code is running in the package main! A second option to make Embperl more secure is the use of the opcode
restriction mask. Before you can use the opcode mask, you must set up
a safe compartment. B<$cp = HTML::Embperl::AddCompartment($name);> This will create a new compartment with a default opcode mask and the
name $name. (The name is used later to tell Embperl which compartment
to use.) Now you can change the operator mask. For example: B<$cp->deny(':base_loop');> In your configuration you must set the option optOpcodeMask in
EMBPERL_OPTIONS and specify from which compartment the opcode mask
should be taken by setting EMBPERL_COMPARTMENT. Example (for use with mod_perl):
B<srm.conf:>
PerlScript startup.pl
SetEnv EMBPERL_DEBUG 2285
Alias /embperl /path/to/embperl/eg
<Location /embperl/x>
SetHandler perl-script
PerlHandler HTML::Embperl
Options ExecCGI
PerlSetEnv EMBPERL_OPTIONS 12
PerlSetEnv EMBPERL_COMPARTMENT test
</Location>
B<startup.pl:>
$cp = HTML::Embperl::AddCompartment('test');
$cp->deny(':base_loop'); This will execute the file startup.pl on server startup. startup.pl
sets up a compartment named `test', which will have a default opcode
mask and additionaly, will have loops disabled. Code will be executed
in a safe namespace. NOTE: The package name from the compartment is NOT used! Look at the documentation of Safe.pm and Opcode.pm for more detailed
information on how to set opcode masks.
|