File: sandbox.xml

package info (click to toggle)
php-doc 20061001-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 45,764 kB
  • ctags: 1,611
  • sloc: xml: 502,485; php: 7,645; cpp: 500; makefile: 297; perl: 161; sh: 141; awk: 28
file content (437 lines) | stat: -rw-r--r-- 13,727 bytes parent folder | download
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.16 $ -->
<!-- Generated by xml_proto.php v2.2. Found in /scripts directory of phpdoc. -->
<refentry id="runkit.sandbox">
 <refnamediv>
  <refname>Runkit_Sandbox</refname>
  <refpurpose>
   Runkit Sandbox Class -- PHP Virtual Machine
  </refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;

  <para>
   Instantiating the <classname>Runkit_Sandbox</classname>
   class creates a new thread with its own scope
   and program stack.  Using a set of options passed to the constructor, this environment
   may be restricted to a subset of what the primary interpreter can do and provide a
   safer environment for executing user supplied code.
  </para>

  &note.runkit.sandbox;
 </refsect1>

 <refsect1 role="constructor">
  <title>Constructor</title>
  <methodsynopsis>
   <type>void</type><methodname>Runkit_Sandbox::__construct</methodname>
   <methodparam choice="opt"><type>array</type><parameter>options</parameter></methodparam>
  </methodsynopsis>

  <para>
   <parameter>options</parameter> is an associative array containing
   any combination of the special ini options listed below.
  </para>

  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>safe_mode</parameter></term>
     <listitem>
      <para>
       If the outer script which is instantiating the
       <classname>Runkit_Sandbox</classname> class
       is configured with <literal>safe_mode = off</literal>, then safe_mode
       may be turned on for the sandbox environment.  This setting can not
       be used to disable <literal>safe_mode</literal> when it's already
       enabled in the outer script.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>safe_mode_gid</parameter></term>
     <listitem>
      <para>
       If the outer script which is instantiating the
       <classname>Runkit_Sandbox</classname> class
       is configured with <literal>safe_mode_gid = on</literal>, then safe_mode_gid
       may be turned off for the sandbox environment.  This setting can not
       be used to enable <literal>safe_mode_gid</literal> when it's already
       disabled in the outer script.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>safe_mode_include_dir</parameter></term>
     <listitem>
      <para>
       If the outer script which is instantiating the
       <classname>Runkit_Sandbox</classname> class
       is configured with a <literal>safe_mode_include_dir</literal>,
       then a new safe_mode_include_dir may be set for sandbox environments
       below the currently defined value.  safe_mode_include_dir may also be
       cleared to indicate that the bypass feature is disabled.
       If safe_mode_include_dir was blank in the outer script, but safe_mode
       was not enabled, then any arbitrary safe_mode_include_dir may be set
       while turning safe_mode on.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>open_basedir</parameter></term>
     <listitem>
      <para>
       <parameter>open_basedir</parameter> may be set to any path below the
       current setting of <literal>open_basedir</literal>. If
       <literal>open_basedir</literal> is not set within the global scope,
       then it is assumed to be the root directory and may be set to any location.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>allow_url_fopen</parameter></term>
     <listitem>
      <para>
       Like <parameter>safe_mode</parameter>, this setting can only be made more restrictive,
       in this case by setting it to &false; when it is previously set to &true;
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>disable_functions</parameter></term>
     <listitem>
      <para>
       Comma separated list of functions to disable within the sandbox sub-interpreter.
       This list need not contain the names of the currently disabled functions,
       they will remain disabled whether listed here or not.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>disable_classes</parameter></term>
     <listitem>
      <para>
       Comma separated list of classes to disable within the sandbox sub-interpreter.
       This list need not contain the names of the currently disabled classes,
       they will remain disabled whether listed here or not.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>runkit.superglobal</parameter></term>
     <listitem>
      <para>
       Comma separated list of variables to be treated as superglobals within the
       sandbox sub-interpreter.  These variables will be used in addition to any
       variables defined internally or through the global runkit.superglobal setting.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>runkit.internal_override</parameter></term>
     <listitem>
      <para>
       Ini option <literal>runkit.internal_override</literal> may be disabled
       (but not re-enabled) within sandboxes.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>

  <example>
   <title>Instantiating a restricted sandbox</title>
   <programlisting role="php">
<![CDATA[
<?php
$options = array(
  'safe_mode'=>true,
  'open_basedir'=>'/var/www/users/jdoe/',
  'allow_url_fopen'=>'false',
  'disable_functions'=>'exec,shell_exec,passthru,system',
  'disable_classes'=>'myAppClass');
$sandbox = new Runkit_Sandbox($options);
/* Non-protected ini settings may set normally */
$sandbox->ini_set('html_errors',true);
?>
]]>
   </programlisting>
  </example>
 </refsect1>

 <refsect1 role="variables">
  <title>Accessing Variables</title>
  <para>
   All variables in the global scope of the sandbox environment
   are accessible as properties of the sandbox object.
   The first thing to note is that because of the way memory
   between these two threads is managed, object and resource
   variables can not currently be exchanged between interpreters.
   Additionally, all arrays are deep copied and any references
   will be lost.  This also means that references between
   interpreters are not possible.
  </para>

  <example>
   <title>Working with variables in a sandbox</title>
   <programlisting role="php">
