solidity icon indicating copy to clipboard operation
solidity copied to clipboard

File outside of allowed directories issue

Open aleitner opened this issue 9 years ago • 84 comments

I have zeppelin as a submodule, and I am trying to import a solidity contract from inside of the zeppelin submodule. solc is throwing and error when trying to compile though. File outside of allowed directories.\nimport 'zeppelin-solidity/contracts/ownership/Ownable.sol any idea what's causing this?

Here is my repository https://github.com/aleitner/MineableToken

Current state:

The following works on linux, but not on windows:

# pwd
/tmp
# cat a/b/c/d/a.sol 
import "../../x/y/r.sol";
# cat a/b/c/x/y/r.sol
# (empty)
# solc --allow-paths . a/b/c/d/a.sol 
Trying to load a/b/x/y/r.sol (boost: "a/b/x/y/r.sol" canonical: "/tmp/a/b/x/y/r.sol" )
Allowed directory: ""
Is allowed: 1
# (compilation successful)

aleitner avatar Aug 14 '17 14:08 aleitner

@aleitner I'm having a similar issue when editing a .sol file in <prj-root>/contracts, trying to import from <prj-root>/node_modules/

How did you resolve this?

HaleTom avatar Oct 16 '17 12:10 HaleTom

It was happening when I was trying to include a file that was a git submodule. When I just added the code to the project in a folder rather than as a submodule, the problem went away

aleitner avatar Oct 16 '17 12:10 aleitner

@aleitner Did the pathname then exist when it didn't before? I created a symlink and its not working :(

HaleTom avatar Oct 16 '17 12:10 HaleTom

I didn't look too far into how git submodules work, but I reopened the issues because it's still a problem that needs to be addressed.

aleitner avatar Oct 16 '17 12:10 aleitner

Solidity checks the canonical path and does not allow symlinks.

chriseth avatar Oct 16 '17 12:10 chriseth

The same behaviour occurs even without symlinks, as shown here.

Also when running from inside the node_modules directory:

$ solc ../contracts/CapitalCoin.sol 
../contracts/CapitalCoin.sol:2:1: Error: Source "zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.
import 'zeppelin-solidity/contracts/token/StandardToken.sol';
^-----------------------------------------------------------^
$ pwd
/home/ravi/repo/erc20/coin/node_modules
$ readlink -f 'zeppelin-solidity/contracts/token/StandardToken.sol'
/home/ravi/repo/erc20/coin/node_modules/zeppelin-solidity/contracts/token/StandardToken.sol
$ 

readlink -f shows that there are no symlinks in this case.

HaleTom avatar Oct 16 '17 13:10 HaleTom

import 'zeppelin-solidity/contracts/token/StandardToken.sol' is importing from an absolute path, i.e. from /zeppelin-solidity/contracts/token/StandardToken.sol. Does it work if you change it to relative?

chriseth avatar Oct 16 '17 13:10 chriseth

If I prepend ./, I get a different issue:

$ pwd
/home/ravi/repo/erc20/coin/node_modules
$ cat ../contracts/testImport.sol
pragma solidity ^0.4.15;
import './zeppelin-solidity/contracts/token/StandardToken.sol';
$ solc ../contracts/testImport.sol
../contracts/testImport.sol:2:1: Error: Source "../contracts/zeppelin-solidity/contracts/token/StandardToken.sol" not found: File outside of allowed directories.
import './zeppelin-solidity/contracts/token/StandardToken.sol';
^-------------------------------------------------------------^
$

It's not using the $PWD working directory as ., but rather ../contracts, so it won't find ../contracts/zeppelin-solidity.

What is the design decision behind not allowing a fundamental feature of POSIX filesystems, namely symlinks?

HaleTom avatar Oct 19 '17 03:10 HaleTom

@chriseth I guess there may be a typo. Here import path is preparing for comparison: https://github.com/ethereum/solidity/blob/dc154b4e5661945ca9c98720e097e84729a528be/solc/CommandLineInterface.cpp#L672

And here one of allow-paths is preparing for append: https://github.com/ethereum/solidity/blob/dc154b4e5661945ca9c98720e097e84729a528be/solc/CommandLineInterface.cpp#L713

I suggest to change boost::filesystem::path(path); into boost::filesystem::canonical(path); in the second fragment.

Do you accept?

limexp avatar Nov 07 '17 19:11 limexp

@ekpyron I think all of these were sorted?

axic avatar Apr 17 '18 13:04 axic

I'm still seeing errors and my setup is like @HaleTom (using node_modules). Given that, and that the issue is still marked as open, I presume it is not yet fixed?

Talvish avatar Jun 27 '18 00:06 Talvish

Issue is still present in 0.4.24 compiler version. Can we expect fixing this error?

JuliusBrain avatar Jul 02 '18 15:07 JuliusBrain

@Talvish @JuliusBrain could you please explain your set up a little more in detail? The issue is still open because it is not clear whether this is a bug or what the expectation is.

chriseth avatar Jul 10 '18 14:07 chriseth

import_remappings will fix this error

compiled_sol = compile_source(contract_source_code, import_remappings=['=./pathDirectory', '-'])
Compiled source code

meherett avatar Aug 01 '18 06:08 meherett

You can use -rmp on the cmd to remap the path to node_modules:

python oyente.py -rmp openzeppelin-solidity=/full/path/to/node_modules/openzeppelin-solidity -s someContract.sol

If you import other files (e. g. stuff you wrote via import '../../blah') in your code you can use -ap to allow other paths, like:

python oyente.py -ap /full/path/to/the/dir/from/where/you/want/to/import/a/module -s someContract.sol

Ofc, you can also combine both.

mdix avatar Aug 30 '18 11:08 mdix

I'm following this tutorial! but got error -> "TokenCreate has not been deployed to detected network (network/artifact mismatch)"
while running command =>TokenCreate.deployed().then(inst => { crowdsale = inst } )
is any idea to resolve it ?

Sunandas1 avatar Sep 19 '18 06:09 Sunandas1

@HaleTom @chriseth try this => import "../../node_modules/zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol";

import "../../node_modules/zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol";
I hope it'll work for you!

Sunandas1 avatar Sep 19 '18 06:09 Sunandas1

@chriseth When I'm using solc to compile a contract which uses contracts from openzeppelin, I get Error: Source "openzeppelin-solidity/contracts/math/SafeMath.sol" not found: File outside of allowed directories.

JuliusBrain avatar Sep 28 '18 13:09 JuliusBrain

@JuliusBrain use solc --allow-paths

chriseth avatar Oct 01 '18 11:10 chriseth

what should I put in the --allow-paths to make it work? My project have typical truffle structure.

JuliusBrain avatar Oct 01 '18 11:10 JuliusBrain