Skip to content

fix: unset LHM_*_CONFIG in the hook wrapper#37

Closed
walter-square wants to merge 1 commit into
block:mainfrom
walter-square:walter-square/hook-wrapper-env-handling
Closed

fix: unset LHM_*_CONFIG in the hook wrapper#37
walter-square wants to merge 1 commit into
block:mainfrom
walter-square:walter-square/hook-wrapper-env-handling

Conversation

@walter-square

Copy link
Copy Markdown
Contributor

The Problem

The LHM_GLOBAL_CONFIG / LHM_LOCAL_CONFIG overrides are intended for dry-run ergonomics, but they're also honored during normal hook execution. Anything that injects env vars into the developer's shell before git runs, e.g. direnv loading a .envrc from a freshly cloned repo, could redirect lhm's config sources to attacker-chosen YAML, which then runs via lefthook.

The Fix

This prepends unset LHM_GLOBAL_CONFIG LHM_LOCAL_CONFIG to the generated wrapper-script content before it execs lhm run-hook, so lhm-as-a-hook never sees those vars even when the surrounding shell does. The vars still work for dry-run via the explicit --global-config / --local-config flags.

Testing

  • cargo test (146 passing, including wrapper-content assertions).

@alecthomas alecthomas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead we should just remove these envars. I haven't used them once since I initially added them.

@alecthomas alecthomas closed this Jun 11, 2026
@alecthomas

Copy link
Copy Markdown
Collaborator

See #40

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.

2 participants