Skip to content

fix(cli): print the dashboard dev-server sign-in link on localhost - #473

Closed
surendraSinghKamboj wants to merge 2 commits into
blitzcrieg1:masterfrom
surendraSinghKamboj:fix/dashboard-dev-server-link-host
Closed

surendraSinghKamboj wants to merge 2 commits into
blitzcrieg1:masterfrom
surendraSinghKamboj:fix/dashboard-dev-server-link-host

Conversation

@surendraSinghKamboj

Copy link
Copy Markdown
Contributor

What and why

Refs #301. agentmetry dashboard --dev-server printed the sign-in link on 127.0.0.1. The cookie is host-only, so it was set for that site. The redirect then landed on localhost:3000, and the dev dashboard calls the API as localhost:8000. A browser treats 127.0.0.1 and localhost as different sites, so the cookie was never sent and every API call returned 401.

This takes the first fix option from the issue: in --dev-server mode a loopback sign-in link is printed (and opened) on localhost. Only the IPv4 loopback literal is rewritten. A custom AGENTMETRY_URL host is left alone, and without --dev-server nothing changes.

Not in this PR

The issue also asks the page to say "not signed in" on a 401 instead of waiting on "Checking sign-in...". That is a dashboard change, so I left it for a separate PR rather than mix a CLI fix with front-end work.

Checks

  • Three tests in tests/test_cli_commands.py (dev-server link on localhost, link unchanged without the flag, other hosts untouched). The first fails on master and passes with the change.
  • python -m pytest -q: 2959 passed, 19 skipped
  • python -m ruff check agentmetry tests passes
  • README collected-test count (2975 to 2978) and CHANGELOG updated
  • Frozen detection files untouched; no secrets in the diff

The sign-in cookie is host-only. The link was printed on 127.0.0.1, so the
cookie was set for that site, while the Next dev dashboard on localhost:3000
calls the API as localhost. A browser treats the two as different sites, so every
API call returned 401. In --dev-server mode a loopback link is now printed on
localhost. Any other host is left alone. Refs blitzcrieg1#301
CodeQL flagged the startswith() on a URL as incomplete URL substring
sanitization. Parse the link and assert scheme, host and port.
@blitzcrieg1

Copy link
Copy Markdown
Owner

Landed as rebased PR #474 after #472 (conflicts in CHANGELOG/README/test file resolved, README recounted to 2980 tests). Thanks @surendraSinghKamboj.

blitzcrieg1 added a commit that referenced this pull request Nov 25, 2026
… refs #301) (#474)

* test(cli): compare the parsed host instead of a URL prefix

CodeQL flagged the startswith() on a URL as incomplete URL substring
sanitization. Parse the link and assert scheme, host and port.

* fix(cli): print the dashboard dev-server sign-in link on localhost

The sign-in cookie is host-only. The link was printed on 127.0.0.1, so the
cookie was set for that site, while the Next dev dashboard on localhost:3000
calls the API as localhost. A browser treats the two as different sites, so every
API call returned 401. In --dev-server mode a loopback link is now printed on
localhost. Any other host is left alone. Refs #301

---------

Co-authored-by: Surendra Singh Kamboj <[email protected]>
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.

3 participants