Skip to content

FIX: Accept local HTTP URLs for CLI --start-server#2212

Merged
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-split-e-cli-start-server
Jul 17, 2026
Merged

FIX: Accept local HTTP URLs for CLI --start-server#2212
romanlutz merged 3 commits into
microsoft:mainfrom
romanlutz:romanlutz-split-e-cli-start-server

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

pyrit_scan --start-server previously refused to launch the bundled backend unless the resolved server URL was exactly the launcher default (http://localhost:8000). Anyone who set --server-url or a server.url config entry to a different local port got an error telling them to start the backend manually, even though the launcher can bind a different local host/port just fine.

This change relaxes the --start-server validation to accept any plain local HTTP URL. _resolve_server_url_async now parses the resolved URL and allows it when:

  • scheme is http
  • host is localhost or 127.0.0.1
  • there is no userinfo, path, query, or fragment

The parsed host and port are then forwarded to ServerLauncher.start_async(host=..., port=...), so --start-server honors a custom local port instead of silently ignoring it. Non-local or otherwise non-plain URLs (remote hosts, embedded credentials, paths) still get a clear error directing the user to start a remote backend separately.

Tests and Documentation

Unit tests in tests/unit/cli/test_pyrit_scan.py:

  • Added test_start_server_uses_custom_local_port, asserting the parsed host/port are forwarded to start_async (host="127.0.0.1", port=8765).
  • Retargeted the former default-mismatch test to test_start_server_refuses_remote_url to cover the rejection path.
  • Full file passes: 86 passed.

Ran JupyText on doc/scanner/1_pyrit_scan.py, which exercises pyrit_scan --start-server. I also verified end to end that --start-server now brings up the backend on a custom local URL/port (http://127.0.0.1:8137) that the previous code rejected, and stops cleanly via --stop-server.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 52d2518d-ebe5-4888-8189-6146b6503448
Comment thread pyrit/cli/pyrit_scan.py Outdated
Copilot AI and others added 2 commits July 16, 2026 15:08
Addresses review feedback on PR microsoft#2212: urllib.parse.urlparse is lightweight stdlib, so it belongs with the other top-level stdlib imports rather than being imported lazily inside functions. Removes the now-redundant function-local imports.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 259582f9-eccd-4fe6-93cb-21597e8bb54c
@romanlutz
romanlutz enabled auto-merge July 17, 2026 14:07
@romanlutz
romanlutz added this pull request to the merge queue Jul 17, 2026
Merged via the queue into microsoft:main with commit 7bd8f62 Jul 17, 2026
56 of 86 checks passed
@romanlutz
romanlutz deleted the romanlutz-split-e-cli-start-server branch July 17, 2026 14:39
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.

4 participants