Skip to content

Fix and document --allow-paths #11688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 27, 2021
Merged

Fix and document --allow-paths #11688

merged 12 commits into from
Sep 27, 2021

Conversation

cameel
Copy link
Member

@cameel cameel commented Jul 24, 2021

Fixes #4623.
Fixes #10059.
Depends on #11686 (draft until that one's merged). Merged.

Cases that this PR fixes:

  • Neither allowed paths nor imports were being normalized before being compared. This broke:
    • Even very simple cases like whitelisting ../dir/ or ./dir/.
    • Non-normalized paths like dir1/../dir2/ dir1/../dir2/, dir1///dir2/.
    • Paths going beyond root like /../../dir/.
    • Symbolic links inside allowed paths were not resolved (only the ones in the imports were).
    • Whitelisted relative paths could only match imports using relative paths as well. Same for absolute paths.
    • All of this applied also to implicit whitelisting of directories due to being remapping targets or base path.
  • Base path was not being automatically whitelisted.
  • Empty paths would just whitelist the whole filesystem. There were several ways they could appear:
    • Given explicitly (e.g. --allow-paths=a/,,b/ or --allow-paths ""). These are now ignored.
    • Resulting from a remapping with an empty target (e.g. x=). These are now ignored. After Fix remappings with empty targets #11685 they will not be possible at all.
    • Resulting from a remapping to a file located at the VFS root (x=contract.sol). These now whitelist the working dir.
  • When a remapping target ended with /.., wrong directory was whitelisted (e.g. for x=/a/b/.. the whitelisted dir was /a/b/, not /a/).
    • Note that this is just a special case. In cases like x=/a/b/c.sol the right directory is actually /a/b/.

@cameel cameel self-assigned this Jul 24, 2021
@cameel cameel force-pushed the fix-and-document-allow-paths branch from 1f2d4ba to f43ff68 Compare July 24, 2021 03:19
@cameel cameel force-pushed the temporary-directory-extra-features branch from 7bca65c to cf1d71b Compare July 27, 2021 14:50
@cameel cameel force-pushed the fix-and-document-allow-paths branch 3 times, most recently from 6c3a611 to c707f13 Compare July 27, 2021 23:04
@cameel
Copy link
Member Author

cameel commented Jul 28, 2021

I resolved all the CI problems I had here except for one that's happening on Windows and this one is actually something that I cannot really fix on our side. I suspect it's a bug in boost::filesystem. I reported it in boostorg/filesystem#201.

The issue is basically that some paths that have redundant .. segments (e.g. /a/../a/b/) make weakly_canonical() throw on Windows. This was not a problem with --base-path because it requires the directory to actually exist. --allow-paths does not and I don't think it can - if it did, the targets of remappings would have to always exist on disk.

One workaround I can think of (other than waiting for this to be fixed in boost) would be to just require these paths not to have such redundant segments. Possibly only on Windows. The user can always avoid it by using a normalized path anyway.

@cameel cameel force-pushed the temporary-directory-extra-features branch from cf1d71b to 6feb4d5 Compare August 4, 2021 13:38
@cameel cameel force-pushed the fix-and-document-allow-paths branch 5 times, most recently from 7366309 to 50a5424 Compare August 5, 2021 16:29
@cameel cameel force-pushed the temporary-directory-extra-features branch from 6feb4d5 to 2b1eeec Compare August 5, 2021 17:11
@cameel cameel force-pushed the fix-and-document-allow-paths branch from 4318a62 to 50a5424 Compare August 5, 2021 19:08
@cameel
Copy link
Member Author

cameel commented Aug 5, 2021

This now passes all tests. I disabled tests that trigger the bug in boost (but only on Windows and on boost <= 1.76). The problem is still there until boost 1.77 gets released and we start using it for release binaries. And even then anyone who builds with older boost will run into it.

I think that's better than waiting until 1.77 is released and increasing the required version. Increasing it might cause problems for people who build on distros that do not have cutting-edge libraries and the bug is Windows-only anyway. To trigger it someone has to specifically use --allow-paths with a path to a directory that does not exist and is unnormalized in a very specific way - either enters and exits a directory (e.g. a/../a/b/) or goes beyond FS root and ends with .. (e.g. /../a/..). It also does not affect --base-path even though we normalize it before checking if the dir exists - that's because the bug is triggered only when we use weakly_canonical() to get symlinks resolved.

@cameel cameel force-pushed the fix-and-document-allow-paths branch from 50a5424 to 8c5047f Compare August 17, 2021 10:42
@cameel cameel force-pushed the temporary-directory-extra-features branch from 6b271b3 to acfa55b Compare August 20, 2021 18:04
@cameel cameel force-pushed the fix-and-document-allow-paths branch from 8c5047f to 11d7f09 Compare August 20, 2021 18:04
@cameel cameel force-pushed the temporary-directory-extra-features branch from acfa55b to 97c1983 Compare August 26, 2021 18:31
@cameel cameel force-pushed the fix-and-document-allow-paths branch from 11d7f09 to 1e9873e Compare August 26, 2021 18:31
@cameel cameel mentioned this pull request Aug 26, 2021
@cameel cameel force-pushed the temporary-directory-extra-features branch from 97c1983 to 92446cb Compare August 27, 2021 13:11
@cameel cameel force-pushed the fix-and-document-allow-paths branch from 1e9873e to e0b56b3 Compare August 27, 2021 13:30
@cameel cameel marked this pull request as ready for review August 27, 2021 13:31
@cameel
Copy link
Member Author

cameel commented Aug 27, 2021

#11686 approved, which now unblocks this PR.

Base automatically changed from temporary-directory-extra-features to develop August 27, 2021 14:06
@cameel cameel force-pushed the fix-and-document-allow-paths branch from ac7741f to 09925ba Compare September 23, 2021 12:01
@cameel
Copy link
Member Author

cameel commented Sep 23, 2021

Commits squashed.

@cameel cameel force-pushed the fix-and-document-allow-paths branch from a801c12 to d4d778d Compare September 27, 2021 11:18
@christianparpart
Copy link
Member

@cameel It's a huge PR, took a while, sorry. But I think that's all "right" :)

@cameel
Copy link
Member Author

cameel commented Sep 27, 2021

Thanks!

Well, it's big but it's either that or splitting it into multiple PRs that depend on each other and in the past I've seen that long chains of dependent PRs get pretty confusing. Still, not sure if this turned out better. I'll probably go back to splitting them next time because that way the parts are smaller and easier to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants