Commit Graph

7 Commits

  • feat: expand the set of commands that can be safely identified as "trusted" (#1668)
    This PR updates `is_known_safe_command()` to account for "safe
    operators" to expand the set of commands that can be run without
    approval. This concept existed in the TypeScript CLI, and we are
    [finally!] porting it to the Rust one:
    
    
    https://github.com/openai/codex/blob/c9e2def49487585cfe6f8bb7b2be442e8c0b5e1b/codex-cli/src/approvals.ts#L531-L541
    
    The idea is that if we have `EXPR1 SAFE_OP EXPR2` and `EXPR1` and
    `EXPR2` are considered safe independently, then `EXPR1 SAFE_OP EXPR2`
    should be considered safe. Currently, `SAFE_OP` includes `&&`, `||`,
    `;`, and `|`.
    
    In the TypeScript implementation, we relied on
    https://www.npmjs.com/package/shell-quote to parse the string of Bash,
    as it could provide a "lightweight" parse tree, parsing `'beep || boop >
    /byte'` as:
    
    ```
    [ 'beep', { op: '||' }, 'boop', { op: '>' }, '/byte' ]
    ```
    
    Though in this PR, we introduce the use of
    https://crates.io/crates/tree-sitter-bash for parsing (which
    incidentally we were already using in
    [`codex-apply-patch`](https://github.com/openai/codex/blob/c9e2def49487585cfe6f8bb7b2be442e8c0b5e1b/codex-rs/apply-patch/Cargo.toml#L18)),
    which gives us a richer parse tree. (Incidentally, if you have never
    played with tree-sitter, try the
    [playground](https://tree-sitter.github.io/tree-sitter/7-playground.html)
    and select **Bash** from the dropdown to see how it parses various
    expressions.)
    
    As a concrete example, prior to this change, our implementation of
    `is_known_safe_command()` could verify things like:
    
    ```
    ["bash", "-lc", "grep -R \"Cargo.toml\" -n"]
    ```
    
    but not:
    
    ```
    ["bash", "-lc", "grep -R \"Cargo.toml\" -n || true"]
    ```
    
    With this change, the version with `|| true` is also accepted.
    
    Admittedly, this PR does not expand the safety check to support
    subshells, so it would reject, e.g. `bash -lc 'ls || (pwd && echo hi)'`,
    but that can be addressed in a subsequent PR.
  • fix: add true,false,nl to the list of trusted commands (#1676)
    `nl` is a line-numbering tool that should be on the _trusted _ list, as
    there is nothing concerning on https://gtfobins.github.io/gtfobins/nl/
    that would merit exclusion.
    
    `true` and `false` are also safe, though not particularly useful given
    how `is_known_safe_command()` works today, but that will change with
    https://github.com/openai/codex/pull/1668.
  • fix: check flags to ripgrep when deciding whether the invocation is "trusted" (#1644)
    With this change, if any of `--pre`, `--hostname-bin`, `--search-zip`, or `-z` are used with a proposed invocation of `rg`, do not auto-approve.
  • chore(rs): update dependencies (#1494)
    ### Chores
    - Update cargo dependencies
    - Remove unused cargo dependencies
    - Fix clippy warnings
    - Update Dockerfile (package.json requires node 22)
    - Let Dependabot update bun, cargo, devcontainers, docker,
    github-actions, npm (nix still not supported)
    
    ### TODO
    - Upgrade dependencies with breaking changes
    
    ```shell
    $ cargo update --verbose
       Unchanged crossterm v0.28.1 (available: v0.29.0)
       Unchanged schemars v0.8.22 (available: v1.0.4)
    ```
  • Disallow expect via lints (#865)
    Adds `expect()` as a denied lint. Same deal applies with `unwrap()`
    where we now need to put `#[expect(...` on ones that we legit want. Took
    care to enable `expect()` in test contexts.
    
    # Tests
    
    ```
    cargo fmt
    cargo clippy --all-features --all-targets --no-deps -- -D warnings
    cargo test
    ```
  • fix: enable clippy on tests (#870)
    https://github.com/openai/codex/pull/855 added the clippy warning to
    disallow `unwrap()`, but apparently we were not verifying that tests
    were "clippy clean" in CI, so I ended up with a lot of local errors in
    VS Code.
    
    This turns on the check in CI and fixes the offenders.
  • feat: initial import of Rust implementation of Codex CLI in codex-rs/ (#629)
    As stated in `codex-rs/README.md`:
    
    Today, Codex CLI is written in TypeScript and requires Node.js 22+ to
    run it. For a number of users, this runtime requirement inhibits
    adoption: they would be better served by a standalone executable. As
    maintainers, we want Codex to run efficiently in a wide range of
    environments with minimal overhead. We also want to take advantage of
    operating system-specific APIs to provide better sandboxing, where
    possible.
    
    To that end, we are moving forward with a Rust implementation of Codex
    CLI contained in this folder, which has the following benefits:
    
    - The CLI compiles to small, standalone, platform-specific binaries.
    - Can make direct, native calls to
    [seccomp](https://man7.org/linux/man-pages/man2/seccomp.2.html) and
    [landlock](https://man7.org/linux/man-pages/man7/landlock.7.html) in
    order to support sandboxing on Linux.
    - No runtime garbage collection, resulting in lower memory consumption
    and better, more predictable performance.
    
    Currently, the Rust implementation is materially behind the TypeScript
    implementation in functionality, so continue to use the TypeScript
    implmentation for the time being. We will publish native executables via
    GitHub Releases as soon as we feel the Rust version is usable.