Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions source/includes/groovy-sandbox-configuration.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
When a Groovy script is executed all code is validated against a blacklist of insecure expressions to prevent code that could
compromise the system. When you try to execute a script that contains insecure expressions you will see an error
similar to this:
When a Groovy script is executed, all code is validated to prevent operations that could compromise the system.
Depending on your installation, validation may use a whitelist (allowed expressions), a blacklist (blocked expressions),
or both. If both are enabled, an expression must be allowed by the whitelist and must not match the blacklist.

When you try to execute a script that contains an expression not included in the whitelist, or an expression blocked by
the blacklist , you’ll see an error similar to the following:

.. code-block:: none
:caption: *Error message encountered for scripts containing insecure expressions*

UnsupportedOperationException: Insecure call staticMethod java.lang.Runtime getRuntime ...
UnsupportedOperationException: Insecure call to staticMethod java.lang.Runtime getRuntime ...

|

It is recommended to keep the default configuration if possible. However, if access to one or more of the blacklisted expressions
is required, it is possible to override the blacklist configuration. Configuration is global and affects all scripts on the server.
It is recommended to keep the default configuration. However, if access to one or more of the blacklisted
expressions is required, or access to one or more expressions not in the whitelist is required, it is possible to
override the blacklist and/or whitelist configuration. Configuration is global and affects all scripts on the server.

.. warning:: When you allow a script to make an insecure call you should make sure it can only be executed with known
arguments and **never** with unverified user input.
Expand Down
72 changes: 70 additions & 2 deletions source/reference/modules/deployer.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
:is-up-to-date: True
:last-updated: 4.2.2
:orphan:
:last-updated: 4.5.0

.. index:: Modules; Crafter Deployer

Expand Down Expand Up @@ -942,6 +941,7 @@ The Groovy sandbox is enabled by default and can be disabled by changing the pro
.. code-block:: yaml
:linenos:
:caption: *CRAFTER_HOME/bin/crafter-deployer/config/application.yaml*
:emphasize-lines: 6

deployer:
main:
Expand All @@ -956,6 +956,16 @@ The Groovy sandbox is enabled by default and can be disabled by changing the pro
# The location of the blacklist to use for all targets
# (this will have no effect if the sandbox is disabled)
path: 'classpath:groovy/blacklist'
whitelist:
# Indicates if the whitelist should be enabled for all targets
# (this will have no effect if the sandbox is disabled)
enabled: true
# The location of the whitelist to use for all targets
# (this will have no effect if the sandbox is disabled)
path: 'file:${deployer.main.config.folderPath}/groovy/whitelist,classpath:groovy/whitelist'
# List of patterns for that is allowed to call as `staticMethod java.lang.System getenv java.lang.String` parameter (regexes separated by commas)
# NOTE: This property is applied even if the whitelist is disabled
getenvRegex: crafter_.*

|

Expand Down Expand Up @@ -987,6 +997,8 @@ To use a custom blacklist follow these steps:

Now you can execute the same script without any issues.

|

"""""""""""""""""""""""""""""""
Disabling the Sandbox Blacklist
"""""""""""""""""""""""""""""""
Expand All @@ -1005,6 +1017,62 @@ restrictions. To disable the blacklist for all targets update the ``application.

|

""""""""""""""""""""""""
Using a Custom Whitelist
""""""""""""""""""""""""
.. version_tag::
:label: Since
:version: 4.5.0

Crafter Deployer includes a default whitelist that you can find `here <https://github.com/craftercms/deployer/blob/support/4.x/src/main/resources/groovy/whitelist>`__. Make sure you review the branch/tag you're using.

To use a custom whitelist follow these steps:

#. Copy the default whitelist file to your classpath, for example:

``CRAFTER_HOME/bin/crafter-deployer/groovy/whitelist``

#. Add, remove or comment (adding a ``#`` at the beginning of the line) the expressions that your scripts require
#. Update the ``application.yaml`` configuration file to load the custom whitelist:

.. code-block:: yaml
:caption: ``CRAFTER_HOME/bin/crafter-deployer/config/application.yaml``

