Skip to content

Commit dc0ba88

Browse files
committed
Docs: Document that disabling access to the Python builtins is a good idea when trying to restrict what Lua code should be able to do.
See GHSA-69v7-xpr6-6gjm
1 parent 2c0e9a6 commit dc0ba88

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

README.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,21 @@ shared memory setup.
873873
Restricting Lua access to Python objects
874874
----------------------------------------
875875

876+
.. note::
877+
Any Lupa deployment that allows untrusted Lua code to be executed
878+
should disable the access to Python's builtin functions,
879+
as shown below. This includes functions like ``eval()``, ``exec()``
880+
or ``__import__()`` that allow arbitrary code execution,
881+
but also seemingly innocent helpers like ``getattr()``
882+
which provides unrestricted access to arbitrary Python attributes
883+
that is not guarded by the attribute access control described below.
884+
876885
..
877886
>>> try: unicode = unicode
878887
... except NameError: unicode = str
879888
880889
Lupa provides a simple mechanism to control access to Python objects.
881-
Each attribute access can be passed through a filter function as
882-
follows:
890+
Each attribute access can be passed through a filter function as follows:
883891

884892
.. code:: python
885893
@@ -890,16 +898,16 @@ follows:
890898
... raise AttributeError('access denied')
891899
892900
>>> lua = lupa.LuaRuntime(
893-
... register_eval=False,
894-
... attribute_filter=filter_attribute_access)
901+
... register_eval=False, # disallow python.eval('...')
902+
... register_builtins=False, # disallow python.builtins.*
903+
... attribute_filter=filter_attribute_access)
895904
>>> func = lua.eval('function(x) return x.__class__ end')
896905
>>> func(lua)
897906
Traceback (most recent call last):
898907
...
899908
AttributeError: access denied
900909
901-
The ``is_setting`` flag indicates whether the attribute is being read
902-
or set.
910+
The ``is_setting`` flag indicates whether the attribute is being read or set.
903911

904912
Note that the attributes of Python functions provide access to the
905913
current ``globals()`` and therefore to the builtins etc. If you want
@@ -934,7 +942,10 @@ setter function implementations for a ``LuaRuntime``:
934942
935943
>>> x = X()
936944
937-
>>> lua = lupa.LuaRuntime(attribute_handlers=(getter, setter))
945+
>>> lua = lupa.LuaRuntime(
946+
... register_eval=False, # disallow python.eval('...')
947+
... register_builtins=False, # disallow python.builtins.*
948+
... attribute_handlers=(getter, setter))
938949
>>> func = lua.eval('function(x) return x.yes end')
939950
>>> func(x) # getting 'yes'
940951
123

0 commit comments

Comments
 (0)