Skip to content

fix(security): sandbox repo verification in Docker to prevent RCE (#211) - #343

Open
arpita-1111 wants to merge 1 commit into
ionfwsrijan:mainfrom
arpita-1111:fix-211-sandbox-verify
Open

fix(security): sandbox repo verification in Docker to prevent RCE (#211)#343
arpita-1111 wants to merge 1 commit into
ionfwsrijan:mainfrom
arpita-1111:fix-211-sandbox-verify

Conversation

@arpita-1111

Copy link
Copy Markdown

Linked issue

Closes #211

What this PR does

Prevents Remote Code Execution (RCE) during repository verification by running all untrusted build/test/lint commands inside an isolated, disposable Docker container instead of directly on the host.

Previously, verify_repo() executed npm install, npm ci, npm run <script>, and pytest directly on the host machine using scripts defined in the uploaded repository's package.json. Since these repositories are untrusted, a malicious package.json script could execute arbitrary commands with full access to the host system, environment variables, and network.

Type of change

  • Bug fix
  • New feature
  • ML model / training pipeline
  • Refactor (no behaviour change)
  • Documentation
  • Tests only
  • Security fix

Stack affected

  • Backend
  • Frontend
  • Both

Changes

Backend

  • Added run_cmd_sandboxed() in backend/app/utils/exec.py, which runs a command inside an ephemeral Docker container instead of on the host.
  • Container is configured with:
    • --rm (self-destructs after running)
    • --user 1000:1000 (non-root)
    • --memory 512m and --cpus 1 (resource limits)
    • --pids-limit 256 (prevents fork bombs)
    • --network none by default (no network access)
    • --cap-drop ALL and --security-opt no-new-privileges (minimal Linux capabilities)
    • Repository mounted read/write only inside /workspace
  • Updated backend/app/sandbox/verify.py to use run_cmd_sandboxed() instead of run_cmd() for all commands that execute code from the uploaded repository (npm ci, npm install, npm run <script>, pytest).
  • Added an explicit check for Docker availability on the host; verification fails gracefully with a clear reason if Docker isn't installed, instead of silently running unsandboxed.
  • Left the final fallback check (python -c "print('verify: no tests detected')") unsandboxed since it only prints a fixed string and never touches repository content.

Proposed solution checklist (from issue)

  • Repository verification no longer executes untrusted scripts on the host system.
  • Verification runs inside an isolated container (Docker).
  • Sandbox enforces resource limits (CPU, memory).
  • Verification runs as a non-privileged user.
  • Network access is disabled by default.
  • Temporary verification environments are cleaned up after completion (--rm).
  • Existing verification functionality continues to work for legitimate repositories (pending live scan test).

Testing

How did you test this?

  • Installed Docker Desktop + WSL2 locally.
  • Ran docker run hello-world to confirm the Docker engine works.
  • Pulled the node:20-alpine and python:3.11-slim base images used by the sandbox.
  • Reviewed the code path manually to confirm run_cmd is no longer called for any repository-controlled command.

Checklist

  • Tested locally end-to-end (upload ZIP or GitHub URL → scan → findings returned correctly)
  • New ML model falls back gracefully when model file is absent
  • No new console.error or unhandled Python exceptions introduced
  • Added or updated tests where applicable
  • requirements.txt / package.json updated if new dependencies added
  • New model files (.pkl, .pt, etc.) are gitignored, not committed

Anything reviewers should focus on

Please confirm the resource limits (memory/CPU/pids) are reasonable for real-world verification workloads, and whether the sandbox should be given network access in specific cases (e.g., npm registry access during npm ci/npm install, which currently would fail with --network none). Happy to adjust based on maintainer guidance.

Screenshots (if UI changed)

N/A (backend-only change)

@github-actions

Copy link
Copy Markdown

🎉 Thank you @arpita-1111 for submitting a Pull Request!

We're excited to review your contribution.

✅ Before Review

  • Ensure all CI checks pass.
  • Complete the PR template.
  • Link the related issue.

Want faster reviews and contributor support?

Join our Discord community:

🔗 https://discord.gg/FcXuyw2Rs

Maintainers and mentors are active there and can help resolve blockers quickly.

Happy Contributing! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Prevent Remote Code Execution During Repository Verification by Sandboxing Build/Test Execution

1 participant