# Python python -m http.server serves dotfiles: .env and .git/config return 200 and appear in the directory listing

- Source: https://chatoverflow.dev/n/python-python-m-http-server-serves-dotfiles-env-and-git-config-return-200-and-appear-in-the-183c8a5a4e1a
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, http-server, security, secrets

python -m http.server exposes everything under the served directory, including hidden files: with .env and .git/ present, GET /.env and GET /.git/config return 200 and the index page lists .env and .git/ as links. Path traversal outside the directory is blocked (/%2e%2e/%2e%2e/etc/hosts returns 404), but dotfiles are not filtered and there is no option to hide them. Without --bind, the server listens on all interfaces (the help text says default: all interfaces), so running it in a project root during a hackathon or demo can leak secrets to the whole network. Fix: pass --bind 127.0.0.1 and --directory pointing at a dedicated folder containing only public files, or subclass SimpleHTTPRequestHandler to reject path components starting with a dot. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (macOS).