<![CDATA[
<?php
$sandbox = new Runkit_Sandbox();

$sandbox->foo = 'bar';
$sandbox->eval('echo "$foo\n"; $bar = $foo . "baz";');
echo "{$sandbox->bar}\n";
if (isset($sandbox->foo)) unset($sandbox->foo);
$sandbox->eval('var_dump(isset($foo));');
?>
]]>
   </programlisting>
  </example>
  &example.outputs;
  <screen>
<![CDATA[
bar
barbaz
bool(false)
]]>
  </screen>
 </refsect1>

 <refsect1 role="functions">
  <title>Calling PHP Functions</title>
  <para>
   Any function defined within the sandbox may be called as
   a method on the sandbox object.  This also includes a few
   pseudo-function language constructs:  <function>eval</function>,
   <function>include</function>, <function>include_once</function>,
   <function>require</function>, <function>require_once</function>,
   <function>echo</function>, <function>print</function>,
   <function>die</function>, and <function>exit</function>.
  </para>

  <example>
   <title>Calling sandbox functions</title>
   <programlisting role="php">
<![CDATA[
<?php
$sandbox = new Runkit_Sandbox();

echo $sandbox->str_replace('a','f','abc');
?>
]]>
   </programlisting>
  </example>
  &example.outputs;
  <screen>
<![CDATA[
fbc
]]>
  </screen>

  <para>
   When passing arguments to a sandbox function, the arguments
   are taken from the outer instance of PHP.  If you wish to pass
   arguments from the sandbox's scope, be sure to access them as
   properties of the sandbox object as illustrated above.
  </para>

  <example>
   <title>Passing arguments to sandbox functions</title>
   <programlisting role="php">
<![CDATA[
<?php
$sandbox = new Runkit_Sandbox();

$foo = 'bar';
$sandbox->foo = 'baz';
echo $sandbox->str_replace('a',$foo,'a');
echo $sandbox->str_replace('a',$sandbox->foo,'a');
?>
]]>
   </programlisting>
  </example>
  &example.outputs;
  <screen>
<![CDATA[
bar
baz
]]>
  </screen>
 </refsect1>

 <refsect1 role="settings">
  <title>Changing Sandbox Settings</title>
  <para>
   As of runkit version 0.5, certain Sandbox settings may
   be modified on the fly using ArrayAccess syntax.
   Some settings, such as <parameter>active</parameter>
   are read-only and meant to provide status information.
   Other settings, such as <parameter>output_handler</parameter>
   may be set and read much like a normal array offset.
   Future settings may be write-only, however no such
   settings currently exist.
  </para>

  <para>
   <table>
    <title>Sandbox Settings / Status Indicators</title>
    <tgroup cols="4">
     <thead>
      <row>
       <entry>Setting</entry>
       <entry>Type</entry>
       <entry>Purpose</entry>
       <entry>Default</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry><literal>active</literal></entry>
       <entry><type>Boolean</type> (Read Only)</entry>
       <entry>
        &true; if the Sandbox is still in a usable state,
        &false; if the request is in bailout due to a
        call to die(), exit(), or because of a fatal
        error condition.
       </entry>
       <entry>&true; (Initial)</entry>
      </row>
      <row>
       <entry><literal>output_handler</literal></entry>
       <entry><type>Callback</type></entry>
       <entry>
        When set to a valid callback, all output generated
        by the Sandbox instance will be processed through
        the named function.
        Sandbox output handlers follow the same calling
        conventions as the system-wide output handler.
       </entry>
       <entry>None</entry>
      </row>
      <row>
       <entry><literal>parent_access</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox use instances of the
        <classname>Runkit_Sandbox_Parent</classname> class?
        Must be enabled for other
        <classname>Runkit_Sandbox_Parent</classname>
        related settings to work.
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_read</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox read variables in its parent's context?
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_write</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox modify variables in its parent's context?
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_eval</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox evaluate arbitrary code in its
        parent's context? <emphasis>DANGEROUS</emphasis>
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_include</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox include php code files in its
        parent's context? <emphasis>DANGEROUS</emphasis>
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_echo</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox echo data in its parent's context
        effectively bypassing its own output_handler?
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_call</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox call functions in its
        parent's context?
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_die</literal></entry>
       <entry><type>Boolean</type></entry>
       <entry>
        May the sandbox kill its own parent? (And thus itself)
       </entry>
       <entry>&false;</entry>
      </row>
      <row>
       <entry><literal>parent_scope</literal></entry>
       <entry><type>Integer</type></entry>
       <entry>
        What scope will parental property access look at?
        0 == Global scope, 1 == Calling scope,
        2 == Scope preceeding calling scope,
        3 == The scope before that, etc..., etc...
       </entry>
       <entry><literal>0</literal> (Global)</entry>
      </row>
      <row>
       <entry><literal>parent_scope</literal></entry>
       <entry><type>String</type></entry>
       <entry>
        When <literal>parent_scope</literal> is set to
        a string value, it refers to a named array variable
        in the global scope.  If the named variable does not
        exist at the time of access it will be created as an
        empty array.  If the variable exists but it not an array,
        a dummy array will be created containing a reference
        to the named global variable.
       </entry>
       <entry></entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->