Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@effected/shell

Latest version: v0.3.2

Overview

Last scanned
28 Nov 2026
Published
28 Nov 2026
npm package Publisher: spencerbeggs
8 Stars
2 Forks
5 Versions
1.1K Downloads
TypeScript Repo language

Scan summary

@effected/shell was last scanned on 28 Nov 2026 at version 0.3.2. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 5 versions; the latest 2 were published within 7 days (22–28 Nov 2026).
  • Findings: No rules fired in version 0.3.2.
  • Downloads: 1,069 downloads.

Versions

5 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.3.2 LATEST 28 Nov 2026 No rules fired
0.3.1 22 Nov 2026 No rules fired
0.3.0 11 Nov 2026 No rules fired
0.2.0 10 Nov 2026 Not shown
0.1.1 9 Nov 2026 Not shown

No rules fired in 0.3.2

Findings

Findings for v0.3.2. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.3.2; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

@effected/shell

npm License: MIT Node.js %3E%3D24.11.0 TypeScript 7.0

A tolerant shell-syntax lexer and segmenter for guards and agent tooling. It answers one question about an untrusted command string: which simple commands would this run, and with which words? Nothing is expanded and nothing is executed, and the parse never fails.

Pre-1.0.0. This package is part of the @effected/* kit, still in 0.x development. It peers on effect and has no other dependency.

Stability: unstable. This package's API surface is not yet considered complete and may change across 0.x releases. Pin an exact version. Full policy: release strategy.

Why @effected/shell

An agent hook that inspects a Bash tool call before it runs has to find every command in the string, not just the first one. Splitting with a general-purpose tokenizer and reading the first words misses git add -A && git commit -m "…", so the guard never sees the commit. Reading a word as a literal when the shell would expand it is the other way to fall open: git {commit,} runs git commit.

This package segments a command string on its control operators, records how every word is quoted, marks every expansion instead of performing it, and skips heredoc bodies so the text inside one is never read as commands. Input it cannot finish becomes an opaque part and a diagnostic, never an exception.

Install

npm install @effected/shell effect
pnpm add @effected/shell effect

Requires Node.js >=24.11.0. effect is a peer dependency. ESM-only: import it from an ES module.

Usage

A guard that sees every command
import { ShellSyntax } from "@effected/shell";
import type { ShellCommand, ShellScript, ShellWord } from "@effected/shell";
import { Option } from "effect";

// git's global options that take a separate argument: `git -C dir commit`.
const GIT_OPTIONS_WITH_ARGUMENT: ReadonlySet<string> = new Set([
  "-C", "-c", "--git-dir", "--work-tree", "--namespace", "--config-env",
]);

// git's subcommand; `undefined` for another command, `null` when unreadable.
const gitSubcommand = (command: ShellCommand): string | null | undefined => {
  const name = Option.getOrUndefined(command.name);
  // `name` is as written: compare its last path segment, so /usr/bin/git counts.
  if (name === undefined || name.slice(name.lastIndexOf("/") + 1) !== "git") return undefined;
  const args = command.args.map((word) => Option.getOrNull(word.literal));
  for (let i = 0; i < args.length; i += 1) {
    const arg = args[i];
    if (arg === undefined || arg === null) return null;
    if (GIT_OPTIONS_WITH_ARGUMENT.has(arg)) i += 1;
    else if (!arg.startsWith("-")) return arg;
  }
  return undefined;
};

// bash evaluates what these read as arithmetic or code, where a quoted
// 'a[$(cmd)]', or a variable holding one, still runs cmd. The parse cannot see
// inside that evaluation, so refuse them (see "Known limits").
const ARITHMETIC_TESTS: ReadonlySet<string> = new Set(["-eq", "-ne", "-lt", "-le", "-gt", "-ge", "-v"]);
// Arithmetic over a name; `${!x}`, `${x@P}` and a subscript over one; and a
// substring offset or length over one, special parameters included (`${s:x}`,
// `${@:x}`, `${-:x}`, `${a[@]: -x}`), which the `:-`, `:=`, `:?` and `:+`
// operators are not.
const EVALUATES_A_NAME =
  /(?:\$\(\(|\$\[|\(\()[^A-Za-z_]*[A-Za-z_]|\$\{(?:!|[^}]*@P|(?:[@*#?$!0-9-]|\w+(?:\[[^\]]*\])?):(?![-=?+])[^}]*[A-Za-z_$])/;
// A subscript over a name in a parameter expansion (`${a[x]}`, `${#a[x]}`),
// read to its matching `]` at any nesting depth (`${a[0[0]+x]}`).
const expandsASubscriptOverAName = (text: string): boolean => {
  for (const match of text.matchAll(/\$\{#?\w*\[/g)) {
    let depth = 0;
    for (let i = match.index + match[0].length - 1; i < text.length; i += 1) {
      const c = text[i] as string;
      if (c === "[") depth += 1;
      else if (c === "]") {
        depth -= 1;
        if (depth === 0) break;
      } else if (/[A-Za-z_$]/.test(c)) return true;
    }
  }
  return false;
};
// A subscript over a name: in an assignment's name, or an array literal's key
// (`a=([x]=1)`): a letter, `_` or `$` anywhere inside `[ … ]`, at any nesting
// depth, so `a=([1[0]+x]=1)` counts as well.
const subscriptOverAName = (text: string): boolean => {
  let depth = 0;
  for (const c of text) {
    if (c === "[") depth += 1;
    else if (c === "]") depth = Math.max(0, depth - 1);
    else if (depth > 0 && /[A-Za-z_$]/.test(c)) return true;
  }
  return false;
};
// Commands that change how bash parses or what a name runs, and commands that
// run a command they are given (unmodelled wrappers among them).
const REFUSED_COMMANDS: ReadonlySet<string> = new Set([
  "shopt", "alias", "hash", "enable", "builtin", "eval", "source", ".", "bash", "sh",
  "su", "ssh", "xargs", "nice", "timeout", "stdbuf", "setsid", "doas", "chroot",
]);
// PS4 is prompt-expanded before every command xtrace traces; POSIXLY_CORRECT
// switches the parser to POSIX mode, which also expands aliases; BASH_ALIASES
// and BASH_CMDS are the alias and command-hash tables, so a write to either
// makes a name run something else. `${NAME:=…}`, `for NAME` and a brace word
// write them with no assignment token, so refuse any mention of one, read with
// quotes and backslashes removed (`POSIX''LY_CORRECT` is the same name).
const REFUSED_VARIABLE = /(?<!\w)(?:PS4|POSIXLY_CORRECT|BASH_ALIASES|BASH_CMDS)(?!\w)/;

// The name an assignment builtin's argument assigns, as written before its
// first `=`; `null` when a variable, a substitution or a brace may supply it.
const assignedName = (word: ShellWord): string | null => {
  const literal = Option.getOrNull(word.literal);
  if (literal !== null) return literal.split("=", 1)[0] ?? "";
  const head = word.joined.split("=", 1)[0] ?? "";
  return /[$`{]/.test(head) ? null : head.replace(/["'\\]/g, "");
};

// An argument's array value, `declare -a x=( … )`: an `opaque` part opening `(`.
const arrayValue = (word: ShellWord): string | undefined =>
  word.parts.find((part) => part.kind === "opaque" && part.raw.startsWith("("))?.raw;

// With an array target the builtin re-reads a quoted or expanded value as a
// compound assignment, so `declare -a 'x=($(cmd))'` and `v='($(cmd))';
// declare -a x="$v"` run cmd. Whether `word` assigns a value bash may re-read
// that way: one not literal, or holding `=(` once quotes are removed, unless
// it is the parse's own unquoted `x=( … )` array.
const mayRereadAsArray = (word: ShellWord): boolean => {
  if (!word.joined.includes("=")) return false;
  const literal = Option.getOrNull(word.literal);
  if (literal !== null) return literal.includes("=(");
  const last = word.parts[word.parts.length - 1];
  const parsedArray =
    last?.kind === "opaque" &&
    last.raw.startsWith("(") &&
    word.parts.slice(0, -1).every((part) => part.kind === "bare");
  return !parsedArray;
};

// An arithmetic test inside a `[[ … ]]` the command evaluates. The parse splits
// one into segments on `&&`, `||` and `(`, so a test can sit in a later segment
// than its `[[`: follow an unclosed one into the segments after it.
const arithmeticTest = (commands: ReadonlyArray<ShellCommand>): boolean => {
  let inTest = false;
  for (const command of commands) {
    for (const word of inTest ? command.segment.words : command.evaluated) {
      if (word.joined === "[[") inTest = true;
      else if (word.joined === "]]") inTest = false;
      else if (inTest && ARITHMETIC_TESTS.has(Option.getOrElse(word.literal, () => ""))) return true;
    }
  }
  return false;
};

const evaluatesText = (command: ShellCommand): boolean => {
  const { segment } = command;
  // bash removes a backslash-newline before it reads a token, so every text
  // test reads `joined`, never `raw`.
  const texts = [
    ...segment.words.map((word) => word.joined),
    ...segment.assignments.map((assignment) => assignment.joined),
    ...segment.redirections.map(({ target }) =>
      target.kind === "heredoc" ? (target.quoted ? "" : target.joined) : target.joined,
    ),
  ];
  if (texts.some((text) => EVALUATES_A_NAME.test(text) || expandsASubscriptOverAName(text))) return true;
  if (texts.some((text) => REFUSED_VARIABLE.test(text.replace(/["'\\]/g, "")))) return true;
  for (const { name, value } of segment.assignments) {
    if (subscriptOverAName(name)) return true;
    if (value.joined.startsWith("(") && subscriptOverAName(value.joined)) return true;
  }
  const name = Option.getOrUndefined(command.name);
  const base = name?.slice(name.lastIndexOf("/") + 1);
  if (base !== undefined && REFUSED_COMMANDS.has(base)) return true;
  const args = command.args.map((word) => Option.getOrNull(word.literal));
  // An indexed array evaluates each key as arithmetic, so `declare -a x=([k]=1)`
  // runs what `k` holds. Keys are strings only from the operand
  // `associativeFrom` names: bash reads the `-A` as written, so a quoted or
  // expanded one (`"-A"`, `\-A`, `$o`) leaves them arithmetic.
  const builtin = Option.getOrUndefined(command.assignmentBuiltin);
  const stringKeysFrom = builtin === undefined ? undefined : Option.getOrUndefined(builtin.associativeFrom);
  const indexedKeyOverAName = command.args.some((word) => {
    const value = arrayValue(word);
    if (value === undefined || !subscriptOverAName(value)) return false;
    const at = builtin?.operands.findIndex((operand) => operand.start === word.start) ?? -1;
    return stringKeysFrom === undefined || at === -1 || at < stringKeysFrom;
  });
  // `-i` evaluates every value as arithmetic, and `-n` makes a nameref, in
  // any spelling: bundled (`-ix`), after `--`, or as `+i`.
  const integerOrNameref = args.some((arg) => arg !== null && /^[-+][A-Za-z]*[in]/.test(arg));
  // An `a` or `A` option, or a word an expansion supplies that may be one.
  const arrayOption = command.args.some((word) => {
    const literal = Option.getOrNull(word.literal);
    return literal === null ? !word.joined.includes("=") : /^[-+][A-Za-z]*[aA]/.test(literal);
  });
  // What an assignment builtin's arguments assign, past its options.
  const assigned = command.args
    .filter((word) => !/^[-+]/.test(Option.getOrElse(word.literal, () => "")))
    .map(assignedName);
  switch (base) {
    case "let":
    case "read":
    case "trap":
      return true;
    case "declare":
    case "typeset":
    case "local":
      // These evaluate a subscript in the name they assign: `declare 'a[$(cmd)]=1'`.
      // They re-read a value as an array whenever the target already is one,
      // for `local`, one already local to the same function.
      return (
        indexedKeyOverAName ||
        integerOrNameref ||
        command.args.some(mayRereadAsArray) ||
        assigned.some((assignee) => assignee === null || assignee.includes("["))
      );
    case "export":
    case "readonly":
      return (
        indexedKeyOverAName ||
        integerOrNameref ||
        (arrayOption && command.args.some(mayRereadAsArray)) ||
        assigned.some((assignee) => assignee === null)
      );
    case "set":
      // Turning on xtrace (PS4 may be inherited) or POSIX mode.
      return args.some((arg) => arg === null || /^-[A-Za-z]*x/.test(arg) || arg === "xtrace" || arg === "posix");
    case "printf":
      return args[0]?.startsWith("-v") === true;
    case "test":
    case "[":
      return args.includes("-v");
    case "find":
      return args.some((arg) => arg === null || /^-(?:exec|execdir|ok|okdir)$/.test(arg));
    default:
      return false;
  }
};

// Refuse a commit, and refuse anything the guard cannot vouch for, at every
// depth of substitution.
const refuses = (script: ShellScript): boolean => {
  const walk = script.allCommands();
  // A substitution too deep to parse is a refusal, never a silent pass.
  if (walk.truncated) return true;
  return walk.scripts.some(({ script: nested }) => {
    const commands = nested.commands();
    if (nested.diagnostics.length > 0 || arithmeticTest(commands)) return true;
    return commands.some((command) => {
      // No name WITH args is a command it cannot name (`$GIT commit`, or a
      // wrapper option it does not know). No name and no args is a segment that
      // runs nothing, such as `fi`.
      if (Option.isNone(command.name) && command.args.length > 0) return true;
      if (evaluatesText(command)) return true;
      const subcommand = gitSubcommand(command);
      return subcommand === null || subcommand === "commit";
    });
  });
};

// Refuse input past a size the hook can afford to parse before its timeout.
// Agent Bash commands top out near 50 KB; a megabyte of densely packed
// substitutions costs about a second to parse and walk.
const MAX_INPUT = 256 * 1024;
const guard = (input: string): boolean => input.length > MAX_INPUT || refuses(ShellSyntax.parse(input));

console.log(guard('git add -A && git commit -m "feat: x"'));
// => true
console.log(guard("if git diff --quiet; then git status; fi"));
// => false

The size gate is the guard's, not the package's. parse and allCommands are linear and never refuse, so their cost is bounded only by the input. How much a guard can spend is set by its hook's timeout, and how long real commands run is set by its agent. Measured on Apple silicon (CPU time, process.cpuUsage), the costliest shapes take about 250 ms at 256 KB and about 1 s at 1 MB, while the longest of 56,176 recorded agent Bash commands is 48.7 KB. A guard whose hook falls open on a timeout needs the gate most, since a slow refusal there becomes a pass.

allCommands() is the guard's view of the whole string: the script and the body of every command and process substitution in it, parsed and walked to maxDepth (16 unless given), each nested script with its own commands() and diagnostics. A substitution whose body sits deeper than the cap is not parsed but recorded in truncations with the reason "depth", never dropped, so the guard refuses when truncated is true. Each distinct substitution is parsed once, at the shallowest depth it is reached, and the walk enforces a budget: the bodies it lexes total at most maxDepth times the input (and at most ShellScript.walkCharacterLimit, 64 MiB), in at most ShellScript.walkRecordLimit (10,000) records, scripts and truncations together. The substitution that would pass it is recorded as a truncation with the reason "budget" and the walk stops, so the guard refuses that too. The walk is breadth first, holds its work on a queue rather than the call stack, and never throws. A maxDepth that is not a non-negative number reads as 0.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @effected/shell

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Copy of Template Design OX Blog (3)
Research

Ruby2Shell: Ruby Memory Corruption Flaws Expose Applications to Remote Code Execution, But is it an Actual Risk?

Vulnerability Insights

Compromised Claude Code extensions (versions 2.1.312 & 2.1.313) in Cursor try to install a backdoor

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Frame 2085668439 (1)
Group 1261154229