Repository navigation
lifecycle: a project's commands run only once approved - #43
Conversation
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.
|
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 (
|
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.
|
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 The test checks U+061C, U+200B, U+2028, U+FEFF and U+2060. Control: passing non-ASCII through unescaped fails it. |
Security fix, found while finishing #26's session hooks.
The hole
cli::prepare_sessiontookLifecycleHooks::discover(workspace)and the REPL ran itson_session_start(cli/mod.rs) through the shell when a session opened. The commands come from the project's own.incode/lifecycle.jsonor thelifecyclesection of.incode.json, so opening incode in a freshly cloned repo ran a command that repo chose, with no approval. Nothing else ever setsconfig.lifecycle_hooks, so in practice every lifecycle command came from the project.The fix
.mcp.jsonservers.runtime::lifecycle::usablereturns the commands only when they are approved as they are now. The key islifecycle:, the canonical workspace, and a length-framed SHA-256 of every named command.incode lifecycle approve.incode lifecycle show|approve|help. It has a completion-table entry and a usage line, and is covered by the verb test.plugin-approvals.json, through newplugin_approvals::{is_approved, approve_key};approvenow usesapprove_key.session_start/session_endhooks 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_workspacean_unreadable_store_runs_nothingthe_cli_shows_and_refuses_what_it_cannot_doControl: making
usableskip 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).