Skip to content

Commit 60b2f2b

Browse files
committed
Documentation for --allow-paths and changelog entry for fixes
1 parent c0b8378 commit 60b2f2b

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Bugfixes:
2121
* Code Generator: Fix ICE on assigning to calldata structs and statically-sized calldata arrays in inline assembly.
2222
* Code Generator: Use stable source order for ABI functions.
2323
* Commandline Interface: Disallow the ``--experimental-via-ir`` option in Standard JSON, Assembler and Linker modes.
24+
* 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.
2425
* Commandline Interface: Report optimizer options as invalid in Standard JSON and linker modes instead of ignoring them.
2526
* Name Resolver: Fix that when importing an aliased symbol using ``import {AliasedName} from "a.sol"`` it would use the original name of the symbol and not the aliased one.
2627
* Opcode Optimizer: Prevent the optimizer from running multiple times to avoid potential bytecode differences for referenced code.

docs/path-resolution.rst

Lines changed: 67 additions & 1 deletion
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
@@ -373,6 +373,72 @@ The resulting file path becomes the source unit name.
373373
When working with older versions of the compiler it is recommended to invoke the compiler from
374374
the base path and to only use relative paths on the command line.
375375

376+
.. index:: ! allowed paths, ! --allow-paths, remapping; target
377+
.. _allowed-paths:
378+
379+
Allowed Paths
380+
=============
381+
382+
As a security measure, the Host Filesystem Loader will refuse to load files from outside of a few
383+
locations that are considered safe by default:
384+
385+
- Outside of Standard JSON mode:
386+
387+
- The directories containing input files listed on the command line.
388+
- The directories used as :ref:`remapping <import-remapping>` targets.
389+
If the target is not a directory (i.e does not end with ``/``, ``/.`` or ``/..``) the directory
390+
containing the target is used instead.
391+
- Base path.
392+
393+
- In Standard JSON mode:
394+
395+
- Base path.
396+
397+
Additional directories can be whitelisted using the ``--allow-paths`` option.
398+
The option accepts a comma-separated list of paths:
399+
400+
.. code-block:: bash
401+
402+
cd /home/user/project/
403+
solc token/contract.sol \
404+
lib/util.sol=libs/util.sol \
405+
--base-path=token/ \
406+
--allow-paths=../utils/,/tmp/libraries
407+
408+
When the compiler is invoked with the command shown above, the Host Filesystem Loader will allow
409+
importing files from the following directories:
410+
411+
- ``/home/user/project/token/`` (because ``token/`` contains the input file and also because it is
412+
the base path),
413+
- ``/home/user/project/libs/`` (because ``libs/`` is a directory containing a remapping target),
414+
- ``/home/user/utils/`` (because of ``../utils/`` passed to ``--allow-paths``),
415+
- ``/tmp/libraries/`` (because of ``/tmp/libraries`` passed to ``--allow-paths``),
416+
417+
.. note::
418+
419+
The working directory of the compiler is one of the paths allowed by default only if it
420+
happens to be the base path (or the base path is not specified or has an empty value).
421+
422+
.. note::
423+
424+
The compiler does not check if allowed paths actually exist and whether they are directories.
425+
Non-existent or empty paths are simply ignored.
426+
If an allowed path matches a file rather than a directory, the file is considered whitelisted, too.
427+
428+
.. note::
429+
430+
Allowed paths are case-sensitive even if the filesystem is not.
431+
The case must exactly match the one used in your imports.
432+
For example ``--allow-paths tokens`` will not match ``import "Tokens/IERC20.sol"``.
433+
434+
.. warning::
435+
436+
Files and directories only reachable through symbolic links from allowed directories are not
437+
automatically whitelisted.
438+
For example if ``token/contract.sol`` in the example above was actually a symlink pointing at
439+
``/etc/passwd`` the compiler would refuse to load it unless ``/etc/`` was one of the allowed
440+
paths too.
441+
376442
.. index:: ! remapping; import, ! import; remapping, ! remapping; context, ! remapping; prefix, ! remapping; target
377443
.. _import-remapping:
378444

docs/using-the-compiler.rst

Lines changed: 2 additions & 5 deletions
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)