Skip to content

fix(compilers): sandbox native solc cwd to stop import path leaks - #2920

Open
0xoasis wants to merge 1 commit into
argotorg:stagingfrom
0xoasis:solc-sandbox-cwd-import-leak
Open

fix(compilers): sandbox native solc cwd to stop import path leaks#2920
0xoasis wants to merge 1 commit into
argotorg:stagingfrom
0xoasis:solc-sandbox-cwd-import-leak

Conversation

@0xoasis

@0xoasis 0xoasis commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Native solc --standard-json still resolves missing imports against the process cwd (allowed base path "."). From solc 0.8.8 onward, a user-supplied contract can import relative host files (e.g. ./.env, package.json); ParserError.formattedMessage then echoes file contents through compiler_error API responses.

  • solc <= 0.8.7 rejects the same imports as outside allowed directories (no content leak)
  • solc-js is unaffected (no filesystem import callback)
  • Production Linux prefers the native binary for solc >= 0.4.10, so this path is reachable in normal verification

Fix

  • Run native solc in an empty temp directory and delete it after compilation
  • Resolve the solc binary path before changing cwd so a relative solcRepo still works

Out of scope

Vyper is not changed. Probing vyper --standard-json (0.3.7 / 0.3.10 / 0.4.0) with HOST cwd bait files vs empty cwd showed:

  • no host-file content in compiler errors
  • HOST vs EMPTY behavior identical (ModuleNotFound / cannot locate interface)
  • so this is a solc-specific issue, not applied to Vyper

Validation

# from packages/compilers
npx mocha --exit --grep 'Should not leak host cwd files' test/solidityCompiler.spec.ts
npx mocha --exit test/solidityCompiler.spec.ts

@0xoasis 0xoasis changed the title fix(compilers): sandbox native solc/vyper cwd to stop import path leaks fix(compilers): sandbox compiler cwd and harden process/version safety Aug 6, 2026
@0xoasis
0xoasis force-pushed the solc-sandbox-cwd-import-leak branch from 989abb4 to 2615557 Compare August 6, 2026 10:33
@0xoasis 0xoasis changed the title fix(compilers): sandbox compiler cwd and harden process/version safety fix(compilers): sandbox native solc/vyper cwd to stop import path leaks Aug 6, 2026
0xoasis added a commit to 0xoasis/sourcify that referenced this pull request Aug 6, 2026
Add a useVyperCompiler smoke test that runs under the temp cwd sandbox and
asserts sourcify-vyper-* dirs are cleaned up. Existing vyper suite still
passes with the sandbox enabled.
Native solc --standard-json (notably >=0.8.8) resolves missing imports
against process cwd (allowed base path "."). User contracts can import
relative host files (e.g. ./.env, package.json); ParserError.formattedMessage
then echoes file contents through compiler_error API responses.

Run native solc in an empty temp directory and clean it up after compilation.
Resolve the solc binary path before changing cwd. Vyper is unchanged: probes
show standard-json does not load missing imports from cwd the same way.
@0xoasis
0xoasis force-pushed the solc-sandbox-cwd-import-leak branch from aad3920 to dba4d41 Compare August 6, 2026 12:07
@0xoasis 0xoasis changed the title fix(compilers): sandbox native solc/vyper cwd to stop import path leaks fix(compilers): sandbox native solc cwd to stop import path leaks Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant