security(gateway): re-resolve skills_sync path constants per call - #441
Open
hashbender wants to merge 1 commit into
Open
security(gateway): re-resolve skills_sync path constants per call#441hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
|
Review Complete Risk: 🟢 Low (18/100) — no findings · 149 LOC across 2 files PR replaces import-time path constants in tools/skills_sync.py with PEP 562 getattr for profile-aware dynamic resolution, and adds a runtime profile isolation test. No blocking issues found. Files Reviewed (2 files) |
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.
Summary
tools/skills_sync.py'sHERMES_HOME/SKILLS_DIR/MANIFEST_FILEare resolved once at import time viaget_hermes_home(), which reads a context-localContextVar(_HERMES_HOME_OVERRIDE) set per-request under the multiplexed gateway (multiple profiles served from one process, e.g. the desktoptui_gateway).gateway/run.pycallssync_skills()directly in-process on every profile's startup:Freezing the resolved path at import time pins every later profile's sync to whichever profile's
HERMES_HOMEhappened to be active the first time this module was imported in the process — a later-starting profile silently syncs bundled skills into the FIRST profile's directory instead of its own, and never gets its own bundled skills synced at all. The module's own comment (visible elsewhere in the codebase,hermes_cli/profiles.py) already flags this for the CLI/hermes updatepath — "Uses subprocess because sync_skills() caches HERMES_HOME at module level" — which routes around it via subprocess isolation, butgateway/run.py's in-process call has no such isolation._rmtree_writable's safety guard (SKILLS_DIR.resolve()as the scope floor for a destructivermtree, guarding against a catastrophic wipe of~/.hermes/) also benefits from this fix: a frozen wrong-profileskills_rootcould desync the guard from the actual skills directory being operated on.Fix
Adopt
tools/skills_hub.py's already-established fix for this exact bug class: a module__getattr__(PEP 562) that resolvesHERMES_HOME/SKILLS_DIR/MANIFEST_FILEdynamically per access, honoring the active profile override, while a test'spatch("tools.skills_sync.SKILLS_DIR", ...)still sets a real module attribute that shadows dynamic resolution entirely — preserving every existing test seam intests/tools/test_skills_sync.py(dozens of call sites) unmodified. All ~20 internal call sites in the module now resolve fresh via_hermes_home()/_skills_dir()/_manifest_file()instead of the frozen names.Test plan
pytest tests/tools/test_skills_sync.py tests/tools/test_skills_list_modified_diff.py -q— 75 passedpytest tests/test_profile_isolation_runtime.py -q— 14 passed (10 pre-existing + 4 new)pytest tests/hermes_cli/test_skills_hub.py -q— 28 passedTestSkillsHubPathResolutionfailures (a test-order-dependent state leak intools/skills_hub.py's own test suite) — confirmed viagit stashthat this happens identically without this change; each file passes cleanly run on its own.ruff checkon all changed files — cleanNote on file co-tenancy
Open PR NousResearch#34577 ("keep bundled skill copies writable on Nix store") also touches
tools/skills_sync.py, but for an unrelated concern (shutil.copytreewrite-permission handling on read-only source filesystems, via new_copy_file_writable/_make_tree_owner_writablehelpers) — no functional overlap with this profile-isolation fix, though whichever merges second will need a small rebase around the constant-block region.Mirror-of: NousResearch#56523
NousResearch#56523