console: approve a CLI login from the code in its link
GET /auth/cli?code=X, signed in, now resolves the code (Paul's R1, spec section 3): a live login is described (code, self-reported label, address with GeoIP place and attribution, started, expiry, the check question) with Approve and That wasn't me. Stale or unknown codes say so and show the typed-code box. The GET lookup budget (lookAddr/lookIP) is checked before resolving and spent only on misses; past it every code gets the same 429. The decision budget is never touched from GET. New strings are drafts in agentLoginCopy pending copy review; the signed-out banner moves to cli.signin_prompt because signinCopy is pinned to approved copy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+370
−83
internal/console/authcli.go+91 −31internal/console/authcli_test.go+197 −32internal/console/claim_invariant_probes_read_test.go+1 −1internal/console/cliplace.go+48 −0internal/console/emailsignin_test.go+1 −1internal/console/emailstepup_test.go+1 −1internal/console/signincopy.go+22 −0internal/console/templates/cli_approve.html+9 −17
Intent
Attributed to this commit: 84.8 g CO₂e (6,326,494 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-agent-login-link, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/authcli.go b/internal/console/authcli.go| index f2040485c..896dc947e 100644 |
| --- a/internal/console/authcli.go |
| +++ b/internal/console/authcli.go |
| @@ -1547,16 +1547,16 @@ type methodRow struct { |
| // shared chrome ("top"/"bottom") keeps working unchanged. |
| type cliPage struct { |
| page |
| - Code string // the code the human typed, echoed back into the form |
| - // LinkCode is the code carried by the ?code= in the URL they followed. |
| - // Shown ONLY as something to check against the terminal's screen — never |
| - // prefilled into the form, never resolved. See handleCLIApprovePage. |
| - LinkCode string |
| - Console string // this deployment's origin — the -console the CLI needs |
| - Request *CLIAuthRequest |
| - Tokens []CLIToken |
| - Methods []methodRow |
| - Days int |
| + Code string // the code the human typed, echoed back into the form |
| + Console string // this deployment's origin — the -console the CLI needs |
| + Request *CLIAuthRequest |
| + // Place is where Request dialled from, by GeoIP (cliplace.go), and |
| + // Started how long ago it began; both only beside a described Request. |
| + Place cliPlace |
| + Started time.Duration |
| + Tokens []CLIToken |
| + Methods []methodRow |
| + Days int |
| // ServiceAccounts maps a service credential's account id to that |
| // account's sqid, so the read-only mirror can say WHERE a row is managed |
| // and link there. Built here rather than hung on CLIToken because the |
| @@ -1571,6 +1571,30 @@ func (p cliPage) MethodsText(id string) string { |
| return copyText("methods."+id, "address", p.Address) |
| } |
| +// CLIText is the approval page's copy by id (signincopy.go). |
| +func (p cliPage) CLIText(id string) string { return copyText(id) } |
| + |
| +// Lede names what is asking and the console it is asking to use, by the |
| +// same name the page's header gives it (Brand, filled by chrome). |
| +func (p cliPage) Lede() string { |
| + label := "" |
| + if p.Request != nil { |
| + label = p.Request.Label |
| + } |
| + if label == "" { |
| + label = copyText("cli.unnamed") |
| + } |
| + return copyText("cli.lede", "label", label, "console", p.Brand) |
| +} |
| + |
| +// StartedText says how long ago the described login began. |
| +func (p cliPage) StartedText() string { |
| + if p.Started < time.Minute { |
| + return copyText("cli.started_now") |
| + } |
| + return copyText("cli.started", "ago", humanAge(p.Started)) |
| +} |
| + |
| func (s *Server) renderCLI(w http.ResponseWriter, status int, name string, p cliPage) { |
| s.chrome(&p.page) |
| _ = s.writeTemplate(w, status, name, p) |
| @@ -1578,35 +1602,71 @@ func (s *Server) renderCLI(w http.ResponseWriter, status int, name string, p cli |
| // handleCLIApprovePage is where the printed link lands. A signed-out visitor |
| // gets the front page, asked to sign in, with next set back here (spec 8). A |
| -// code-shaped ?code= rides along in next only so it can be shown again for |
| -// comparison; the console never carries a pending approval through an |
| -// authentication it has not finished. |
| +// code-shaped ?code= rides along in next; the console never carries a |
| +// pending approval through an authentication it has not finished. |
| +// |
| +// SIGNED IN, IT ACTS ON ?code=: it looks the code up and, for a live login, |
| +// describes it and offers Approve. This reverses the old rule that nothing is |
| +// approved by following a link (Paul's ruling R1, agent login by link spec |
| +// §3). An agent can relay a link but cannot make a person type a code, and |
| +// the check that matters, "does your agent show this code?", is one the |
| +// person can still make by eye. GitHub and Google accept the same risk. What |
| +// stands between a phished link and a credential: |
| +// |
| +// - a session: a signed-out visitor gets the front page and nothing more; |
| +// - Approve and Deny are POSTs carrying the session's CSRF token, so this |
| +// GET only ever describes; |
| +// - Approve needs a fresh step-up (requireFreshAuth); Deny stays ungated; |
| +// - the page shows the code, the self-reported label with its caveat, |
| +// where the login dialled from and when, and asks the check question; |
| +// - issuance tells the person (notifyCLIIssued), "That wasn't me" kills |
| +// the request, and a request lives only CLIAuthTTL; |
| +// - a GET lookup budget per signed-in address and per IP, checked BEFORE |
| +// the lookup and spent only by lookups that find nothing, so past it a |
| +// valid code gets the same 429 as a wrong one. It is separate from the |
| +// decision budget the POSTs spend: a top-level navigation carries no |
| +// CSRF token, so forced GETs must never lock a person out of Approve. |
| // |
| -// IT DELIBERATELY DOES NOT ACT ON ?code=. Not to resolve it, not to look it |
| -// up, and above all not to render an Approve button for it. A prefilled code |
| -// that arrives one click from approval is the device-code phishing attack that |
| -// has been run at scale against Microsoft tenants: the attacker starts the |
| -// flow, sends the victim the ready-made link with a plausible pretext, and one |
| -// click binds a 90-day credential — held by the attacker — to the victim's |
| -// identity. Requiring the code to be TYPED is what breaks it: to type it you |
| -// have to be reading it off a terminal you started, and a code you cannot see |
| -// is one you cannot transcribe. The value from the URL is shown only as |
| -// something to check against your screen, never as something to submit. |
| +// Looking up writes nothing but that budget. |
| func (s *Server) handleCLIApprovePage(w http.ResponseWriter, r *http.Request) { |
| + code := NormalizeUserCode(r.URL.Query().Get("code")) |
| + codeShaped := len(code) == userCodeLen+1 |
| addr, raw, ok := s.session(r) |
| if !ok { |
| next := "/auth/cli" |
| - if c := NormalizeUserCode(r.URL.Query().Get("code")); len(c) == userCodeLen+1 { |
| - next += "?code=" + url.QueryEscape(c) |
| + if codeShaped { |
| + next += "?code=" + url.QueryEscape(code) |
| } |
| - s.renderHome(w, r, homeForm{Next: next, Banner: copyText("home.cli_prompt")}) |
| + s.renderHome(w, r, homeForm{Next: next, Banner: copyText("cli.signin_prompt")}) |
| return |
| } |
| - p := cliPage{page: page{Title: "Approve a terminal", Address: addr, CSRF: raw}, |
| + p := cliPage{page: page{Title: copyText("cli.title"), Address: addr, CSRF: raw}, |
| Days: int(CLITokenTTL / (24 * time.Hour))} |
| - // Echoed for comparison only — no store lookup, which also means this page |
| - // is not an oracle for enumerating live codes. |
| - p.LinkCode = NormalizeUserCode(r.URL.Query().Get("code")) |
| + switch { |
| + case code == "": |
| + // The bare page: the typed-code box, nothing to look up. |
| + case !codeShaped: |
| + // No code has this shape, so there is nothing to look up and nothing |
| + // to guess: say the link's code is no good. |
| + p.Error = copyText("cli.link_unknown") |
| + default: |
| + now := time.Now() |
| + ip := s.clientIP(r) |
| + if !s.cliBudgetOpen(s.cli.lookAddr, s.cli.lookIP, addr, ip, now) { |
| + s.renderMessage(w, r, http.StatusTooManyRequests, "Too many attempts", |
| + "Too many bad login codes. Wait a minute, then try again.") |
| + return |
| + } |
| + req, err := s.store.CLIAuthByUserCode(code, now) |
| + if err != nil { |
| + s.cliBudgetSpend(s.cli.lookAddr, s.cli.lookIP, addr, ip, now) |
| + p.Error = copyText("cli.link_unknown") |
| + break |
| + } |
| + p.Request = req |
| + p.Place = s.cliPlaceFor(req.RemoteAddr) |
| + p.Started = now.Sub(req.CreatedAt) |
| + } |
| s.renderCLI(w, http.StatusOK, "cli_approve", p) |
| } |
| @@ -1649,7 +1709,7 @@ func (s *Server) handleCLIApprove(w http.ResponseWriter, r *http.Request) { |
| code := NormalizeUserCode(r.FormValue("code")) |
| action := r.FormValue("action") |
| now := time.Now() |
| - p := cliPage{page: page{Title: "Approve a terminal", Address: addr, CSRF: raw}, |
| + p := cliPage{page: page{Title: copyText("cli.title"), Address: addr, CSRF: raw}, |
| Code: code, Days: int(CLITokenTTL / (24 * time.Hour))} |
| // Wrong codes are counted wherever a code is resolved, and against both |
diff --git a/internal/console/authcli_test.go b/internal/console/authcli_test.go| index dbd54d3c6..12bd7935f 100644 |
| --- a/internal/console/authcli_test.go |
| +++ b/internal/console/authcli_test.go |
| @@ -7,12 +7,14 @@ import ( |
| "io" |
| "net/http" |
| "net/url" |
| + "os" |
| "path/filepath" |
| "strconv" |
| "strings" |
| "testing" |
| "time" |
| + "github.com/carlosframework/platform/internal/geo" |
| "github.com/carlosframework/platform/internal/svcrole" |
| ) |
| @@ -101,8 +103,9 @@ func TestCLILoginEndToEnd(t *testing.T) { |
| t.Fatalf("poll before approval = %v, want pending", poll) |
| } |
| - // Typing the code is what produces a described terminal — following a |
| - // link never does (see TestCLIApprovalPageNeverApprovesFromALink). |
| + // Typing the code still produces a described terminal (the fallback for a |
| + // code read off a screen); following the link does too (see |
| + // TestCLIApprovalPageResolvesTheLinkCode). |
| csrf := sessionToken(t, fx, browser) |
| code, _, body := postForm(t, browser, fx.ts.URL+"/auth/cli/approve", |
| url.Values{"code": {userCode}, "action": {"continue"}, "csrf": {csrf}}) |
| @@ -197,50 +200,212 @@ func TestCLILoginEndToEnd(t *testing.T) { |
| } |
| } |
| -// The device-code phishing attack, refused. An attacker starts a login, sends |
| -// the victim the ready-made verification_uri_complete with a pretext, and the |
| -// victim clicks it while signed in. If that page rendered an Approve button |
| -// for the attacker's code, one click would bind a 90-day credential — held by |
| -// the attacker — to the victim's identity. This is the campaign that has been |
| -// run against Microsoft tenants at scale, so the page must not do it: no |
| -// lookup, no description, no Approve button, and an EMPTY input the human has |
| -// to type into off their own screen. |
| -func TestCLIApprovalPageNeverApprovesFromALink(t *testing.T) { |
| +// The link an agent prints carries its code, and following it while signed |
| +// in now describes that login and offers Approve (spec §3, Paul's R1): the |
| +// person checks the code against the one their agent shows. GET only looks, |
| +// so the login is still pending afterwards. |
| +func TestCLIApprovalPageResolvesTheLinkCode(t *testing.T) { |
| fx := newConsoleFixture(t) |
| - victim := newBrowser(t) |
| - signUp(t, fx, victim, "code-phish") |
| - |
| - // The attacker's terminal, started from somewhere else entirely. |
| - _, start := postJSON(t, fx.ts.URL+"/auth/cli/start", map[string]string{"label": "attacker@vps"}, "") |
| + browser := newBrowser(t) |
| + signUp(t, fx, browser, "code-link") |
| + _, start := postJSON(t, fx.ts.URL+"/auth/cli/start", map[string]string{"label": "Claude Code on box"}, "") |
| userCode := str(t, start, "user_code") |
| - status, _, body := get(t, victim, fx.ts.URL+"/auth/cli?code="+url.QueryEscape(userCode)) |
| + status, _, body := get(t, browser, fx.ts.URL+"/auth/cli?code="+url.QueryEscape(userCode)) |
| if status != http.StatusOK { |
| t.Fatalf("approval page = %d", status) |
| } |
| - // The code is echoed to be CHECKED against the terminal's screen… |
| - if !strings.Contains(body, userCode) { |
| - t.Fatalf("the page hides the code the link carried, so it cannot be checked:\n%s", body) |
| - } |
| - // …but never described (that would also make this an enumeration oracle)… |
| - if strings.Contains(body, "attacker@vps") { |
| - t.Fatalf("the page resolved a code from a URL:\n%s", body) |
| - } |
| - // …and never one click from approval. |
| - if strings.Contains(body, `value="approve"`) { |
| - t.Fatalf("the page rendered an Approve button for a code from a URL:\n%s", body) |
| + for _, want := range []string{userCode, "Claude Code on box", `value="approve"`, `value="deny"`, |
| + esc(copyText("cli.check")), esc(copyText("cli.not_me")), |
| + esc(copyText("cli.lede", "label", "Claude Code on box", "console", fx.srv.brandName()))} { |
| + if !strings.Contains(body, want) { |
| + t.Fatalf("approval page missing %q:\n%s", want, body) |
| + } |
| } |
| - if strings.Contains(body, `name="code" value="`+userCode) { |
| - t.Fatalf("the page prefilled the typed-code field from the URL:\n%s", body) |
| + // The code is the one the approve form submits, not one typed again. |
| + if !strings.Contains(body, `name="code" value="`+userCode+`"`) { |
| + t.Fatalf("the approve form does not carry the link's code:\n%s", body) |
| } |
| - // The request really is still pending — the page did not consume it, it |
| - // simply refused to act on it. |
| _, poll := postJSON(t, fx.ts.URL+"/auth/cli/poll", map[string]string{"device_code": str(t, start, "device_code")}, "") |
| if str(t, poll, "status") != CLIAuthPending { |
| t.Fatalf("poll = %v, want the request untouched and pending", poll) |
| } |
| } |
| +// A link whose code is no longer pending (approved, denied, or never issued) |
| +// says so and offers the typed-code box, never an Approve button. |
| +func TestCLIApprovalPageStaleCodeShowsTheBox(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + browser := newBrowser(t) |
| + signUp(t, fx, browser, "code-stale") |
| + now := time.Now() |
| + approved, _, err := fx.st.NewCLIAuth("approved@box", "192.0.2.1", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.ApproveCLIAuth(approved, "paul@keymail.dev", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + denied, _, err := fx.st.NewCLIAuth("denied@box", "192.0.2.1", now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.DenyCLIAuth(denied, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + for name, code := range map[string]string{"approved": approved, "denied": denied, "unknown": "ZZZZ-ZZZZ"} { |
| + status, _, body := get(t, browser, fx.ts.URL+"/auth/cli?code="+url.QueryEscape(code)) |
| + if status != http.StatusOK { |
| + t.Fatalf("%s: approval page = %d", name, status) |
| + } |
| + if strings.Contains(body, `value="approve"`) { |
| + t.Fatalf("%s: a stale code rendered an Approve button:\n%s", name, body) |
| + } |
| + if !strings.Contains(body, `name="code" value=""`) || !strings.Contains(body, `value="continue"`) { |
| + t.Fatalf("%s: no typed-code box:\n%s", name, body) |
| + } |
| + if !strings.Contains(body, esc(copyText("cli.link_unknown"))) { |
| + t.Fatalf("%s: the page does not say the link's code is spent:\n%s", name, body) |
| + } |
| + if strings.Contains(body, name+"@box") { |
| + t.Fatalf("%s: a stale code was described:\n%s", name, body) |
| + } |
| + } |
| +} |
| + |
| +// GET lookups that find nothing spend their own budget, and past it a VALID |
| +// code is refused exactly like a wrong one: the page is not an oracle. |
| +func TestCLIApprovalPageLookupBudget(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + browser := newBrowser(t) |
| + signUp(t, fx, browser, "code-look") |
| + refusedBody := "" |
| + for i := 0; i < cliGuessBurst+3 && refusedBody == ""; i++ { |
| + status, _, body := get(t, browser, fx.ts.URL+"/auth/cli?code=ZZZZ-ZZZZ") |
| + switch status { |
| + case http.StatusOK: |
| + case http.StatusTooManyRequests: |
| + refusedBody = body |
| + default: |
| + t.Fatalf("bad code %d = %d", i, status) |
| + } |
| + } |
| + if refusedBody == "" { |
| + t.Fatalf("bad link codes were never rate-limited in %d lookups", cliGuessBurst+3) |
| + } |
| + _, start := postJSON(t, fx.ts.URL+"/auth/cli/start", map[string]string{"label": "look@laptop"}, "") |
| + userCode := str(t, start, "user_code") |
| + status, _, body := get(t, browser, fx.ts.URL+"/auth/cli?code="+url.QueryEscape(userCode)) |
| + if status != http.StatusTooManyRequests { |
| + t.Fatalf("valid code past the lookup budget = %d, want 429", status) |
| + } |
| + if strings.Contains(body, "look@laptop") || strings.Contains(body, userCode) { |
| + t.Fatalf("a refused lookup described the login:\n%s", body) |
| + } |
| + if body != refusedBody { |
| + t.Fatalf("the refusal differs for a valid code:\nbad:\n%s\nvalid:\n%s", refusedBody, body) |
| + } |
| + // The bare page, with no code to look up, is never refused. |
| + if status, _, _ := get(t, browser, fx.ts.URL+"/auth/cli"); status != http.StatusOK { |
| + t.Fatalf("bare approval page past the lookup budget = %d, want 200", status) |
| + } |
| +} |
| + |
| +// A signed-in top-level navigation carries no CSRF token, so forcing GETs to |
| +// bad codes must never spend the decision budget: Approve still works. |
| +func TestCLIForcedLookupsLeaveDecisionsWorking(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + browser := newBrowser(t) |
| + signUp(t, fx, browser, "code-forced") |
| + limited := false |
| + for i := 0; i < cliGuessBurst+3; i++ { |
| + if status, _, _ := get(t, browser, fx.ts.URL+"/auth/cli?code=ZZZZ-ZZZZ"); status == http.StatusTooManyRequests { |
| + limited = true |
| + } |
| + } |
| + if !limited { |
| + t.Fatal("precondition: the lookup budget was never spent") |
| + } |
| + _, start := postJSON(t, fx.ts.URL+"/auth/cli/start", map[string]string{"label": "forced@laptop"}, "") |
| + code, _, body := postGated(t, fx, browser, fx.ts.URL+"/auth/cli/approve", |
| + url.Values{"code": {str(t, start, "user_code")}, "action": {"approve"}, "csrf": {sessionToken(t, fx, browser)}}) |
| + if code != http.StatusOK || !strings.Contains(body, "Approved") { |
| + t.Fatalf("approve after forced lookups = %d:\n%s", code, body) |
| + } |
| +} |
| + |
| +// dbipReader is the apigeo tests' GeoIP2-City fixture relabelled as a DB-IP |
| +// database: the metadata's database_type is rewritten in place (same length), |
| +// so the source the snapshot reports is one AttributionFor credits. |
| +func dbipReader(t *testing.T) *geo.Swappable { |
| + t.Helper() |
| + raw, err := os.ReadFile("../geo/testdata/GeoIP2-City-Test.mmdb") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + meta := bytes.LastIndex(raw, []byte("\xab\xcd\xefMaxMind.com")) |
| + if meta < 0 || bytes.Count(raw[meta:], []byte("GeoIP2-City")) != 1 { |
| + t.Fatal("fixture metadata not as expected") |
| + } |
| + raw = append(raw[:meta:meta], bytes.Replace(raw[meta:], []byte("GeoIP2-City"), []byte("DBIP-City-L"), 1)...) |
| + path := filepath.Join(t.TempDir(), "dbip.mmdb") |
| + if err := os.WriteFile(path, raw, 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + db, err := geo.OpenMMDB(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + sw := geo.NewSwappable() |
| + sw.Swap(db) |
| + t.Cleanup(func() { sw.Swap(nil) }) |
| + return sw |
| +} |
| + |
| +// Where a login dialled from: the platform GeoIP answer, with the credit its |
| +// database's licence asks for from the same snapshot, and nothing at all |
| +// when there is no answer. |
| +func TestCLIPlaceAttribution(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + if got := fx.srv.cliPlaceFor("81.2.69.142"); got != (cliPlace{}) { |
| + t.Fatalf("nil reader = %+v, want nothing", got) |
| + } |
| + empty := geo.NewSwappable() |
| + fx.srv.cfg.GeoIPReader = empty |
| + if got := fx.srv.cliPlaceFor("81.2.69.142"); got != (cliPlace{}) { |
| + t.Fatalf("empty reader = %+v, want nothing", got) |
| + } |
| + fx.srv.cfg.GeoIPReader = dbipReader(t) |
| + want := cliPlace{Text: "GB-ENG, GB", Attribution: "IP Geolocation by DB-IP", AttributionURL: "https://db-ip.com"} |
| + for _, addr := range []string{"81.2.69.142", "81.2.69.142:52114"} { |
| + if got := fx.srv.cliPlaceFor(addr); got != want { |
| + t.Fatalf("cliPlaceFor(%q) = %+v, want %+v", addr, got, want) |
| + } |
| + } |
| + for _, addr := range []string{"10.0.0.1", "", "not-an-ip"} { |
| + if got := fx.srv.cliPlaceFor(addr); got != (cliPlace{}) { |
| + t.Fatalf("cliPlaceFor(%q) = %+v, want nothing", addr, got) |
| + } |
| + } |
| + |
| + // And the page shows it beside the address. |
| + browser := newBrowser(t) |
| + signUp(t, fx, browser, "code-place") |
| + userCode, _, err := fx.st.NewCLIAuth("place@laptop", "81.2.69.142", time.Now()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + status, _, body := get(t, browser, fx.ts.URL+"/auth/cli?code="+url.QueryEscape(userCode)) |
| + if status != http.StatusOK { |
| + t.Fatalf("approval page = %d", status) |
| + } |
| + for _, want := range []string{"81.2.69.142", "GB-ENG, GB", `<a href="https://db-ip.com">IP Geolocation by DB-IP</a>`} { |
| + if !strings.Contains(body, want) { |
| + t.Fatalf("approval page missing %q:\n%s", want, body) |
| + } |
| + } |
| +} |
| + |
| // Issuing a credential tells the human, in the inbox their identity is |
| // anchored to. Every other defence here is preventive; this is the one that |
| // makes a phished approval detectable afterwards. |
diff --git a/internal/console/claim_invariant_probes_read_test.go b/internal/console/claim_invariant_probes_read_test.go| index 93b667531..c0ffa21ab 100644 |
| --- a/internal/console/claim_invariant_probes_read_test.go |
| +++ b/internal/console/claim_invariant_probes_read_test.go |
| @@ -217,7 +217,7 @@ var claimReadProbes = map[string]claimProbe{ |
| "route GET /a/{sqid}/{$}": claimPageRead(nil, "/a/bab/", "kass"), |
| "route GET /accounts/new": claimPageRead(nil, "/accounts/new", "<h1>New account</h1>"), |
| "route GET /settings": claimPageRead(nil, "/settings", "<h1>Your settings</h1>"), |
| - "route GET /auth/cli": claimPageRead(nil, "/auth/cli", "<h1>Approve a terminal</h1>"), |
| + "route GET /auth/cli": claimPageRead(claimDeviceLogin, "/auth/cli?code=<usercode>", "<h1>Approve a sign-in</h1>", "census terminal", `value="approve"`), |
| "route GET /invite/{token}": claimInvitePageProbe(), |
| "route GET /fleet": claimPageRead(nil, "/fleet", "<h1>Dashboard</h1>"), |
| "route GET /fleet/activity": claimPageRead(nil, "/fleet/activity", "<h1>Activity</h1>"), |
diff --git a/internal/console/cliplace.go b/internal/console/cliplace.go| new file mode 100644 |
| index 000000000..57405d503 |
| --- /dev/null |
| +++ b/internal/console/cliplace.go |
| @@ -0,0 +1,48 @@ |
| +package console |
| + |
| +// The approval page's location line (agent login by link, spec §3): where a |
| +// login dialled from, as the platform GeoIP answer gives it. The answer has |
| +// no city, so this is "Subdivision, Country" or "Country"; with no answer it |
| +// is empty and the page shows the address alone. |
| + |
| +import ( |
| + "net" |
| + |
| + "github.com/carlosframework/platform/internal/geoip" |
| +) |
| + |
| +// cliPlace is the location beside a login's address, with the credit the |
| +// answering database's licence asks for when it asks for one. |
| +type cliPlace struct{ Text, Attribution, AttributionURL string } |
| + |
| +// cliPlaceFor looks remoteAddr up once. The place, its source and its |
| +// attribution all come from that one snapshot, so a database swap between |
| +// the lookup and the render can never credit the wrong database (geoip spec |
| +// §5.4). remoteAddr is a stored CLIAuthRequest.RemoteAddr, "ip" or |
| +// "ip:port"; anything else, a nil or empty reader, and a miss all answer the |
| +// zero cliPlace. The address is never logged. |
| +func (s *Server) cliPlaceFor(remoteAddr string) cliPlace { |
| + if s.cfg.GeoIPReader == nil { |
| + return cliPlace{} |
| + } |
| + host := remoteAddr |
| + if h, _, err := net.SplitHostPort(remoteAddr); err == nil { |
| + host = h |
| + } |
| + ip := net.ParseIP(host) |
| + if ip == nil { |
| + return cliPlace{} |
| + } |
| + a := geoip.FromSnapshot(s.cfg.GeoIPReader.Lookup(ip)) |
| + if a.State != geoip.StateHit || a.Country == "" { |
| + return cliPlace{} |
| + } |
| + p := cliPlace{Text: a.Country} |
| + if a.Subdivision != "" { |
| + p.Text = a.Subdivision + ", " + a.Country |
| + } |
| + if at, ok := geoip.AttributionFor(a.Source); ok { |
| + p.Attribution, p.AttributionURL = at.Text, at.URL |
| + } |
| + return p |
| +} |
diff --git a/internal/console/emailsignin_test.go b/internal/console/emailsignin_test.go| index 71271e268..22b8178bd 100644 |
| --- a/internal/console/emailsignin_test.go |
| +++ b/internal/console/emailsignin_test.go |
| @@ -616,7 +616,7 @@ func TestInvitePageSignedOutPrefills(t *testing.T) { |
| func TestCLIPageSignedOutBanner(t *testing.T) { |
| fx := newConsoleFixture(t) |
| status, _, body := get(t, newBrowser(t), fx.ts.URL+"/auth/cli") |
| - if status != http.StatusOK || !strings.Contains(body, esc(copyText("home.cli_prompt"))) || |
| + if status != http.StatusOK || !strings.Contains(body, esc(copyText("cli.signin_prompt"))) || |
| !strings.Contains(body, `name="next" value="/auth/cli"`) || !strings.Contains(body, `action="/auth/continue"`) { |
| t.Fatalf("signed-out /auth/cli = %d:\n%s", status, body) |
| } |
diff --git a/internal/console/emailstepup_test.go b/internal/console/emailstepup_test.go| index e12257250..28902cfd9 100644 |
| --- a/internal/console/emailstepup_test.go |
| +++ b/internal/console/emailstepup_test.go |
| @@ -401,7 +401,7 @@ func TestCLILoginByEmailUserOneEmail(t *testing.T) { |
| c := newBrowser(t) |
| status, _, body := get(t, c, fx.ts.URL+"/auth/cli") |
| - if status != http.StatusOK || !strings.Contains(body, esc(copyText("home.cli_prompt"))) || |
| + if status != http.StatusOK || !strings.Contains(body, esc(copyText("cli.signin_prompt"))) || |
| !strings.Contains(body, `name="next" value="/auth/cli"`) { |
| t.Fatalf("signed-out /auth/cli = %d:\n%s", status, body) |
| } |
diff --git a/internal/console/signincopy.go b/internal/console/signincopy.go| index 18835b295..23410ec5d 100644 |
| --- a/internal/console/signincopy.go |
| +++ b/internal/console/signincopy.go |
| @@ -47,6 +47,25 @@ var signinCopy = map[string]string{ |
| "team.bad_address": "That doesn't look like an email address.", |
| } |
| +// agentLoginCopy holds the approval page's strings for agent login by link |
| +// (2026-11-07-agent-login-link-design.md §3, §5). DRAFTS, awaiting copy |
| +// review (the plan's Task 5 applies the approved text verbatim). Kept apart |
| +// from signinCopy, which TestSigninCopyMatchesApproved pins to approved copy |
| +// byte for byte. cli.signin_prompt replaces home.cli_prompt on the front |
| +// page; the approved home.cli_prompt stays in signinCopy until that review |
| +// retires it. |
| +var agentLoginCopy = map[string]string{ |
| + "cli.title": "Approve a sign-in", |
| + "cli.lede": "{label} is asking to use {console} as you.", |
| + "cli.unnamed": "An unnamed agent or terminal", |
| + "cli.check": "Does your agent show this code?", |
| + "cli.not_me": "If you didn't just ask an agent or terminal to log in, press That wasn't me.", |
| + "cli.started": "Started {ago} ago.", |
| + "cli.started_now": "Started just now.", |
| + "cli.link_unknown": "That link's code has expired or was already used. Ask your agent to start the login again.", |
| + "cli.signin_prompt": "Sign in to connect your agent or terminal.", |
| +} |
| + |
| // copyText returns the approved string for id with each {key} placeholder |
| // replaced by its value (kv is key, value, key, value, ...). An unknown id is |
| // a programming error and panics, so a typo cannot ship blank copy. |
| @@ -55,6 +74,9 @@ func copyText(id string, kv ...string) string { |
| if !ok { |
| text, ok = socialSigninCopy[id] |
| } |
| + if !ok { |
| + text, ok = agentLoginCopy[id] |
| + } |
| if !ok { |
| panic("console: unknown copy id " + id) |
| } |
diff --git a/internal/console/templates/cli_approve.html b/internal/console/templates/cli_approve.html| index dae971dcc..4f50330a4 100644 |
| --- a/internal/console/templates/cli_approve.html |
| +++ b/internal/console/templates/cli_approve.html |
| @@ -1,20 +1,23 @@ |
| {{define "cli_approve"}}{{template "top" .}} |
| -<h1>Approve a terminal</h1> |
| +<h1>{{.CLIText "cli.title"}}</h1> |
| {{if .Error}}<p class="error">{{.Error}}</p>{{end}} |
| {{if .Request}} |
| -<p class="lede">A command line asked to sign in as you.</p> |
| +<p class="lede">{{.Lede}}</p> |
| +<p class="tile-value"><code>{{.Request.UserCode}}</code></p> |
| +<p><strong>{{.CLIText "cli.check"}}</strong></p> |
| <div class="banner"> |
| - <p><strong>Code</strong> <code>{{.Request.UserCode}}</code></p> |
| <p><strong>Terminal</strong> {{emptyOrDash .Request.Label}} |
| <span class="small">— this name was supplied by the machine asking. Trust |
| it only if it matches the machine in front of you.</span></p> |
| - <p><strong>From</strong> {{emptyOrDash .Request.RemoteAddr}}</p> |
| - <p class="small">Expires {{fmtTime .Request.ExpiresAt}}</p> |
| + <p><strong>From</strong> {{emptyOrDash .Request.RemoteAddr}}{{if .Place.Text}}, {{.Place.Text}}{{end}} |
| + {{- if .Place.Attribution}} <span class="small">(<a href="{{.Place.AttributionURL}}">{{.Place.Attribution}}</a>)</span>{{end}}</p> |
| + <p class="small">{{.StartedText}} Expires {{fmtTime .Request.ExpiresAt}}</p> |
| </div> |
| <p>Approving gives that terminal your identity — every account you belong to — |
| for {{.Days}} days. You can revoke it at any time from |
| <a href="/settings">command-line access</a>, and a note goes to your |
| Keymail inbox the moment it is issued.</p> |
| +<p>{{.CLIText "cli.not_me"}}</p> |
| <form class="signin" method="post" action="/auth/cli/approve"> |
| <input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <input type="hidden" name="code" value="{{.Request.UserCode}}"> |
| @@ -23,23 +26,12 @@ Keymail inbox the moment it is issued.</p> |
| </form> |
| {{else}} |
| <p class="lede">Type the code your terminal printed.</p> |
| -{{if .LinkCode}} |
| -<div class="banner"> |
| - <p>The link you followed carries the code <code>{{.LinkCode}}</code>.</p> |
| - <p class="small"><strong>Check it against your own screen before typing it.</strong> |
| - If you did not just run <code>carlos auth login</code> yourself, or that is not |
| - the code your terminal printed, close this page: somebody else is asking to |
| - become you, and typing their code is what would let them.</p> |
| -</div> |
| -{{end}} |
| <form class="signin" method="post" action="/auth/cli/approve"> |
| <input type="text" name="code" value="" placeholder="XXXX-XXXX" autocomplete="off" spellcheck="false"> |
| <input type="hidden" name="csrf" value="{{.CSRF}}"> |
| <button type="submit" name="action" value="continue">Continue</button> |
| </form> |
| -<p class="small">Codes look like <code>WXYZ-4823</code> and last ten minutes. |
| -Nothing here is ever approved by following a link — the code has to be typed, |
| -which means it has to be on a screen in front of you.</p> |
| +<p class="small">Codes look like <code>WXYZ-4823</code> and last ten minutes.</p> |
| {{end}} |
| {{template "bottom" .}}{{end}} |