fix(auth): preserve the session domain during automatic re-login - #345
Open
BenyD wants to merge 1 commit into
Open
fix(auth): preserve the session domain during automatic re-login#345BenyD wants to merge 1 commit into
BenyD wants to merge 1 commit into
Conversation
EstablishUserLoginSession re-execs the CLI as 'login --silent', forwarding only --silent. The child resolves its domain from scratch, and because usePresetDomain deliberately ignores default cloud URLs unless --domain was set on that invocation, an expired EU Cloud session falls through to the region prompt, opens https://app.infisical.com/login, and on completion rewrites LoggedInUserDomain to US. Every subsequent command then targets the wrong region. Forwards the domain the parent already resolved. Because the child now sees an explicit --domain, usePresetDomain accepts it even for EU/US cloud URLs, so no change to that function is needed and the explicit login path is untouched. Fixes all callers of EstablishUserLoginSession at once. The bare US default is deliberately not forwarded: it is what an unconfigured invocation looks like, and forwarding it would silently skip the region prompt on first login. Fixes Infisical#312
Contributor
|
| Filename | Overview |
|---|---|
| packages/util/auth.go | Adds domain-preserving automatic re-login logic; argument handling is shell-safe, existing login normalization accepts API-form URLs, and no new actionable SSRF path was identified. |
| packages/util/auth_test.go | Adds focused table-driven tests for domain precedence and re-login argument construction. |
Reviews (1): Last reviewed commit: "fix(auth): preserve the session domain d..." | Re-trigger Greptile
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.
Description 📣
EstablishUserLoginSession()re-execs the CLI aslogin --silent, forwarding only--silent. The child then resolves its domain from scratch, and becauseusePresetDomain()deliberately ignores default cloud URLs unless--domainwas set on that specific invocation, an expired EU Cloud session falls through to the region prompt, openshttps://app.infisical.com/login, and on completion rewritesLoggedInUserDomainto US. Every subsequent command then targets the wrong region.This forwards the domain the parent has already resolved.
Why this is the only change needed. Because the child now sees an explicit
--domain,cmd.Flags().Changed("domain")is true, sousePresetDomain()accepts the value even for EU/US cloud URLs. The exclusion atlogin.go:465is never reached, which means no change tousePresetDomain()itself. That function is shared with the normalinfisical loginpath, so leaving its semantics alone seemed preferable to widening them. This also fixes every caller ofEstablishUserLoginSession()at once rather than per command.Precedence. The stored
LoggedInUserDomainwins, since it is the instance whose session just expired. Otherwiseconfig.INFISICAL_URLis used, as already resolved by the root command from--domain,INFISICAL_DOMAIN, or.infisical.json.One deliberate exception: the bare US default is not forwarded.
config.INFISICAL_URLdefaults to the US URL rather than empty, so forwarding it unconditionally would set an explicit--domainon every re-login and silently skip the region prompt for users who have never configured one. Returning""in that case preserves today's behaviour exactly.Scoped to one of the three fixes suggested in #312. Suggestion 2 is subsumed by the above. Suggestion 3, guarding
askForDomain()/browserCliLogin()behind a TTY check, is a UX change for semi-interactive contexts and felt like a maintainer's call rather than something to fold into a bug fix. Happy to add it or open it separately if you want it.Fixes #312
Type ✨
Tests 🛠️
Split the decision into two pure functions,
resolveReLoginDomainandbuildReLoginArgs, so the logic is testable without spawning a process. This mirrors the existingGetUpdateInstructions()/getUpdateInstructions(goos, execPath)split incheck-for-update.go.New
packages/util/auth_test.gocovers stored EU domain, stored self-hosted domain, explicit non-default override with nothing stored, the bare US default, nothing known at all, and stored US Cloud.Verified the tests are meaningful by forcing
resolveReLoginDomainto always return"", reproducing the pre-fix behaviour: the EU, self-hosted, and explicit-override cases all fail. Fullpackages/utilsuite passes with no regressions, andgo build ./...is clean.What I could not test: I do not have an EU Cloud account, so this was diagnosed by reading the code paths rather than reproducing end to end. The unit tests cover the decision logic; a reviewer with EU access confirming the real flow would be worthwhile.