Skip to content

Use form POST navigation for browser auth callback - #86

Closed
itssimon wants to merge 1 commit into
mainfrom
cli-auth-form-callback
Closed

itssimon wants to merge 1 commit into
mainfrom
cli-auth-form-callback

Conversation

@itssimon

Copy link
Copy Markdown
Member

Summary

Browser-based apitally auth fails in Safari: WebKit blocks any http:// subresource request from an https:// page as mixed content, including http://127.0.0.1 (WebKit bug 171934). Chrome also gates it behind a Local Network Access permission prompt. Top-level form navigations are not subject to mixed-content blocking, so the callback transport changes from a cross-origin fetch() to a form POST.

Requires the matching dashboard change to be deployed first.

Changes

  • The CLI opens {app_url}/cli-auth?callback_port=<port>&callback_mode=form.
  • The callback server accepts POST /callback with an application/x-www-form-urlencoded body containing api_key:
    • On success it responds 303 See Other with Location: {app_url}/cli-auth/success and stops listening.
    • A POST without api_key gets 400 Bad Request and the server keeps listening.
  • The request is read until the full body has arrived according to Content-Length (capped at 64 KiB), instead of a single read().
  • JSON body parsing and CORS handling (OPTIONS preflight, Access-Control-* headers) are removed.
  • Over SSH (SSH_CONNECTION or SSH_TTY set), the browser cannot reach the CLI's loopback server, so no callback server is started. The CLI opens {app_url}/cli-auth without query parameters and waits for the API key to be pasted. Without an interactive terminal it fails immediately, pointing to --api-key / APITALLY_API_KEY.
  • Adds form_urlencoded as a direct dependency (already in the lock file via mockito).

Testing

  • Updated test_run_with_callback for the form POST protocol, including headers and body arriving in separate writes.
  • Manual end-to-end check with curl against the built binary (303 + Location, 400 without api_key, auth.json written).
  • Manual check of both SSH paths (fails fast without a terminal; with a terminal no port is bound and the pasted key is saved).

Safari blocks fetch() from the https dashboard to http://127.0.0.1 as mixed content, and Chrome gates it behind a Local Network Access prompt. The dashboard now submits a top-level form POST to the callback server, which responds with a 303 redirect to the success page. Over SSH, the callback server is skipped and the user pastes the API key.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/auth.rs
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.71930% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.44%. Comparing base (03a79e7) to head (15eb969).

Files with missing lines Patch % Lines
src/auth.rs 87.71% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
- Coverage   91.67%   91.44%   -0.23%     
==========================================
  Files          13       13              
  Lines        2523     2538      +15     
==========================================
+ Hits         2313     2321       +8     
- Misses        210      217       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@itssimon itssimon closed this Oct 23, 2026
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.

1 participant