Repository navigation
Follow or refuse the variables a line sets (#163, part 2) - #183
Merged
Merged
Conversation
A call after set -a, export X+=y, local -x, ${env:X}=, Set-Item env:X,
[Environment]::SetEnvironmentVariable or Remove-Item Env:X ran with variables
cloudpin didn't read, so it could land on the wrong account with no objection.
Each literal form is now followed, through the same path as export, so a value
reaches the identity lookup, and cloudpin's own variables stay ignored. What can
set a name cloudpin can't read (. file, source file, export $(...), read $V)
stops later guarded, non-exempt calls as "can't tell", through the existing
path and only with a pin in play. A name it can read with a value it can't
(read X, $env:X inside a block) stops only the CLI that name picks the account
for. A subshell, a pipe's side and a job keep what they set, as in bash.
New logic is in src/line-env.ts; shellwords.ts got shorter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns (#163) read -- needs no branch of its own, PS names need one test, and a cast on a plain PowerShell variable is outside this family, so it goes back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also where the User and Machine reading of SetEnvironmentVariable comes from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| const ASSIGNMENT = /^\$(?:(?:script|global|local|private):)?([A-Za-z_]\w*)([-+*/%]?=)?/i; | ||
| // `$env:X` and `${env:X}`, with a cast or not (#163): PowerShell takes them all. | ||
| const ENV_ASSIGNMENT = /^(?:\[[\w.[\]]+\])*\$(?:env:([A-Za-z_]\w*)|\{env:([^}]+)\})([-+*/%]?=)?/i; |
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.
Part of #163 (PR 2 of 5, the environment family). Design:
docs/superpowers/specs/2026-11-04-fail-closed-design.md.The bug. Variables that pick the account, set in forms the parser didn't read, reached the CLI unseen:
set -a; GH_HOST=x,export X+=y,${env:X}='v',Set-Item env:X v,[Environment]::SetEnvironmentVariable(...)and others. Measured with a printer named like the CLI: the wrong call really ran with no objection.The fix: follow or refuse (new
src/line-env.ts).set -a,set -o allexport,X+=yeverywhere,local -x,export X; X=v,declareand friends on an exported name,export $Vwhere the line knows V,export -n,bash -a -c.${env:X}=,$env:X ='v',+=,Set-Item,Set-Content,New-Item,Remove-Item,Clear-Itemand their aliases,SetEnvironmentVariablewith no target orProcess. AUserorMachinetarget changes nothing for later calls (from .NET's source; not run, because it writes to the registry).. file,source file,export $(...),read $V,Rename-ItemandCopy-Itemonenv:,env:*. A call before them isn't affected.read X,$env:Xset inside a block, and an unknown value through any new form.CLOUDPIN_*stays ignored in every new form.explainandcloudpin_checkagree with the hook. With no pin file, or one that doesn't pin this CLI, nothing stops.Known cost.
source venv/bin/activate && aws ...now stops as "can't tell" in a project that pinsaws, because a sourced file can set anything. It's rare in the commands measured, but other people may run this shape more often.Evidence
npm run typecheckexit 0;npx vitest run: 3904 passed, 19 skipped. 435 new tests, seen failing first.local -x FOO=l; ghoutside a function, which bash rejects with an error.. file,source file,export $(...)andset -a; GH_HOST=x, and passes for a call before thesource, an exempt call, a line with no guarded call, an unrelated variable, and a folder with no pin file.Not tested
pwsh, zsh, macOS and Linux shells.Left open
printf -v,${X:=y},declare -u/-l/-iand namerefs;.\script.ps1and& script.ps1, which can set process variables;false && export X=y, read as if it ran. A plain PowerShell variable set in a block ($s='a'; if ($c) { $s='b' }; az --subscription $s) reads the first value; that goes in PR 3.🤖 Generated with Claude Code