Skip to content

lifecycle: a project's commands run only once approved - #43

Merged
blockmandev merged 3 commits into
mainfrom
fix/lifecycle-approval
Oct 22, 2026
Merged

blockmandev merged 3 commits into
mainfrom
fix/lifecycle-approval

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Security fix, found while finishing #26's session hooks.

The hole

cli::prepare_session took LifecycleHooks::discover(workspace) and the REPL ran its on_session_start (cli/mod.rs) through the shell when a session opened. The commands come from the project's own .incode/lifecycle.json or the lifecycle section of .incode.json, so opening incode in a freshly cloned repo ran a command that repo chose, with no approval. Nothing else ever sets config.lifecycle_hooks, so in practice every lifecycle command came from the project.

The fix

  • Approval gate. This is the same rule as a project's plugins (plugins: a project's plugin is used only once approved, as its files are #33) and .mcp.json servers.
    • runtime::lifecycle::usable returns the commands only when they are approved as they are now. The key is lifecycle:, the canonical workspace, and a length-framed SHA-256 of every named command.
    • Otherwise it returns none, plus a note naming the file, every command it would have run, and incode lifecycle approve.
  • Which changes need re-approving. A changed, added or moved command needs approving again. The same commands in another checkout are not approved by the first.
  • Unreadable store. A store that can't be read runs nothing and says why.
  • New command: incode lifecycle show|approve|help. It has a completion-table entry and a usage line, and is covered by the verb test.
  • Shared store. Approvals live in the same plugin-approvals.json, through new plugin_approvals::{is_approved, approve_key}; approve now uses approve_key.
  • README updated.
  • Unchanged: your own session_start/session_end hooks in admin.json need no approval.

Tests

  • a_projects_commands_run_only_once_approved_as_they_are: unapproved means not run, and the note names the file and command; after approval they run; after a change they don't.
  • an_approval_is_for_one_workspace
  • an_unreadable_store_runs_nothing
  • the_cli_shows_and_refuses_what_it_cannot_do

Control: making usable skip the approval check fails the first two, with "an unapproved command would run".

Local Windows gate: fmt, clippy -D warnings, cargo test (2222 lib + 59 bin).

A project's .incode/lifecycle.json (or .incode.json's lifecycle section)
arrives with whatever was cloned, and the REPL ran its on_session_start
through the shell at session open with no approval: opening incode in a
cloned repo ran a command that repo chose. As with a project's plugins
and .mcp.json servers, lifecycle::usable now runs them only when the
workspace and a fingerprint of the commands are approved; otherwise it
says what was not run and how to approve it (incode lifecycle approve).
A changed command needs approving again. The approvals share
plugin-approvals.json through plugin_approvals::{is_approved, approve_key}.
Review of the previous commit: the approval screen printed a project's
commands raw, so one holding a carriage return or an ANSI sequence could
redraw itself as something harmless, and a Unicode direction override
could reorder what was read, while the real command was what got
approved and run. Every control character and direction override is now
shown as an escape.
@blockmandev

Copy link
Copy Markdown
Member Author

Pushed a fix from a security review of the first commit. The approval screen printed a project's commands raw, so a command holding a carriage return or an ANSI sequence could redraw itself as something harmless, and a Unicode direction override could reorder what is read. You would approve what you saw, while the real command was what ran.

Every control character and direction override is now shown as an escape (lifecycle::visible).

  • Test: a_command_cannot_disguise_itself_on_the_approval_screen.
  • Control: listing the raw command fails it.

Review of the previous commit: the escape covered control characters and
a hand-written list of direction overrides, and a list falls short (the
Arabic letter mark, zero-width and other format characters, the line
separator). Every character that is not printable ASCII or a space is
now shown as an escape, so nothing can be hidden in what is approved.
@blockmandev

Copy link
Copy Markdown
Member Author

Second review fix. The escape now covers every character that isn't printable ASCII or a space, not a hand-written list of direction characters, which would always miss one (U+061C, zero-width characters, U+2028, the BOM). Shell commands are ASCII in all but rare cases, and those still read as \u{..}.

The test checks U+061C, U+200B, U+2028, U+FEFF and U+2060. Control: passing non-ASCII through unescaped fails it.

@blockmandev
blockmandev merged commit 0bd70d9 into main Oct 22, 2026
7 checks passed
@blockmandev
blockmandev deleted the fix/lifecycle-approval branch November 15, 2026 20:29
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