Skip to content

feat: check redirect targets against edit rules and external_directory - #12

Closed
preved911 wants to merge 10 commits into
mainfrom
feat/bash-guard-plugin
Closed

feat: check redirect targets against edit rules and external_directory#12
preved911 wants to merge 10 commits into
mainfrom
feat/bash-guard-plugin

Conversation

@preved911

Copy link
Copy Markdown
Owner

Redirects (2>&1, >/dev/null, > file, etc.) were invisible to the plugin because unbash stores them in cmd.redirects, not cmd.suffix. The reconstructed command text silently dropped redirects, bypassing all security checks.

Changes

  • src/chain.ts: Added RedirectInfo interface and redirects field to ChainSegment. Redirect operators and targets are now included in getCommandText. Statement-level redirects ({ echo hi; } > file) are captured too.
  • src/config.ts: Added editRules to PluginConfig, parsed from permission.edit.
  • src/enforce.ts: New resolveRedirectTargets() function:
    • Well-known redirects (FD redirects like 2>&1, /dev/null, heredocs) → always allowed
    • File redirects inside cwd → checked against editRules only
    • File redirects outside cwd → checked against editRules and external_directory
    • Most-restrictive-wins across bash permission, external directory, and redirect checks

Tests

7 new redirect enforcement tests + 6 new chain parsing tests. All 66 tests pass.

Developer 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)
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
@preved911 preved911 closed this Jul 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👀 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

Comment thread src/enforce.ts
}

if (actions.length === 0) return null;
if (actions.includes("deny")) return "deny";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider mentioning 'redirects' in the comment to clarify what segments are being checked.

Comment thread src/chain.ts
@@ -20,6 +45,12 @@ function getCommandText(cmd: Command): string {
for (const word of cmd.suffix) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ensure to handle cases where redirects may not have a fileDescriptor set as per your logic.

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