Skip to content

fix(hooks): pin the module path before every hook line resolves a command - #65

Merged
raandree merged 4 commits into
mainfrom
ai/guard-module-shadowing
Nov 16, 2026
Merged

raandree merged 4 commits into
mainfrom
ai/guard-module-shadowing

Conversation

@raandree

Copy link
Copy Markdown
Owner

Brief 18: every PowerShell hook line, the 15 of hooks.json and the 3
of the contributor-profile asset, pins the module path of each
PowerShell process it runs in to that interpreter's own Modules
folder before it resolves a command by name. A module that the run
identity can plant for Windows PowerShell 5.1 no longer answers for the
push guard or the grant recorder (R12-02, R12-08). The inner -Command
starts with the pin, and the closing statement makes the same call
first, with the exit codes it gave before. No hook script changed: the
guard, the grant recorder and the appender keep their digests.

HookContract accepts only the new closing statement, holds the
-Command text of a pinned line to the exact pin, refuses a later
mention of PSModulePath by name, -File, -EncodedCommand and a
line without a command, and runs every payload with a tripwire module
of its own as a second net.

Option 3 was decided under the owner's delegation; merging this is the
owner's explicit answer.

Validation: every new test red first; mutants on copies 12 of 12, then
25 of 25. The full gate before the Memory Bank commit passed 6,231
tests, 0 failed, 145 skipped, coverage 91.61 %. Review: Request
changes (R18-01 Major), re-review Approve with changes (R18-09, taken
as records); all fixed.

Open: code after the pin is read only for a mention of PSModulePath,
so keep the inner -Command text exactly as shipped; the outer 5.1 of
VS Code looks powershell up in its modules when its PATH lacks it;
the host's environment, a writable $PSHOME, and the bare
powershell and pwsh stay open. The Ubuntu and macOS legs first
ran, green, in an early read of the whole stack (run 43695341208),
where the eight planted-module controls passed on Windows; they fail
rather than skip where a runner's 5.1 does not search a planted
place.

Re-pin once merged, deriving every pinned hooks.json again from the
shipped PreToolUse entry:

  • verifier:
    32558cf02a594aa2922f8614bb897cab1d651d4f46932a653c98d77801842842
  • hooks.json:
    ed05f232b68d0715b5c351d50234f9250ef14b8139801fb5810c9b825512cb14
  • contributor-profile.hooks.json:
    e553312ef5d9051e510b08a19894a48f0a4bf819998901e22e7652de01ff1eec

Rebased onto main unchanged: the tree is the brief's recorded tip
plus brief 12's test fix (b69cb23), which main already holds.

Co-authored-by: AI Assistant ai@example.com
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

raandree and others added 4 commits November 16, 2026 20:28
…mand

Windows PowerShell 5.1 and pwsh load a command such as Get-Variable from
the first module on PSModulePath that exports it. A module that the
account puts first on that path, in its own module folder, or in the
working directory of a 5.1 without a documents folder turned the guard's
denial into exit 0 (R12-02, R12-08).

All 15 PowerShell lines of hooks.json and the 3 of the contributor-profile
asset now start their inner command with
[Environment]::SetEnvironmentVariable('PSModulePath',
[IO.Path]::Combine([AppContext]::BaseDirectory, 'Modules')), and the
closing statement makes the same call first. No hook script changes.
HookContract accepts only the new closing statement and runs every payload
with a tripwire module where the PowerShell of each spawn looks first.

Migration: derive pinned hooks.json files again, re-pin hooks.json and the
verifier in every containment profile, and refresh ~/.copilot.

Co-authored-by: AI Assistant <ai@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The review of 4667dd7 ran three hand edits of the contained guard line
against HookContract, and each passed although a planted module then
turned a denial into exit 0: aliases before anything else, every name
module-qualified, and a pin with a profile folder first (R18-01).

HookContract now requires the interpreter to get its text with -Command,
that text to start with the shipped pin, compared as typed, and no
second PSModulePath after it, as it requires the shipped closing
statement; a line that fails is refused before anything runs. The
tripwire stays as a second net, with a narrowed claim. The Windows
PowerShell 5.1 wrapper is first asked which folder it looks in first,
and runs with PSModulePath removed where the machine sets none
(R18-04, R18-06). XDG_DATA_HOME is removed for the tripwire's spawns,
and its placement is tested on every platform (R18-05).

The records state that the outer 5.1 of VS Code looks for powershell in
its modules when PATH lacks it (R18-02); the hook authoring Instruction
no longer shows an unpinned launcher (R18-03). The planted-module cases
get a positive control, and test messages drop ANSI escapes that broke
the NUnit report (R18-08). hooks.json, the asset and every hook script
are unchanged; the verifier changes.

Co-authored-by: AI Assistant <ai@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…he pin

The re-review of 34de586 (R18-09) passed six hand edits after the pin
through HookContract while a planted module or script answered for the
guard: the module path set again under another spelling (a computed
name, an Env:PSModuleP* wildcard, New-Item Env:), Import-Module by
path, an alias to a script by path, and a nested pwsh. The records said
that assigning the module path again is refused.

The hooks README (the HookContract row, gap 4 and the section on the
containment profile), docs/SECURITY-REVIEW.md and the CHANGELOG now say
what the check refuses: a -Command text that does not start with the
exact pin, a later mention of PSModulePath by name, -File,
-EncodedCommand, a line without a command, and any closing statement
but the exact one. They name the six forms by kind and tell operators
to keep the inner -Command text of every line exactly as shipped. No
code changes; the verifier stays at 32558cf0.

Co-authored-by: AI Assistant <ai@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Align decision 0016 with the closing statement that pins the module path
first (R18-07): a dated note names the pin, the new statement of the
windows and powershell launchers, and the entry of 2026-11-14 in
docs/SECURITY-REVIEW.md; last-verified moves to 2026-11-14.

activeContext.md makes brief 18 the current focus, names brief 19, the
owner's publish step, as next, moves brief 15 to the previous focuses,
records the residual of brief 18, and narrows brief 12's. progress.md
gains the brief 18 milestone and drops the oldest one, so both files stay
under 180 lines. systemPatterns.md adds one sentence to the hooks bullet:
a hook line pins its module path through .NET types before any command.

Co-authored-by: AI Assistant <ai@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@raandree
raandree merged commit bd28133 into main Nov 16, 2026
10 checks passed
raandree added a commit that referenced this pull request Nov 16, 2026
Brief 19 published the stack of briefs 13, 16, 17, 12, 14, 15 and 18
as #59 to #65, each squash tree equal to its rebased tip and each
pull request's CI green on Ubuntu, macOS and Windows. #62's first CI
failed one relay row off Windows, a fixture gap that a test-only fix
in its squash closed; the CI-platform pattern records the lesson.
~/.copilot was redeployed from bd28133.

The active context moves the merged briefs to previous focuses and
names the owner's remaining steps. Progress records the milestone and
the newest preview, and curates the oldest milestone.

Co-authored-by: AI Assistant <ai@example.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@raandree
raandree deleted the ai/guard-module-shadowing branch November 16, 2026 21:39
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