summaryrefslogtreecommitdiff
path: root/doc/source
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source')
-rw-r--r--doc/source/config.rst126
-rw-r--r--doc/source/faq.rst6
2 files changed, 107 insertions, 25 deletions
diff --git a/doc/source/config.rst b/doc/source/config.rst
index c01377c..0b7b7fd 100644
--- a/doc/source/config.rst
+++ b/doc/source/config.rst
@@ -1,16 +1,6 @@
1Configuration 1Configuration
2============= 2=============
3 3
4Options are chainable by using dots (``.``) and string parameters
5**must** be quoted, while booleans and integers aren't.
6
7Comments are prefixed either with ``#``, or ``;``.
8
9Some rules apply in a specific ``function`` (context) on a specific ``variable``
10(data), like ``disable_function``. Others can only be enabled/disabled, like
11``harden_random``.
12
13
14.. warning:: 4.. warning::
15 5
16 If you configure Snuffleupagus incorrectly, your website *might* not work 6 If you configure Snuffleupagus incorrectly, your website *might* not work
@@ -21,17 +11,6 @@ Some rules apply in a specific ``function`` (context) on a specific ``variable``
21 read the present documentation about how to configure them, 11 read the present documentation about how to configure them,
22 evaluate your threat model and write your configuration file accordingly. 12 evaluate your threat model and write your configuration file accordingly.
23 13
24Most of the features can be used in ``simulation`` mode by appending the
25``.simulation()`` option to them (eg. ``sp.readonly_exec.simulation().enable();``) to see
26whether or not they could break your website. The simulation mode won't block the request,
27but will write a warning in the log.
28
29The rules are evaluated in the order that they are written, the **first** one
30to match will terminate the evaluation (except for rules in simulation mode).
31
32Configuration file format
33-------------------------
34
35Since PHP *ini-like* configuration model isn't flexible enough, 14Since PHP *ini-like* configuration model isn't flexible enough,
36Snuffleupagus is using its own format in the file specified by 15Snuffleupagus is using its own format in the file specified by
37the directive ``sp.configuration_file`` **in** your ``php.ini`` file, 16the directive ``sp.configuration_file`` **in** your ``php.ini`` file,
@@ -61,6 +40,38 @@ your logs of course. We do **not** recommend to use it of course, but sometimes
61it might be useful to be able to "debug in production" without breaking your 40it might be useful to be able to "debug in production" without breaking your
62website. 41website.
63 42
43Configuration file format
44-------------------------
45
46Options are chainable by using dots (``.``).
47
48Some options have a string parameter, that **must** be quoted with double quotes, e.g. ``"string"``.
49
50Comments are prefixed either with ``#``, or ``;``.
51
52Some rules apply in a specific ``function`` (context) on a specific ``variable``
53(data), like ``disable_function``. Others can only be enabled/disabled, like
54``harden_random``.
55
56Most of the features can be used in ``simulation`` mode by appending the
57``.simulation()`` or ``.sim()`` option to them (eg. ``sp.readonly_exec.simulation().enable();``) to see
58whether or not they could break your website. The simulation mode won't block the request,
59but will write a warning in the log.
60
61The rules are evaluated in the order that they are written, the **first** one
62to match will terminate the evaluation (except for rules in simulation mode).
63
64Rules can be split into lines and contain whitespace for easier readability and maintenance: (This feature is available since version 0.8.0.)
65
66::
67
68 sp.disable_function.function("mail")
69 .param("to").value_r("\\n")
70 .alias("newline in mail() To:")
71 .drop();
72
73The terminating ``;`` is optional for now, but it should be used for future compatibility.
74
64Miscellaneous 75Miscellaneous
65------------- 76-------------
66 77
@@ -178,6 +189,70 @@ Cookies-related mitigations
178Since snuffleupagus is providing several hardening features for cookies, 189Since snuffleupagus is providing several hardening features for cookies,
179there is a dedicated web page :ref:`here <cookie-encryption-page>` about them. 190there is a dedicated web page :ref:`here <cookie-encryption-page>` about them.
180 191
192INI Settings Protection
193^^^^^^^^^^^^^^^^^^^^^^^
194INI settings can be forced to a value, limited by min/max value or regular expression and set read-only mode.
195
196First, this feature can be enabled or disabled:
197
198::
199
200 sp.ini_protection.enable();
201 sp.ini_protection.disable();
202
203The INI protection feature can be set to simulation mode, where violations are only reported, but rules are not enforced:
204
205::
206
207 sp.ini_protection.simulation();
208
209Rule violations can be set to drop as a global policy, or alternatively be set on individual rules using ``.drop()``.
210
211::
212
213 sp.ini_protection.policy_drop();
214
215Rules can be set to fail silently without logging anything:
216
217::
218
219 sp.ini_protection.policy_silent_fail();
220 ## or write sp.ini_protection.policy_no_log(); as an alias
221
222Read-only settings are implemented in a way that the PHP system itself can block the setting, which is very efficient. If you do not need to log read-only violations, these can be set to silent separately:
223
224::
225
226 sp.ini_protection.policy_silent_ro();
227
228A global access policy can be set to either read-only or read-write. Individual entries can be set to read-only/read-write as well using ``.ro()``/``.rw()``.
229
230::
231
232 sp.ini_protection.policy_readonly();
233 sp.ini_protection.policy_readwrite();
234
235Individual rules are specified using ``sp.ini``. These entries can have the following attributes:
236
237- ``.key("...")``: mandatory ini name.
238- ``.set("...")``: set the initial value. This overrides php.ini. checks are not performed for this initial value.
239- ``.min("...")`` / ``.max("...")``: value must be an integer between .min and .max. shorthand notation (e.g. 1k = 1024) is allowed
240- ``.regexp("...")``: value must match the regular expression
241- ``.allow_null()``: allow setting a NULL-value
242- ``.msg("...")``: message is shown in logs on rule violation instead of default message
243- ``.readonly()`` / ``.ro()`` / .readwrite() / .rw(): set entry to read-only or read-write respectively. If no access keyword is provided, the entry inherits the default policy set by ``sp.ini_protection.policy_*``-rules.
244- ``.drop()``: drop request on rule violation for this entry
245- ``.simulation()``: only log rule violation for this entry
246
247Examples:
248
249::
250
251 sp.ini.key("display_errors").set("0").ro();
252 sp.ini.key("default_socket_timeout").min("1").max("300").rw();
253 sp.ini.key("highlight.comment").regexp("^#[0-9a-fA-F]{6}$");
254
255For more examples, check out the ``config`` directory.
181 256
182readonly_exec 257readonly_exec
183^^^^^^^^^^^^^ 258^^^^^^^^^^^^^
@@ -218,14 +293,15 @@ It can either be ``enabled`` or ``disabled`` and can be used in ``simulation`` m
218 sp.upload_validation.script("/var/www/is_valid_php.py").enable(); 293 sp.upload_validation.script("/var/www/is_valid_php.py").enable();
219 294
220 295
221disable_xxe 296xxe_protection
222^^^^^^^^^^^ 297^^^^^^^^^^^
223 298
224:ref:`disable_xxe <xxe-feature>`, enabled by default, will prevent XXE attacks by disabling the loading of external entities (``libxml_disable_entity_loader``) in the XML parser. 299:ref:`xxe_protection <xxe-feature>`, disabled by default, will prevent XXE attacks by disabling the loading of external entities (``libxml_disable_entity_loader``) in the XML parser.
225 300
226:: 301::
227 302
228 sp.disable_xxe.enable(); 303 sp.xxe_protection.enable();
304 sp.xxe_protection.disable();
229 305
230 306
231Whitelist of stream-wrappers 307Whitelist of stream-wrappers
@@ -380,7 +456,7 @@ It's currently not possible to:
380 `for now <https://github.com/jvoisin/snuffleupagus/issues/190>`__). 456 `for now <https://github.com/jvoisin/snuffleupagus/issues/190>`__).
381 This is why hooked ``print`` will be displayed as ``echo`` in the logs. 457 This is why hooked ``print`` will be displayed as ``echo`` in the logs.
382- Hook `strlen`, since in latest PHP versions, this function is usually 458- Hook `strlen`, since in latest PHP versions, this function is usually
383 optimized away by the compiled. 459 optimized away by the compiler.
384 460
385 461
386Examples 462Examples
diff --git a/doc/source/faq.rst b/doc/source/faq.rst
index bdfc7c1..0695089 100644
--- a/doc/source/faq.rst
+++ b/doc/source/faq.rst
@@ -79,6 +79,12 @@ We chose the LGPL because we don't care that much how you're using Snuffleupagus
79but we'd like to force people to make their improvements/contributions 79but we'd like to force people to make their improvements/contributions
80available to everyone. 80available to everyone.
81 81
82The complete license text is shipped with the sources and can be found under ``LICENSE``.
83
84For compatibility with older PHP versions, some original PHP source code was copied or ported back to older versions.
85This source code resides in ``src/sp_php_compat.c`` and ``src/sp_php_compat.h`` and retains its original license
86`The PHP License, version 3.01 <https://www.php.net/license/3_01.txt>`_, also included with the sources as ``PHP_LICENSE``.
87
82 88
83What is the different between SNuffleupaugs and a (WAF) like ModSecurity? 89What is the different between SNuffleupaugs and a (WAF) like ModSecurity?
84""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 90"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""