fix: add timeout and scheme validation when fetching remote topologies - #3767
Conversation
|
Nice fixes, thank you. However, being of the "every constant eventually becomes a variable" persuasion, it would be nice to have both parameters (timeout, allowed URL schemas) as variables defined in system settings, which creates a bit of a conundrum as we have to read the topology before we can download the topology. I will add that bit to the code (might take a few days to find the time to do it) and then merge this. Thanks again, Ivan |
ipspace
left a comment
There was a problem hiding this comment.
Thanks again. I added the configurable parameters and documentation. Merging.
There was a problem hiding this comment.
Pull request overview
This PR hardens remote-topology fetching in netlab create/netlab up by adding URL-scheme allowlisting and a bounded HTTP request timeout, reducing the risk of hanging workers (notably in the netlab api job queue path).
Changes:
- Add URL scheme validation (allow
http/https) before downloading remote topologies. - Add a configurable
requests.get(..., timeout=...)for remote topology downloads. - Document the scheme restriction and how to change allowed schemes via system defaults.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
netsim/defaults/netlab.yml |
Introduces default download settings (timeout + allowed schemes) for remote topology fetches. |
netsim/cli/create.py |
Implements scheme validation and request timeout in http_fetch_content(). |
docs/netlab/create.md |
Documents the HTTP/HTTPS-only behavior and the defaults knob to alter allowed schemes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
http_fetch_content()innetsim/cli/create.pydownloads a remote topology withrequests.get(url)using no timeout and without validating the URL scheme. This function is reached whenever a topology is supplied as a URL (netlab up <url>/netlab create <url>), and it is also reachable from the built-innetlab apiserver: aPOST /jobsrequest with atopologyUrlfield routes intonetlab create/netlab up, which call this function.Two problems:
No request timeout.
requests.get()defaults to blocking forever. In thenetlab apiserver the fetch runs inside a worker that holds the globalRUN_LOCK(seenetsim/cli/api.py), so a single request pointing at an unresponsive or slow-loris host makes the worker hang indefinitely and permanently wedges the job queue. Basic auth on the API server is optional and off by default, so this is triggerable without credentials.No URL-scheme validation. The URL is passed straight to
requestswith no restriction, so unexpected schemes (for examplefile://when a filesystem transport adapter is mounted) are accepted rather than rejected up front.Fix
http/httpsbefore the request is made.HTTP_FETCH_TIMEOUT(20s) to therequests.get()call so a stuck download fails cleanly instead of blocking forever.The change is confined to
http_fetch_content()and preserves existing behavior for validhttp/httpstopology URLs (including the GitHub?raw=truerewrite).Testing
python3 -c "import ast; ast.parse(open('netsim/cli/create.py').read())"passes.http/httpsURLs follow the unchanged download path; non-http(s) URLs now exit with a clear error; an unresponsive host now fails after the timeout instead of hanging.