feat: check redirect targets against edit rules and external_directory - #12
Closed
preved911 wants to merge 10 commits into
Closed
feat: check redirect targets against edit rules and external_directory#12preved911 wants to merge 10 commits into
preved911 wants to merge 10 commits into
Conversation
added 10 commits
July 27, 2026 04:50
- Project setup with package.json, tsconfig.json, build config - Config reader module: parse permission.bash and external_directory - Chain detection: unbash AST parsing with segment extraction - Path extraction: word tokens, Fig specs, absolute path resolution - Enforcement: segment resolution, aggregation, dual-hook pattern - 51 unit tests across all modules - README with install, prerequisite, and limitations docs - LICENSE (MIT)
…ehavior; ci: type-check before test
Redirects (2>&1, >/dev/null, > file, etc.) were invisible to the plugin because unbash stores them in cmd.redirects, not cmd.suffix. This meant the reconstructed command text silently dropped redirects, bypassing all security checks. Changes: - chain.ts: include redirects in ChainSegment with wellKnown flag (FD redirects, /dev/null, heredocs are well-known; file redirects are not) - config.ts: add permission.edit rule parsing - enforce.ts: check non-well-known redirect targets against edit rules; if the target is outside cwd, also check external_directory - Tests added for redirect parsing and enforcement
There was a problem hiding this comment.
👀 AI Code Review
The changes introduce proper handling of command redirects, enhancing security by checking against edit rules and external directories. The implementation includes new tests that comprehensively validate the redirection logic.
Powered by GPT-4o via GitHub Models
| } | ||
|
|
||
| if (actions.length === 0) return null; | ||
| if (actions.includes("deny")) return "deny"; |
There was a problem hiding this comment.
Consider mentioning 'redirects' in the comment to clarify what segments are being checked.
| @@ -20,6 +45,12 @@ function getCommandText(cmd: Command): string { | |||
| for (const word of cmd.suffix) { | |||
There was a problem hiding this comment.
Ensure to handle cases where redirects may not have a fileDescriptor set as per your logic.
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.
Redirects (
2>&1,>/dev/null,> file, etc.) were invisible to the plugin becauseunbashstores them incmd.redirects, notcmd.suffix. The reconstructed command text silently dropped redirects, bypassing all security checks.Changes
src/chain.ts: AddedRedirectInfointerface andredirectsfield toChainSegment. Redirect operators and targets are now included ingetCommandText. Statement-level redirects ({ echo hi; } > file) are captured too.src/config.ts: AddededitRulestoPluginConfig, parsed frompermission.edit.src/enforce.ts: NewresolveRedirectTargets()function:2>&1,/dev/null, heredocs) → always allowedcwd→ checked againsteditRulesonlycwd→ checked againsteditRulesandexternal_directoryTests
7 new redirect enforcement tests + 6 new chain parsing tests. All 66 tests pass.