sandbox:
whitelist:
# The location of the whitelist to use for all targets
# (this will have no effect if the sandbox is disabled)
path: 'file:${deployer.main.config.folderPath}/groovy/whitelist,classpath:groovy/whitelist'

#. Restart CrafterCMS

Now you can execute the same script without any issues.

|

"""""""""""""""""""""""""""""""
Disabling the Sandbox Whitelist
"""""""""""""""""""""""""""""""
.. version_tag::
:label: Since
:version: 4.5.0

It is possible to disable the whitelist to allow the execution of most expressions, in
case you need to use a considerable number of the expression not included in the whitelist while keeping some basic
restrictions.

To disable the whitelist for all targets update the ``application.yaml`` configuration file:

.. code-block:: yaml
:caption: *CRAFTER_HOME/bin/crafter-deployer/config/application.yaml*

sandbox:
whitelist:
# Indicates if the whitelist should be enabled for all targets
# (this will have no effect if the sandbox is disabled)
enabled: false


"""""""""""""""""""
Grape Configuration
"""""""""""""""""""
Expand Down
62 changes: 61 additions & 1 deletion source/reference/modules/engine.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:is-up-to-date: True
:last-updated: 4.3.1
:last-updated: 4.5.0

.. _crafter-engine:

Expand Down Expand Up @@ -3754,13 +3754,18 @@ The Groovy sandbox is enabled by default and can be disabled by changing the pro
.. code-block:: properties
:linenos:
:caption: *CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/engine/extension/server-config.properties*
:emphasize-lines: 2

# Indicates if the sandbox should be enabled for all sites
crafter.engine.groovy.sandbox.enable=true
# Indicates if the blacklist should be enabled for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.blacklist.enable=true
# The location of the default blacklist to use for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.blacklist.path=classpath:crafter/engine/groovy/blacklist
# Indicates if the whitelist should be enabled for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.whitelist.enable=true
# The location of the default whitelist to use for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.whitelist.path=classpath:crafter/engine/groovy/whitelist

|

Expand Down Expand Up @@ -3792,6 +3797,8 @@ To use a custom blacklist follow these steps:

Now you can execute the same script without any issues.

|

"""""""""""""""""""""""""""""""
Disabling the Sandbox Blacklist
"""""""""""""""""""""""""""""""
Expand All @@ -3808,6 +3815,59 @@ restrictions. To disable the blacklist for all projects/sites update the server

|

""""""""""""""""""""""""
Using a Custom Whitelist
""""""""""""""""""""""""
.. version_tag::
:label: Since
:version: 4.5.0

Crafter Engine includes a default whitelist that you can find
`here <https://github.com/craftercms/engine/blob/support/4.x/src/main/resources/crafter/engine/groovy/whitelist>`__. Make sure you review the branch/tag you're using.

To use a custom whitelist follow these steps:

#. Copy the default whitelist file to your classpath, for example:

``CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/engine/extension/groovy/whitelist``

#. Add, remove or comment (adding a ``#`` at the beginning of the line) the expressions that your scripts require
#. Update the :ref:`server-config.properties <engine-configuration-files>` configuration file to load the custom whitelist:

.. code-block:: properties
:caption: ``CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/engine/extension/server-config.properties``

# The location of the whitelist to use for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.whitelist.path=classpath:crafter/engine/extension/groovy/whitelist

#. Restart CrafterCMS

Now you can execute the same script without any issues.

|

"""""""""""""""""""""""""""""""
Disabling the Sandbox Whitelist
"""""""""""""""""""""""""""""""
.. version_tag::
:label: Since
:version: 4.5.0

It is possible to disable the whitelist to allow the execution of most expressions, in
case you need to use a considerable number of the expression not included in the whitelist while keeping some basic
restrictions.

To disable the whitelist for all projects/sites update the server configuration file
:ref:`server-config.properties <engine-configuration-files>`:

.. code-block:: properties
:caption: *CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/engine/extension/server-config.properties*

