Skip to content

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

Open
romanlutz wants to merge 2 commits into
microsoft:mainfrom
romanlutz:romanlutz-split-e-cli-start-server
Open

FIX: Accept local HTTP URLs for CLI --start-server#2212
romanlutz wants to merge 2 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
# configured a different URL we can't honor it — refuse rather than
# silently start a server the user can't reach.
if base_url != DEFAULT_SERVER_URL:
from urllib.parse import urlparse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we want imports at top of file?

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
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