Repository navigation
feat(agent-server): Canvas Extensions installation persistence [3/4] - #4364
Conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.
Summary
Reviewed the Canvas Extensions manifest and entrypoint-containment module (openhands-agent-server/openhands/agent_server/canvas_extensions/). All 52 tests pass locally. The PR introduces the manifest schema (CanvasExtensionManifest, CanvasExtensionPage, CanvasExtensionContributes) and the security-critical resolve_entrypoint() containment primitive.
Security Analysis
The entrypoint containment is well-designed with defense-in-depth:
- Syntactic field validation (
_validate_entrypoint) rejects empty strings, absolute paths, and..path components at model construction time. - Filesystem-level containment (
resolve_entrypoint) resolves symlinks viaPath.resolve()and checksis_relative_to(root)— catching symlink escapes, symlinked-directory escapes, symlinked package roots, and the pathlibroot / "/abs"footgun. Theis_file()check additionally rejects directories, dangling symlinks, and symlink cycles (confirmed by the adversarial test suite). package_root.resolve()is called before joining — correctly normalizing a symlinked package root before containment is evaluated.
The function returns the fully-resolved path (symlinks already eliminated), which is the TOCTOU-safe path to serve. The docstring correctly states this must be called immediately before serving — follow-up ticket #4352 (REST API surface) should ensure it serves the returned resolved candidate path directly, not a re-read through root / entrypoint, to avoid a symlink-swap TOCTOU window between resolution and read.
Correctness
- The
candidate != rootguard on line 154 is functionally redundant (is_relative_toreturnsTruewhen paths are equal, sonot is_relative_to(root)is alreadyFalse), but it documents the.edge case explicitly. Not a bug — behavior is identical with or without it. - Name/contribution-id validation reuses
validate_extension_name()from the SDK rather than duplicating the kebab-case regex — consistent with DRY and the repo's reuse-over-duplicate guidance. - Duplicate page id/path detection runs via
field_validatoronpagesand correctly fires throughmodel_validate(dict)(the real JSON ingestion path), verified bytest_duplicate_page_contribution_ids_rejected_through_full_manifest. model_copy(update=...)in the containment tests correctly bypasses field validators (Pydantic v2 design) to testresolve_entrypointin isolation — this is appropriate for adversarial testing of the defense-in-depth layer.
Test Coverage
The adversarial test suite is thorough: textual traversal (4 variants), symlinked file/directory/package-root escapes, symlink cycles, the absolute-path footgun, entrypoint-as-directory, missing entrypoint, and a legitimate in-package symlink that must still resolve. Manifest validation covers required fields, wrong types, duplicate ids/paths, and invalid name/id/path patterns. No gaps identified.
Risk Assessment
Low risk. This PR adds a new self-contained module with no changes to existing code paths — no Agent, Conversation, or existing agent-server routes are modified. The import of openhands.sdk.extensions.installation.utils.validate_extension_name is permitted by the repo's import dependency rules (agent-server to sdk is allowed). The module is not yet wired to any HTTP route (that is #4352), so there is no attack surface exposed in this PR. The security-critical containment logic is sound and well-tested.
Material Findings
No material issues found. The two style-level suggestions from the prior review (comment on line 42, redundant guard on line 154) are non-material and I have no additional inline findings to add.
|
Posted a GitHub PR review on PR #4364 (commit 62ae3b2) as Review summary: The PR adds a thin wrapper around the shared
Risk assessment: Medium. Both inline comments were accepted by the GitHub review API. This comment was posted by an AI agent (OpenHands). |
smolpaws
left a comment
There was a problem hiding this comment.
🐾 Hi, I'm smolpaws — a feline OpenHands agent doing a review pass to help. Reviewed this layer against its base (extension-canvas-2).
Verdict: well-reasoned layer, but the disabled-by-default guarantee has one real gap — it isn't enforced on the load path.
The module's stated promise (docstring) is: every newly created entry, whether from install() or from self-healing directory discovery, lands enabled=False until explicitly enabled. install_canvas_extension and list_installed_canvas_extensions enforce that via _force_disable_new. But:
1. load_installed_canvas_extensions() bypasses the guarantee (installed.py:173).
It calls manager.load_installed() directly — no _force_disable_new, no _tracked_names pre-check (unlike list_installed_canvas_extensions at :166). Chain: load_installed() → list_installed() → session.sync() → discover_untracked(), which builds entries with InstallationInfo.enabled defaulting to True, persists them, then load_installed() returns every enabled one.
So a directory dropped straight into the installed dir — exactly the case your list_installed_canvas_extensions docstring says "also lands disabled" — is loaded enabled on the first load_installed_canvas_extensions() call, and stays enabled because enabled: true is now written to .installed.json. This contradicts both the module docstring and that function's own docstring.
Note load_installed() returns manifests (T), not InstallationInfo, so you can't just reuse _force_disable_new here — you'd want to run the disciplined discover-and-disable pass first, then load only what's still enabled.
2. Minor — the disable is a second write, not atomic with discovery (installed.py:166).
_force_disable_new calls manager.disable(), which does a separate full metadata load/sync/save per discovered entry, on top of the sync list_installed() already ran. Two consequences: (a) discovering N dirs triggers ~N extra directory re-scans + manifest re-parses per list call — correct but wasteful; (b) the "flip to disabled" write is separate from the "discovered as enabled" write, so a reader racing between them can briefly observe the entry enabled. Eventually-consistent, not atomic.
What's sharp: the _tracked_names reasoning — a stale metadata record with no matching directory must not count as "already installed," or a real install would inherit its enabled state as if it were a force-reinstall. That's a subtle correctness point and you got it right. Tests are thorough too.
Fixing #1 is the one I'd want resolved before this ships as the "disabled-by-default" layer. 🐾
enyst
left a comment
There was a problem hiding this comment.
Seem this little detail might be worth a quick pass?
So a directory dropped straight into the installed dir — exactly the case your list_installed_canvas_extensions docstring says "also lands disabled" — is loaded enabled on the first load_installed_canvas_extensions() call, and stays enabled because enabled: true is now written to .installed.json. This contradicts both the module docstring and that function's own docstring.
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
…sabled-by-default guarantee InstallationManager.install() and its self-healing directory discovery both default a freshly created tracked entry to enabled=True. Canvas Extensions require any newly created entry -- from an explicit install or from discovery -- to land disabled until explicitly enabled, so this wraps the shared manager and corrects that as an explicit post-write step, without touching the shared framework used by Plugins/Skills.
…alled_canvas_extensions load_installed_canvas_extensions() called InstallationManager.load_installed() directly, skipping the force-disable pass that list_installed_canvas_extensions() applies to newly discovered entries. A directory dropped straight into the installed dir was loaded (and persisted) as enabled on first load, contradicting the module's disabled-by-default guarantee.
d0aec32 to
8d63bac
Compare
HUMAN:
Adding installation persistence for canvas-extension.
AGENT:
Why
Part of the Canvas Extensions backend build-out (#4348). Issue #4350 identified two concrete bugs in reusing the shared
openhands.sdk.extensions.installationframework (also used by Plugins/Skills) as-is for Canvas Extensions:InstallationInfo.enableddefaults toTrue, and neitherInstallationManager.install()(on a genuinely new install) nor its self-healing directory discovery override that default. A freshly installed or newly discovered canvas extension would come back enabled, when Canvas Extensions require explicit opt-in.This branch also carries #4349 (
requested_reftracking) forward -- it was implemented directly onextension-canvas-2but never had its own PR, since it's small, independent SDK work with no canvas-extensions-specific surface.Note for reviewers: this branch is stacked on top of #4361 (still open, not yet merged), so the diff below currently includes #4348's manifest/containment files again alongside the new work. Those shrink out of this diff automatically once #4361 merges into
main.Summary
openhands-agent-server/openhands/agent_server/canvas_extensions/installed.py: a thin wrapper around the sharedInstallationManager, following the same shape asopenhands/sdk/plugin/installed.py, with on-disk layout at~/.openhands/canvas-extensions/installed/<name>/.enabled=Falseon every write path that creates a new tracked entry (fresh install, self-healing discovery) via an explicit post-write correction, while correctly preserving the prior enabled state on a legitimate force-reinstall of an already-tracked extension. Hardened against a stale/tampered.installed.jsonentry with no matching directory being treated as "already installed."resolve_entrypoint()containment checking (built in Canvas Extensions: manifest model, validation, and entrypoint containment #4348 but never called) at manifest load time, so both install and discovery enforce it.MANIFEST_FILENAME(Final[str]) constant tomanifest.py.update_canvas_extension()deliberately not added -- that's theinstall(force=True)/.update()anti-pattern issue Canvas Extensions: staged install + atomic swap + two-step refresh (check/apply) #4351 (staged install + atomic swap) exists to replace, not something to introduce here.Issue Number
#4350
How to Test
77 tests pass (25 for the new persistence module, plus the existing manifest/containment suites). Coverage includes the three regression scenarios named in #4350 (fresh install lands disabled, a smuggled
enabled: truestale-metadata record is ignored, a manually-placed directory is discovered disabled), force-reinstall state preservation in both directions, mixed-state handling across multiple extensions in one listing call, and rejection/skip paths for malformed manifests, mismatched manifest names, and entrypoint containment escapes at both install and discovery time.Mutation-tested the two highest-stakes correctness properties directly: neutering the force-disable correction fails 5 of the new tests; disabling the pre-existing/new-entry distinction fails the mixed-state and force-reinstall tests specifically. Confirms the tests exercise real logic, not just happy-path assertions.
uv run pre-commit run --files <changed files>passes (ruff format/lint, pyright, import-dependency-rules, tool-subclass-registration).Video/Screenshots
N/A -- backend persistence module only, no UI or HTTP route in this PR (REST API surface is #4352, blocked on this one).
Type
Notes
Scoped to #4350 (+ carrying forward the already-implemented #4349). Everything else in the epic remains separate, already-filed tickets: staged install/atomic swap (#4351, blocked on this), REST API surface (#4352), OpenAPI/typescript-client (#4354), audit logging (#4355), manifest API-scope + reserved names (#4356), adversarial fuzz suite (#4357).