Skip to content

improvement(agent-vault): read the session token from the environment - #395

Open
saifsmailbox98 wants to merge 2 commits into
mainfrom
agent-vault-session-token-env-var
Open

improvement(agent-vault): read the session token from the environment#395
saifsmailbox98 wants to merge 2 commits into
mainfrom
agent-vault-session-token-env-var

Conversation

@saifsmailbox98

@saifsmailbox98 saifsmailbox98 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Description 📣

--session-token was the only Agent Vault flag with no environment fallback. --proxy, --client-id, --client-secret and the proxy's --enrollment-token and --data-dir all go through GetCmdFlagOrEnvWithDefaultValue, so the one credential that carries the whole access bundle had to sit on the command line, where it lands in shell history and in process listings. It now falls back to INFISICAL_AGENT_VAULT_SESSION_TOKEN.

Resolution moves into a single helper so the two rules that turn on where the token came from are testable:

  • Flag beats environment. The environment value is trimmed, and a blank one names no session.
  • --session-token "" stays a hard error rather than falling back to the environment. That shape is "$AV_TOKEN" with the variable unset, and running the agent on a session the operator did not name is the outcome worth refusing.
  • --access-bundle alongside a flag token is still the existing "pass one of them, not both" error. Alongside an environment token it warns and mints instead, because an exported variable is ambient and may be left over from an unrelated run, while the flag was typed for this run.

Companion docs PR: Infisical/infisical#8104

The agent process already receives the session token either way, as the password in the HTTPS_PROXY URL, so this does not widen what the child sees. It only keeps the token out of history and out of ps.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

# Here's some code block to paste some code snippets

@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-395-improvement-agent-vault-read-the-session-token-from-the-enviro

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@greptile-apps

greptile-apps Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

This PR is not safe to merge until an environment token overridden by --access-bundle is removed from the launched child’s environment.

Findings

  1. P1 Security Ambient Token Remains Exposed

Summary

  • Explicit session-token flags take precedence and explicitly blank flags remain errors.
  • Ambient tokens yield to an explicit access-bundle request.
  • Unit tests cover direct token resolution cases.
  • The access-bundle override currently leaves the supposedly ignored ambient credential exposed to the child process.

Reviews (1) · Last reviewed commit: "improvement(agent-vault): read the sessi..."

Comment on lines +188 to +189
util.PrintWarning(fmt.Sprintf("%s is set, but --access-bundle was passed: minting a new session and ignoring the token in the environment.", agentVaultSessionTokenEnv))
sessionToken = ""

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.

P1 security Ambient Token Remains Exposed

When --access-bundle overrides an ambient session token, this branch clears only the local variable. buildAgentVaultRunEnv still copies INFISICAL_AGENT_VAULT_SESSION_TOKEN into the child environment, so the launched process and anything it spawns receive the supposedly ignored bearer credential. If the stale token grants broader access than the newly minted bundle, the child retains those broader privileges. Remove the variable from the child environment when constructing an access-bundle run.

How this was verified: The access-bundle branch clears only the local token, while buildAgentVaultRunEnv copies every non-proxy parent variable, including the ambient session token, into the child environment.

--session-token was the only Agent Vault flag without an environment
fallback, so the one credential that carries the whole access bundle had
to sit on the command line, in shell history and in process listings. It
now falls back to INFISICAL_AGENT_VAULT_SESSION_TOKEN, the same shape
--proxy, --client-id and the proxy's --enrollment-token already have.

Resolution moves into one helper so the two rules that turn on the
token's source are testable. An explicit but empty --session-token stays
an error rather than falling back to the environment: that shape is
"$AV_TOKEN" with the variable unset, and running on a session the
operator did not name is the outcome worth refusing. --access-bundle
alongside a flag token is still the "pass one of them, not both" error,
but alongside an environment token it warns and mints, because an
exported variable is ambient and may be left over from an unrelated run
while the flag was typed for this one.

The agent already receives the token either way, as the password in the
HTTPS_PROXY URL, so nothing new reaches the child process.
return "", fromFlag, fmt.Errorf(
"--session-token was given but is empty; pass a session token from the dashboard, or drop the flag and set %s", agentVaultSessionTokenEnv)
}
token, err = util.GetCmdFlagOrEnvWithDefaultValue(cmd, "session-token", []string{agentVaultSessionTokenEnv}, "")

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.

Medium: Overridden session token remains exposed to the child

buildAgentVaultRunEnv copies unrelated entries from os.Environ(), so the launched command still receives INFISICAL_AGENT_VAULT_SESSION_TOKEN. When a flag takes precedence or --access-bundle mints a narrower session, the child can read this stale token and use its potentially broader access despite the CLI claiming to ignore it. Filter agentVaultSessionTokenEnv from the environment passed to the child after resolving the token.

@veria-ai

veria-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

PR overview

This pull request updates the agent-vault command to read its session token from the environment while supporting flag and access-bundle token resolution when launching child commands.

One security issue remains open: a child process can still inherit an overridden session token from the environment. If that stale token has broader permissions than the selected or newly minted token, the child could use it to obtain unintended vault access; no issues have yet been addressed.

Open issues (1)

Fixed/addressed: 0 · PR risk: 6/10

buildAgentVaultRunEnv copies the parent environment wholesale, so an
exported INFISICAL_AGENT_VAULT_SESSION_TOKEN reached the agent. On an
--access-bundle run that is the token the command just said it was
ignoring: the agent could read it and use it as the proxy password
itself, getting whatever the older bundle allowed instead of the bundle
that was named.

Stripped on every run rather than only on that path. When the variable
is the session, the agent already has it as the proxy password, so
dropping it costs nothing there and leaves one rule: the agent's session
comes from the proxy URL and nowhere else.
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