1. Path containment: why `posixpath.normpath("//share")` escapes `join`
In Python, `posixpath.normpath("//server/share/file")` preserves the leading double slash per POSIX rules (whereas `///` collapses to `/`). If a path guard only checks for single-slash prefixes or `..` traversal, `//server/share/file` slips past and `posixpath.join("uploads", "//server/share/file")` drops `"uploads"` completely.
Reject any normalized path where `norm.startswith("/")` (which covers both `/` and `//`), contains backslashes, drive colons, or escapes upward with `..`.
import posixpath
def safe_upload_path(user_path: str) -> str | None:
norm = posixpath.normpath(user_path)
if norm.startswith("/") or "\\" in norm or norm == ".." or norm.startswith("../"):
return None
if len(norm) >= 2 and norm[1] == ":":
return None
return posixpath.join("uploads", norm)2. Redirects and unrewindable upload streams
When an HTTP client follows a 307 or 308 redirect, it must replay the request body from the starting offset captured before the first send. Recording the cursor after the first read rewinds to EOF, sending empty payloads with the old Content-Length.
If the body stream is not seekable, fail cleanly as unrewindable before sending a corrupt partial request—and on 301/302/303 redirects, switch to GET and clear the body and Content-Length permanently.
3. Connection pool keys must include TLS policy
Pooling connections solely by `(scheme, host, port)` means an earlier request with `verify=False` or a custom CA bundle leaves an idle socket in the pool. Updating settings on the session does not re-run the TLS handshake on an already open connection.
Include the effective verification mode and trust profile name in the connection pool key so verified requests never inherit unauthenticated sockets.
- Check `startswith("/")` after `posixpath.normpath` to catch `//` UNC paths.
- Record upload stream checkpoints before the initial read.
- Key TLS connection pools by `(origin, effective_tls_policy)`.
- Canonicalize query separators consistently between proxy and app.
Frequently asked questions
- Why does `posixpath.normpath("//server/share")` keep two leading slashes in Python?
- POSIX allows an implementation-defined meaning for exactly two leading slashes, so `posixpath.normpath` preserves `//` while collapsing three or more slashes (`///`) to `/`. Passing `//server/share` to `posixpath.join("uploads", path)` drops `"uploads"` unless you explicitly reject `path.startswith("/")`.
- What causes an unrewindable stream error during HTTP redirects?
- A 307 or 308 redirect preserves the POST/PUT method and must resend the request body. If the body stream is non-seekable (like a pipe or generator), it cannot be rewound to its initial offset and must abort instead of sending an empty body.
Further reading
Start with primary reports and documentation. Community discussions are discovery leads, not evidence on their own.