# Indicates if the whitelist should be enabled for all sites (this will have no effect if the sandbox is disabled)
crafter.engine.groovy.sandbox.whitelist.enable=false

|

"""""""""""""""""""
Grape Configuration
"""""""""""""""""""
Expand Down
77 changes: 75 additions & 2 deletions source/reference/modules/studio.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:is-up-to-date: True
:last-updated: 4.4.3
:last-updated: 4.5.0

.. highlight:: xml

Expand Down Expand Up @@ -5192,7 +5192,7 @@ The Groovy sandbox is enabled by default and can be disabled by changing the pro
Using a Custom Blacklist
~~~~~~~~~~~~~~~~~~~~~~~~
Crafter Studio includes a default blacklist that you can find
`here <https://github.com/craftercms/studio/blob/support/4.x/src/main/resources/crafter/studio/groovy/blacklist>`_.
`here <https://github.com/craftercms/studio/blob/support/4.x/src/main/resources/crafter/studio/groovy/blacklist>`__.
Make sure you review the branch/tag you're using.

To use a custom blacklist follow these steps:
Expand All @@ -5214,6 +5214,8 @@ To use a custom blacklist follow these steps:

Now you can execute the same script without any issues.

|

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Disabling the Sandbox Blacklist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -5229,11 +5231,82 @@ the blacklist for all projects/sites update the ``studio-config-override.yaml``

|

~~~~~~~~~~~~~~~~~~~~~~~~
Using a Custom Whitelist
~~~~~~~~~~~~~~~~~~~~~~~~
.. version_tag::
:label: Since
:version: 4.5.0

Crafter Studio includes a default whitelist that you can find
`here <https://github.com/craftercms/studio/blob/support/4.x/src/main/resources/crafter/studio/groovy/whitelist>`__.
Make sure you review the branch/tag you're using.

To use a custom whitelist follow these steps:

#. Copy the default whitelist file to your classpath, for example:

``CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/studio/extension/groovy/whitelist``

#. Add, remove or comment (adding a ``#`` at the beginning of the line) the expressions that your scripts require
#. Update the ``studio-config-override.yaml`` configuration file to load the custom whitelist:

.. code-block:: yaml
:caption: *CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/studio/extension/studio-config-override.yaml*

# The location of the default whitelist to use (this will have no effect if the sandbox is disabled)
studio.scripting.sandbox.whitelist.path: classpath:crafter/studio/groovy/whitelist

#. Restart CrafterCMS

Now you can execute the same script without any issues.

|

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Disabling the Sandbox Whitelist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. version_tag::
:label: Since
:version: 4.5.0

It is possible to disable the whitelist to allow the execution of most expressions, in case you need to use a
considerable number of expressions not included in the whitelist while keeping some basic restrictions. To disable
the whitelist for all projects/sites update the ``studio-config-override.yaml`` configuration file:

.. code-block:: yaml
:caption: *CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/studio/extension/studio-config-override.yaml*

# Indicates if the whitelist should be enabled (this will have no effect if the sandbox is disabled)
studio.scripting.sandbox.whitelist.enable: false

|

~~~~~~~~~~~~~~~~~~~
Grape Configuration
~~~~~~~~~~~~~~~~~~~
.. include:: /includes/groovy-grape-configuration.rst

~~~~~~~~~~~~~~~
Grapes Download
~~~~~~~~~~~~~~~
.. version_tag::
:label: Since
:version: 4.5.0

The following allows you to enable or disable automatic Groovy dependency (grapes) downloads for scripts (@grab):

.. code-block:: yaml
:caption: *CRAFTER_HOME/bin/apache-tomcat/shared/classes/crafter/studio/extension/studio-config-override.yaml*
:emphasize-lines: 3

# Indicates if @Grab annotations should download grapes
# If false, only already downloaded grapes will be available
studio.scripting.grapes.download.enabled: false

Automatic grapes download is disabled by default. Set ``studio.scripting.grapes.download.enabled`` to true to enable
automatic grapes download.

~~~~~~~~~~~~~~~
Important Notes
~~~~~~~~~~~~~~~
Expand Down