Repository navigation
Describe profiles in --json without their credentials - #36
Merged
Merged
Conversation
`imogen profiles --json` serialised the whole `Config`, so `access_token` and `refresh_token` went to stdout on any logged-in machine — into a pipe, a CI log, a shell history, an agent transcript. The table beside it showed name, server, auth kind and scopes and no secret, so the two audiences disagreed about what was safe to print, and the machine one got strictly more. `--json` now answers with a `ProfilesView` naming the same four things the table does, plus `expires_at` where there is one. A view struct rather than `#[serde(skip_serializing)]` on the token fields: the attribute has to be remembered by whoever adds the next credential to `Config`, while a struct that must be extended on purpose cannot leak one by omission. The table's "signed in via" and its notion of which profile is current now come from the same two helpers the view uses, so the audiences cannot drift apart again. Closes #33 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review finding. `current_profile` skipped a `current` naming a profile that is no longer saved and fell to the first key, while every other command resolves through `Config::default_profile_name`, which returns it verbatim. With `current = "gone"`, `profiles` reported and painted `family` while `ls` failed on "gone" — the two disagreeing about which login is in use, which is the thing this change set out to stop. It now gives the same answer as `default_profile_name`, departing only for the empty config, where that function invents “default”: the right name for a profile about to be written, and the wrong description of what exists. The tests assert the two agree rather than asserting the view alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review finding. `signed_in_via` and `expires_at` were snake_case because the fields they replace wear that casing on disk, but every key this program synthesises is camelCase — `capturedAt`, `faceIds`, `loggedOut` — as are the SDK's own models. A script that reads `.loggedOut` from one command and `.signed_in_via` from this one has no way to predict which it will get. This PR redefines the shape of `profiles --json` anyway, so aligning costs nothing now and would be a second break later. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review findings, both low, both about a claim the change makes being wider than the code behind it. The structural half of the credential test grepped for `token":`, which the camelCase rename two commits ago had already defeated: a field added later as `access_token` serialises as `accessToken` and would have sailed past the one assertion advertised as catching it. It now walks the keys of the serialised view case-insensitively — keys rather than bytes, because “token” is a legitimate *value* of `signedInVia`. Proven by adding an `access_token` field with a harmless value and watching it fail. `current_profile`'s empty-profiles early return also swallowed a recorded `current`, so a truncated config would have had `profiles` report null while every other command still resolved and failed on the name. Dropping the early return leaves exactly the one departure the comment claims. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #33.
What was wrong
imogen profiles --jsonserialised the wholeConfigwithout.json(&config), andProfilecarriesaccess_tokenandrefresh_tokenwithskip_serializing_ifonly forNone. On any logged-in machine that command put live bearer credentials into whatever consumed the stream — a pipe, a CI log, a shell history, a bug report, an agent transcript.The table immediately below showed name, server,
browser|tokenand scopes, and no secret. The two audiences disagreed about what was safe to print, and the machine one got strictly more — the extra part being the credential.What changed
--jsonnow answers with aProfilesView: the same four things the table shows, plusexpiresAt(unix ms) where there is one. The top-level shape —currentand aprofilesmap keyed by name — is unchanged, so anything reading.currentor.profiles.home.serverstill works.This is a wider break of the
profiles --jsoncontract than just the credentials, and worth stating plainly:client_id,expires_inandobtained_atare gone from the output too. Nothing is lost —signedInViastands in forclient_id, andexpiresAtfor the other two — but anyone scripting against.profiles.*.expires_inhas to move.A view struct, not
#[serde(skip_serializing)]on the token fields. Both close today's leak. The attribute has to be remembered by whoever adds the next credential toConfig— the same omission that caused this bug, waiting to happen again. A struct that names everything it prints has to be extended on purpose, so it cannot leak a new field by omission. The test greps the serialised bytes for the secret rather than checking fields one by one, for the same reason.The table's "signed in via" and its notion of which profile is current now come from the same two helpers the view uses, so the two audiences cannot drift apart again.
current_profilealso fixes a small honesty problem the olddefault_profile_name()had here: it invents"default"for an empty config, which is right when naming a profile about to be written and wrong when describing what is saved.Nothing needs the token via
--jsontoday.login --jsonalready answers with profile, server, user and the credentials path;logout --jsonwith a name and a flag. Nothing in the repo reads a token back out of a--jsonstream —auth.rsandcontext.rstake it fromConfigin process. If a token is ever wanted on stdout it should be an explicit, separate, deliberate command, not a side effect of listing profiles.Nothing on the wire changes.
Verify
test result: ok. 128 passed; 0 failed; 2 ignored— fmt, clippy and the release build clean.The reproducing test was written first and watched fail, printing the leak verbatim:
Review
code-reviewat medium, three iterations, scoped by PR URL —main...HEADin the worktree pointed the tool at an unrelated repo. Two findings fixed, both as their own commits:current_profileskipped acurrentnaming a profile that is no longer saved and fell to the first key, while every other command resolves throughConfig::default_profile_name, which returns it verbatim.profileswould have reported and painted one login whilelsfailed on another — the same disagreement between audiences this PR exists to remove. It now givesdefault_profile_name's answer, departing only for the empty config.The final run reported zero blockers and zero significants.
Found, not fixed
Nothing.
session.rsis the only place that serialises aConfig, and no other command puts a token on stdout.🤖 Generated with Claude Code