fix(agent-context): validate JARVOS_SECONDBRAIN_DIR before loading modules - #187
Open
levineam wants to merge 1 commit into
Open
fix(agent-context): validate JARVOS_SECONDBRAIN_DIR before loading modules#187levineam wants to merge 1 commit into
levineam wants to merge 1 commit into
Conversation
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.
Motivation
JARVOS_SECONDBRAIN_DIR(after only tilde expansion) and passed it intorequire()calls, creating a module-loading trust boundary that can lead to arbitrary JavaScript execution if the env var points at an attacker-controlled tree.Description
secondbrainDir()short-circuit with logic that requires an absolute path (path.isAbsolute) and canonicalizes it withfs.realpathSyncbefore use.(stat.mode & 0o022) !== 0).loadJarvosPaths,loadNoteWriter,loadJournalLinker, etc.) continue to callsecondbrainDir()but now receive a validated canonical path, preventing pre-require()execution of untrusted code.createNote rejects an untrusted secondbrain module root before loading codeinmodules/jarvos-agent-context/test/agent-context.test.jsthat asserts a relative/attacker-controlledJARVOS_SECONDBRAIN_DIRis rejected before any module is loaded.Testing
npm testinmodules/jarvos-agent-contextand the full test suite passed successfully.Codex Task