Skip to content

Commit f43ff68

Browse files
committed
Documentation for --allow-paths and changelog entry for fixes
1 parent 3dd3a83 commit f43ff68

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bugfixes:
1616
* Code Generator: Fix internal compiler error when calling functions bound to calldata structs and arrays.
1717
* Code Generator: Fix internal compiler error when passing a 32-byte hex literal or a zero literal to ``bytes.concat()`` by disallowing such literals.
1818
* Commandline Interface: Fix crash when a directory path is passed to ``--standard-json``.
19+
* Commandline Interface: Fix resolution of paths whitelisted with ``--allowed-paths`` or implicitly due to base path, remappings and files being compiled. Correctly handle paths that do not match imports exactly due to being relative, non-normalized or empty.
1920
* Commandline Interface: Read JSON from standard input when ``--standard-json`` gets ``-`` as a file name.
2021
* Standard JSON: Include source location for errors in files with empty name.
2122
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.

docs/path-resolution.rst

+61-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Here are some examples of what you can expect if they are not:
297297
The same effect can be achieved in a more reliable way by using direct imports with
298298
:ref:`base path <base-path>` and :ref:`import remapping <import-remapping>`.
299299

300-
.. index:: ! base path, --base-path
300+
.. index:: ! base path, ! --base-path
301301
.. _base-path:
302302

303303
Base Path
@@ -355,6 +355,66 @@ If the base path is empty (e.g. if it is not explicitly provided), it is treated
355355
to the path to the current working directory with all symbolic links resolved.
356356
The result becomes the source unit name.
357357

358+
.. index:: ! allowed paths, ! --allow-paths, remapping; target
359+
.. _allowed-paths:
360+
361+
Allowed Paths
362+
=============
363+
364+
As a security measure, the Host Filesystem Loader will refuse to load files from outside of a few
365+
locations that are considered safe by default:
366+
367+
- Outside of Standard JSON mode:
368+
369+
- The directories containing input files listed on the command line.
370+
- The directories used as :ref:`remapping <import-remapping>` targets.
371+
If the target is not a directory (i.e does not end with ``/``, ``/.`` or ``/..``) the directory
372+
containing the target is used instead.
373+
- Base path.
374+
375+
- In Standard JSON mode:
376+
377+
- Base path.
378+
379+
Additional directories can be whitelisted using the ``--allow-paths`` option.
380+
The option accepts a comma-separated list of paths:
381+
382+
.. code-block:: bash
383+
384+
cd /home/user/project/
385+
solc token/contract.sol \
386+
lib/util.sol=libs/util.sol \
387+
--base-path=token/ \
388+
--allow-paths=../utils/,/usr/libraries
389+
390+
When the compiler is invoked with the command shown above, the Host Filesystem Loader will allow
391+
importing files from the following directories:
392+
393+
- ``/home/user/project/token/`` (because ``token/`` contains the input file and also because it is
394+
the base path),
395+
- ``/home/user/project/libs/`` (because ``libs/`` is a directory containing a remapping target),
396+
- ``/home/user/utils/`` (because of ``../utils/`` passed to ``--allow-paths``),
397+
- ``/usr/libraries`` (because of ``/usr/libraries`` passed to ``--allow-paths``),
398+
399+
.. note::
400+
401+
The working directory of the compiler is not one of the allowed paths by default unless it
402+
happens to be the base path (or the base path is not specified or has an empty value).
403+
404+
.. note::
405+
406+
The compiler does not check if allowed paths actually exist and whether they are directories.
407+
Non-existent or empty paths are simply ignored.
408+
If an allowed path matches a file rather than a directory, the file is considered whitelisted too.
409+
410+
.. warning::
411+
412+
Files and directories only reachable through symbolic links from allowed directories are not
413+
automatically whitelisted.
414+
For example if ``token/contract.sol`` in the example above was actually a symlink pointing at
415+
``/etc/passwd`` the compiler would refuse to load it unless ``/etc/`` was one of the allowed
416+
paths too.
417+
358418
.. index:: ! remapping; import, ! import; remapping, ! remapping; context, ! remapping; prefix, ! remapping; target
359419
.. _import-remapping:
360420

docs/using-the-compiler.rst

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,13 @@ it is also possible to provide :ref:`path redirects <import-remapping>` using ``
4747

4848
This essentially instructs the compiler to search for anything starting with
4949
``github.com/ethereum/dapp-bin/`` under ``/usr/local/lib/dapp-bin``.
50-
``solc`` will not read files from the filesystem that lie outside of
51-
the remapping targets and outside of the directories where explicitly specified source
52-
files reside, so things like ``import "/etc/passwd";`` only work if you add ``/=/`` as a remapping.
5350

5451
When accessing the filesystem to search for imports, :ref:`paths that do not start with ./
55-
or ../ <relative-imports>` are treated as relative to the directory specified using
52+
or ../ <direct-imports>` are treated as relative to the directory specified using
5653
``--base-path`` option (or the current working directory if base path is not specified).
5754
Furthermore, the part added via ``--base-path`` will not appear in the contract metadata.
5855

59-
For security reasons the compiler has restrictions on what directories it can access.
56+
For security reasons the compiler has :ref:`restrictions on what directories it can access <allowed-paths>`.
6057
Directories of source files specified on the command line and target paths of
6158
remappings are automatically allowed to be accessed by the file reader, but everything
6259
else is rejected by default.

0 commit comments

Comments
 (0)