Skip to content

fix(security): fix sandbox bypass and panic when -sandbox and -python are both set - #222

Draft
neo-by-projectdiscovery[bot] wants to merge 1 commit into
mainfrom
security/fix-sandbox-python-bypass
Draft

neo-by-projectdiscovery[bot] wants to merge 1 commit into
mainfrom
security/fix-sandbox-python-bypass

Conversation

@neo-by-projectdiscovery

Copy link
Copy Markdown

Summary

Two related security issues in Python listing mode.

1. Runtime panic (DoS) — Sandbox + Python mode

File: pkg/httpserver/httpserver.go:65

When -sandbox is set, dir is a SandboxFileSystem, not http.Dir. The type assertion panics at server startup:
interface conversion: http.FileSystem is httpserver.SandboxFileSystem, not http.Dir

2. Sandbox bypass in Python listing mode

File: pkg/httpserver/pythonliststyle.go

Python mode constructed raw filesystem paths via os.Stat / http.ServeFile directly, completely bypassing SandboxFileSystem's dot-file filter, symlink rejection, and containment checks.

Fix

  • Changed PythonStyle to accept http.FileSystem (not http.Dir)
  • Replaced raw path construction with fs.Open() so SandboxFileSystem.Open() is always exercised
  • Delegate serving to http.FileServer(root)

Tests added (both fail without fix)

  • TestPythonStyleAcceptFileSystem
  • TestNewServerSandboxPythonNoPanic

… are both set

PythonStyle previously accepted http.Dir via a type assertion:

    httpHandler = PythonStyle(dir.(http.Dir))

When -sandbox is also set, dir is a SandboxFileSystem, not http.Dir.
The assertion panics at startup:

    interface conversion: http.FileSystem is httpserver.SandboxFileSystem, not http.Dir

Beyond the crash, Python mode also bypassed SandboxFileSystem's
containment checks (dot-file filter, symlink rejection, single-level
glob) even when -sandbox was not set, because it built raw OS paths
via filepath.Join+os.Stat instead of using the FileSystem's Open().

Fix:
- Change PythonStyle to accept http.FileSystem (not http.Dir)
- Replace os.Stat + raw filepath.Join path construction with fs.Open()
  so SandboxFileSystem's Open() is always consulted
- Delegate actual file/directory serving to http.FileServer(root)
  which also uses the FileSystem

Regression tests: TestPythonStyleAcceptFileSystem,
                  TestNewServerSandboxPythonNoPanic
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.

0 participants