Skip to content

fix(extensions): wire up list --available catalog query + harden add --from path traversal#3051

Draft
darion-yaphet wants to merge 3 commits into
github:mainfrom
darion-yaphet:fix/extension-list-available
Draft

fix(extensions): wire up list --available catalog query + harden add --from path traversal#3051
darion-yaphet wants to merge 3 commits into
github:mainfrom
darion-yaphet:fix/extension-list-available

Conversation

@darion-yaphet

Copy link
Copy Markdown
Contributor

What

Wires up the long-advertised extension list --available / --all catalog listing, and hardens extension add --from against path traversal. Split out of the PR-7 structural refactor (#3014) so the behavior change is reviewed on its own, with tests.

Depends on #3014. This branch is built on top of refactor/split-init-pr7 because the handler lives in extensions/_commands.py, which that refactor introduces. Until #3014 merges, its structural-move commit will also show in this diff; it disappears once #3014 lands in main.

Why

The --available / --all flags have existed since the original extension system (#1551), and their help text has always advertised "Show available extensions from catalog." But the implementation was a stub — it printed a static specify extension add <name> hint and never queried the catalog, even though ExtensionCatalog already existed. This is a long-standing dead/misleading-flag fix, not a new feature, and it's orthogonal to the refactor — which is why it's pulled out of #3014.

Changes

  • extension list --available / --all: query the catalog and list uninstalled extensions (filtering out installed IDs). --available lists catalog-only; --all lists installed + available; discovery-only entries are marked; a clear error is surfaced and the command exits non-zero when the catalog is unavailable.
  • extension add --from <url>: sanitize the extension label before building the download filename, so ../-style separators can no longer escape the downloads cache dir (path traversal).

Tests

  • test_extension_list_available.py — catalog query, installed-ID filtering, discovery-only entries, empty catalog, catalog-error exit, --all showing both sections.
  • test_extension_add_path_traversal.py — a traversal label is sanitized so the download stays inside the downloads dir.

Both suites verified red against the pre-fix behavior and green after.

…(PR-7/8)

Convert the flat extensions.py module into an extensions/ package and
extract all extension_app and catalog_app command handlers plus their
private helpers (_resolve_installed_extension, _resolve_catalog_extension,
_print_extension_info) out of __init__.py into the new
extensions/_commands.py, mirroring the domain-dir layout used for
presets/_commands.py (PR-6) and integrations/_commands.py (PR-5).

- extensions.py -> extensions/__init__.py (pure rename, 99%); intra-module
  relative imports bumped from `.x` to `..x` since they reference root
  siblings.
- Root helpers (_require_specify_project, _locate_bundled_extension,
  load_init_options, _display_project_path) are reached through thin shims
  that re-fetch from the parent package at call time, so test
  monkeypatching of specify_cli.<helper> keeps working unchanged.
- __init__.py drops ~1444 lines (3511 -> 2067); CLI surface preserved via
  register(app).

No behavior change. Full suite failure set is identical before/after
(82 pre-existing env failures, 0 new).
…ry the catalog

- extension add --from: sanitize the extension label before building the
  download filename so "../" path separators can no longer escape the
  downloads dir and overwrite arbitrary files
- extension list --available/--all: actually query the catalog and list
  uninstalled extensions (filtering out installed IDs), instead of only
  printing a static install hint that contradicted the CLI help and docs
… path traversal

Add regression coverage for the two behaviors wired up in the preceding fix:

- list --available/--all: queries the catalog, filters installed IDs,
  marks discovery-only entries, reports an empty catalog, and exits 1 on
  catalog failure.
- add --from <url>: a label containing path separators is sanitized so the
  download cannot escape the downloads cache dir.

Both suites were verified red against the pre-fix behavior and green after.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR wires up the previously-stubbed specify extension list --available/--all behavior to actually query the extension catalog (including filtering out installed extensions and marking discovery-only entries), and hardens specify extension add --from <url> by sanitizing the user-provided label before forming the downloaded ZIP filename (preventing path traversal).

Changes:

  • Implement catalog-backed listing for extension list --available and --all, including installed-ID filtering and clearer catalog-unavailable failures.
  • Sanitize the extension label used for --from URL download filenames to prevent ../-style path traversal.
  • Add targeted tests for catalog-backed listing behavior and the path traversal hardening.
Show a summary per file
File Description
tests/test_extension_list_available.py Adds behavioral tests for extension list --available/--all catalog querying, filtering, and error cases.
tests/test_extension_add_path_traversal.py Adds a security regression test ensuring --from label sanitization keeps downloads within the cache directory.
src/specify_cli/extensions/_commands.py Introduces the extension/catalog Typer command handlers (moved from __init__.py) and implements the new list --available/--all + add --from hardening.
src/specify_cli/extensions/__init__.py Updates imports for the new extensions package structure (part of the handler move).
src/specify_cli/__init__.py Registers the new extensions/_commands.py command group to preserve the CLI surface after the move.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

Comment on lines +202 to +214
if show_installed and installed:
console.print("\n[bold cyan]Installed Extensions:[/bold cyan]\n")

for ext in installed:
status_icon = "✓" if ext["enabled"] else "✗"
status_color = "green" if ext["enabled"] else "red"

console.print(f" [{status_color}]{status_icon}[/{status_color}] [bold]{ext['name']}[/bold] (v{ext['version']})")
console.print(f" [dim]{ext['id']}[/dim]")
console.print(f" {ext['description']}")
console.print(f" Commands: {ext['command_count']} | Hooks: {ext['hook_count']} | Priority: {ext['priority']} | Status: {'Enabled' if ext['enabled'] else 'Disabled'}")
console.print()

Comment on lines +179 to +185
@extension_app.command("list")
def extension_list(
available: bool = typer.Option(False, "--available", help="Show available extensions from catalog"),
all_extensions: bool = typer.Option(False, "--all", help="Show both installed and available"),
):
"""List installed extensions."""
from . import ExtensionManager, ExtensionCatalog, ExtensionError
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.

3 participants