apache-magpie
Apache Magpie agentic skills for maintaining open-source projects. Install the per-family plugins you use, so a session loads only what you need.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Check it deeper on your machine
Its scripts were only partly scanned.
As a Claude Code plugin, install it and then ask Claude Code:
/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/apache/magpie with scanskillsafety
Or from a terminal, clone it and run it:
git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/apache/magpie'
It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.
Badge for your README
Markdown
[](/listings/apache--magpie)HTML
<a href="/listings/apache--magpie"><img src="/api/listings/apache--magpie/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
**Start here → [Quick start](docs/quick-start.md)** — a handful of commands, in the agent you already use. Nothing is written to your repository.
/plugin marketplace add apache/magpie # Claude Code /plugin install magpie-setup@apache-magpie # install this one first /plugin install magpie-vetted-ops@apache-magpie # always: the skills run on it /plugin install magpie-agent-guard@apache-magpie # the baseline: /plugin install magpie-utilities@apache-magpie # take all four /plugin install magpie-pr-management@apache-magpie # + the families you need /plugin install magpie-security-tools@apache-magpie # + the framework tools the families run
Those first four are the **baseline** — and the same set a project commits as its floor when it adopts Magpie, so taking them is taking what a project would recommend to every contributor. After that, install **one plugin per family you actually want**: every installed skill costs context on every turn, used or not (~0.2–2.0k tokens a family), so there is deliberately no install-everything plugin.
Once `magpie-setup` is in, you never type these again — ask in plain language (*"install the Magpie families for PR review"*) and the setup skill runs the installs for you.
Codex, VS Code / Copilot, Antigravity, Pi and Goose are short too — the [quick start](docs/quick-start.md) has each of them, plus what to run next to put the agent in its sandbox. Nothing is committed to your repository.
**Fallback — the pinned snapshot install.** Use it when a marketplace is not an option or not enough: your agent has no plugin mechanism, you need the signed ASF source release rather than a git clone, or the project wants every contributor and CI job pinned to one committed version with drift detection.
1. [Download / pin a release](https://magpie.apache.org/downloads/) 2. Set up the symlinks and git-ignores — see [`docs/setup/install-recipes.md`](docs/quick-start/other-install-methods.md) 3. Ask your agent to complete the install: `/magpie-setup:setup install`
The two are complementary, not exclusive.
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
.claude-plugin/marketplace.json · Manifest · 94 lines
- {
- "name": "apache-magpie",
- "owner": {
- "name": "Apache Magpie",
- "url": "https://magpie.apache.org/"
- },
- "description": "Apache Magpie agentic skills for maintaining open-source projects. Install the per-family plugins you use, so a session loads only what you need.",
- "plugins": [
- {
- "name": "magpie-adversarial-review",
- "source": "./plugins/magpie-adversarial-review",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie \u2014 adversarial review: runs other models' CLIs (Codex, Copilot, Antigravity, Pi, Grok, Goose, Claude) read-only over a change before its PR is created, and merges their findings. Runs from the installed plugin, so no repository needs a copy."
- },
- {
- "name": "magpie-agent-guard",
- "source": "./plugins/magpie-agent-guard",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie \u2014 deterministic pre-execution command guard: a PreToolUse hook that denies shell commands which would break a hard framework rule. Runs from the installed plugin, so no repository or worktree needs a local copy."
- },
- {
- "name": "magpie-security-tools",
- "source": "./plugins/magpie-security-tools",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie \u2014 the framework tools the skills run as <framework>/tools/<tool> (security tracker edits and CVE JSON, PR and release management, contributor metrics, the privacy gate, setup's permission audit), shipped so a marketplace install needs no framework checkout. The name is historical: every family that runs one of these tools needs this plugin."
- },
- {
- "name": "magpie-vetted-ops",
- "source": "./plugins/magpie-vetted-ops",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie \u2014 vetted-ops: a dispatcher for fixed, policy-scoped forge operations, so a session needs one allowlist entry instead of a dozen wildcard `ask` rules. Runs from the installed plugin, which is what keeps the operation catalogue out of reach of the agent that calls it."
- },
- {
- "name": "magpie-contributor-growth",
- "source": "./plugins/magpie-contributor-growth",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie contributor-growth family (9 skills)."
- },
- {
- "name": "magpie-issue",
- "source": "./plugins/magpie-issue",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie issue family (8 skills)."
- },
- {
- "name": "magpie-mentoring",
- "source": "./plugins/magpie-mentoring",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie mentoring family (4 skills)."
- },
- {
- "name": "magpie-pairing",
- "source": "./plugins/magpie-pairing",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie pairing family (2 skills)."
- },
- {
- "name": "magpie-pr-management",
- "source": "./plugins/magpie-pr-management",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie pr-management family (10 skills)."
- },
- {
- "name": "magpie-release-management",
- "source": "./plugins/magpie-release-management",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie release-management family (10 skills)."
- },
- {
- "name": "magpie-repo-health",
- "source": "./plugins/magpie-repo-health",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie repo-health family (8 skills)."
- },
- {
- "name": "magpie-security",
- "source": "./plugins/magpie-security",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie security family (16 skills)."
- },
- {
- "name": "magpie-setup",
- "source": "./plugins/magpie-setup",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie setup family (12 skills)."
- },
- {
- "name": "magpie-utilities",
- "source": "./plugins/magpie-utilities",
- "version": "0.9.0.dev202611180540",
- "description": "Apache Magpie utilities family (6 skills)."
- }
- ]
- }
README.md · README · 229 lines
- <!-- SPDX-License-Identifier: Apache-2.0
- https://www.apache.org/licenses/LICENSE-2.0 -->
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
- - [Apache Magpie](#apache-magpie)
- - [See it in action](#see-it-in-action)
- - [Install](#install)
- - [Usage](#usage)
- - [Update / maintain](#update--maintain)
- - [Skill families](#skill-families)
- - [External skill sources](#external-skill-sources)
- - [Acknowledgements](#acknowledgements)
- - [Cross-references](#cross-references)
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
- <!-- SPDX-License-Identifier: Apache-2.0
- https://www.apache.org/legal/release-policy.html -->
- # Apache Magpie
- [](https://magpie.apache.org/)
- **Adopt a Magpie.** Magpie is a curated set of skills for the AI agent you
- already use — Claude Code, Codex, Antigravity, Copilot and others — that take
- on the repetitive parts of running an open-source project: triaging issues and
- pull requests, reviewing code, mentoring contributors, drafting fixes, and
- handling security reports end to end.
- **Three things make it different from a folder of prompts:**
- - **Nothing is sent in your name.** Every comment, email, label and PR is
- *drafted* by the agent and posted by a person. There is no autonomous mode.
- - **The agent is confined before it reads anything real.** A filesystem and
- network sandbox, a credential-stripped environment, and a deterministic
- guard that inspects each shell command *before* it runs and denies the ones
- that break a hard rule — not a prompt asking it nicely.
- - **It is an Apache project, not a product.** Apache-2.0, vendor-neutral
- across agents, no account and no service in the middle. Telemetry is opt-in
- per project and off by default — install it and never run a skill, and it
- generates no outbound traffic at all.
- Magpie is currently in development for ASF projects + Python Core team
- friendlies. Testers welcome!
- ## See it in action
- One security report, start to finish — installed from the marketplace, the
- agent sandboxed and guarded, then the report imported, triaged against the
- project's history, fixed, and published as a CVE:
- 
- *Illustrative — a written transcript, rendered deterministically, not a
- recording.* The [**interactive version**](https://magpie.apache.org/#see-it-in-action)
- on the project site steps through the same story with the full output of each
- command.
- > [!IMPORTANT]
- > The motivation, scope, and design commitments behind this work
- > live in [`MISSION.md`](MISSION.md) — the founding mission of the
- > Apache Magpie Top-Level Project, originally filed as its
- > establishment proposal. Read that for the *why*; this README is
- > the *how* once you've decided to install.
- ## Install
- **Start here → [Quick start](docs/quick-start.md)** — a handful of commands,
- in the agent you already use. Nothing is written to your repository.
- ```text
- /plugin marketplace add apache/magpie # Claude Code
- /plugin install magpie-setup@apache-magpie # install this one first
- /plugin install magpie-vetted-ops@apache-magpie # always: the skills run on it
- /plugin install magpie-agent-guard@apache-magpie # the baseline:
- /plugin install magpie-utilities@apache-magpie # take all four
- /plugin install magpie-pr-management@apache-magpie # + the families you need
- /plugin install magpie-security-tools@apache-magpie # + the framework tools the families run
- ```
- Those first four are the **baseline** — and the same set a project commits as
- its floor when it adopts Magpie, so taking them is taking what a project would
- recommend to every contributor. After that, install **one plugin per family you
- actually want**: every installed skill costs context on every turn, used or
- not (~0.2–2.0k tokens a family), so there is deliberately no
- install-everything plugin.
- Once `magpie-setup` is in, you never type these again — ask in plain language
- (*"install the Magpie families for PR review"*) and the setup skill runs the
- installs for you.
- Codex, VS Code / Copilot, Antigravity, Pi and Goose are short too — the
- [quick start](docs/quick-start.md) has each of them, plus what to run next to put
- the agent in its sandbox. Nothing is committed to your repository.
- **Fallback — the pinned snapshot install.** Use it when a marketplace is not
- an option or not enough: your agent has no plugin mechanism, you need the
- signed ASF source release rather than a git clone, or the project wants every
- contributor and CI job pinned to one committed version with drift detection.
- 1. [Download / pin a release](https://magpie.apache.org/downloads/)
- 2. Set up the symlinks and git-ignores — see
- [`docs/setup/install-recipes.md`](docs/quick-start/other-install-methods.md)
- 3. Ask your agent to complete the install: `/magpie-setup:setup install`
- The two are complementary, not exclusive.
- ## Usage
- Magpie is used by interacting with your AI agents. You'll use plain-language
- prompts like
- > review PR #5193
- or
- > triage the latest security reports
- or skill calls starting with a slash, like
- > /magpie-repo-health:dependency-vulnerability-audit
- (the family-plugin form, assuming the recommended marketplace install above —
- see [Skill names differ by install method](docs/setup/marketplace.md#skill-names-differ-by-install-method)
- if you're on the pinned-snapshot fallback instead).
- ## Update / maintain
- **Upgrading is one command on every install:** say *"upgrade magpie"*, or run `/magpie-setup:upgrade` on the marketplace install.
- It moves to the new version when it has to, then checks this machine and this project and applies the fixes you approve.
- After Magpie changes, every skill asks whether to upgrade until you have.
- Each agent's spelling and update command: [Upgrading Magpie](docs/setup/marketplace.md#upgrading-magpie).
- **Marketplace install** (the recommended path above):
- - `/plugin marketplace update apache-magpie` then
- `/plugin update <plugin>@apache-magpie` — refresh the marketplace
- metadata, then bump the installed plugin(s) to its latest.
- Auto-update does the same in the background once enabled.
- - Reconciliation needs no extra step.
- Each skill checks itself on its first run after an upgrade and proposes any fixes your configuration or overrides need.
- To check the whole project at once, run `/magpie-setup:setup reconcile`.
- See [Reconciliation when a skill first runs after an upgrade](docs/setup/marketplace.md#reconciliation-when-a-skill-first-runs-after-an-upgrade).
- - If you use the secure agent setup, the same pre-flight proposes
- `/magpie-setup:isolated-setup-update` after an upgrade that changed its files, and weekly otherwise.
- Run it directly to check now.
- See [Automatic reminders from the pre-flight](docs/setup/secure-agent-setup.md#automatic-reminders-from-the-pre-flight).
- - Add or drop families by installing or uninstalling their plugin —
- there is no separate "pick families" step once you're on a
- marketplace install.
- **Pinned-snapshot install** (the fallback):
- - the `upgrade` skill (`magpie-setup-upgrade` on this install) — refresh the snapshot to the version the
- committed lock pins (it runs `/magpie-setup update`), reconcile any
- overrides against the new framework structure, then check and fix
- this machine and project.
- - `/magpie-setup verify` — read-only health check (snapshot
- intact, symlinks live, `.gitignore` correct, etc.).
- - `/magpie-setup:setup override <framework-skill>` — open or
- scaffold an override file for a framework skill.
- ## Skill families
- The following skill families ship in the framework, all at `experimental` or
- `stable`, and each skill declares its family in a `family:` frontmatter
- key. On the recommended marketplace install, you choose families by which
- per-family plugin(s) you install (see [Install](#install) above) — install
- or uninstall a plugin at any time to add or drop a family. On the
- pinned-snapshot fallback, `/magpie-setup` offers the **opt-in** families —
- and the optional **MCP servers** (`ponymail`, `apache-projects`,
- `gmail-plaintext`) — in a single install choice, and symlinks for the picked
- families land in the skill directory. Either way, the two **always-on**
- families (`setup`, `utilities`) are wired unconditionally and never prompted
- for.
- The **Modes** column maps each family to the MISSION agent-assistance
- taxonomy — see [`docs/modes.md`](docs/modes.md) for what each mode
- means and which modes are still proposed vs. shipping today.
- | Family | Type | Modes | Purpose | Detail |
- |---|---|---|---|---|
- | [**Setup**](docs/setup/README.md) | always-on | (infra) | Isolated agent setup, framework install + maintenance, shared-config sync. The prerequisite — at minimum the `setup` skill itself runs out of this family. | 12 skills, [`docs/setup/`](docs/setup/) |
- | [**Skill tools**](docs/utilities/README.md) | always-on | (meta) | Framework meta-skills for discovering, authoring, and maintaining skills, and reporting framework bugs. | 5 skills |
- | [**Security reports**](docs/security/README.md) | opt-in | Triage, Drafting | 16-step security-issue handling lifecycle — from `security@` import through CVE publication, including state sync — plus producing, verifying, and maintaining the project's own security model. Maintainer-only. | 16 skills, [`docs/security/`](docs/security/) |
- | [**Pull requests**](docs/pr-management/README.md) | opt-in | Triage | Maintainer-facing PR-queue management — triage, stats, deep code review, stack review, express-lane merge, stale-sweep, reviewer routing, and pre-first-PR checks. | 9 skills, [`docs/pr-management/`](docs/pr-management/README.md) |
- | [**Issues**](docs/issue-management/README.md) | opt-in | Triage, Drafting | General-issue lifecycle: triage, reproduction, fix drafting, reassess, stale-sweep, deduplication, and backlog reporting. | 8 skills, [`docs/issue-management/`](docs/issue-management/README.md) |
- | [**Releases**](docs/release-management/README.md) | opt-in | Triage, Drafting | 14-step ASF release lifecycle, planning issue, RC cut + sign, `[VOTE]` thread, tally, promote, `[ANNOUNCE]`, archive, audit log. Agent never holds the RM's signing key and never publishes the release. **Experimental**, all 10 skills shipped. | 10 skills, [`docs/release-management/`](docs/release-management/) |
- | [**Repository maintenance**](docs/repo-health/README.md) | opt-in | Triage | Repository maintenance audits and fixes: obsolete runner labels, Actions workflow security, dependency vulnerabilities, dependency licence review, license/NOTICE compliance, flaky-test patterns, workflow runner-usage optimization, plus fixes for audit findings. | 8 skills, [`docs/repo-health/`](docs/repo-health/) |
- | [**Local code review**](docs/pairing/README.md) | opt-in | Pairing | Pair a change with a structured self-review or a multi-agent adversarial review before it lands. | 2 skills, [`docs/pairing/`](docs/pairing/README.md) |
- | [**Mentoring**](docs/mentoring/README.md) | opt-in | Mentoring | Newcomer-facing mentoring — first-contact welcome, newcomer-issue explanations, and good-first-issue authoring + backlog curation. **Experimental**. | 4 skills, [`docs/mentoring/`](docs/mentoring/README.md) |
- | [**Committer readiness and onboarding**](docs/contributor-growth/README.md) | opt-in | Triage, Mentoring | The path-to-committer track: activity sweeps, nomination briefs, contributor-sentiment signals, readiness tracking, threshold calibration, candidate screening, committer / post-vote onboarding, and contributor identity mapping across Slack, Discord, and social media. | 9 skills, [`docs/contributor-growth/`](docs/contributor-growth/README.md) |
- ### External skill sources
- Skill families or individual skills can be pulled
- from a **trusted external source** — a repo other than `apache/magpie` that
- ships Magpie-shaped skills (with their evals and tests). Where a skill
- directory would sit, a `skills/<name>/source.md` **redirect** names a
- pinned, verified source the adopter has vouched for; `/magpie-setup` fetches
- it into the gitignored snapshot and wires it in exactly like a framework
- skill. Nothing is fetched unless the adopter commits the pin — see
- [`docs/skill-sources/`](docs/skill-sources/README.md),
- [`PRINCIPLES.md` §14](PRINCIPLES.md#14-one-easy-install-that-upgrades-and-reconciles-never-vendored-copies),
- and [`RFC-AI-0006`](docs/rfcs/RFC-AI-0006.md).
- ## Acknowledgements
- Apache Magpie was first developed and proven inside **Apache Airflow**, and was
- maintained for a time as the `apache/airflow-steward` repository under the
- Airflow PMC before being renamed and established as its own project. It also
- incorporates early skill work contributed by way of the **Apache Groovy**
- community. All of that code carries the same rightsholder — Copyright The Apache
- Software Foundation, under the Apache License 2.0 — so it is not a third-party
- inclusion; the required attribution lines from the originating projects' NOTICE
- files are reproduced in [`NOTICE`](NOTICE).
- ## Cross-references
- - [`MISSION.md`](MISSION.md) — founding mission of the established TLP: motivation, scope, design commitments, initial PMC composition target.
- - [`docs/setup/agentic-overrides.md`](docs/setup/agentic-overrides.md) — the contract between adopters who write overrides and framework skills that read them.
- - [`docs/prerequisites.md`](docs/quick-start/prerequisites.md) — what a maintainer needs installed before invoking any framework skill (Claude Code, Gmail MCP, GitHub auth, browser, `uv`, etc.).
- - [`docs/source-release-contents.md`](docs/source-release-contents.md) — what ships in the signed `apache-magpie-<version>-source.zip` (and what is excluded), with the rationale for the repository-root metadata/config files it keeps.
- - [`docs/release-management/manual-release-process.md`](docs/release-management/manual-release-process.md) — the concrete, as-executed runbook for cutting a Magpie release by hand on the current hybrid SVN-dist + ATR-vote backend (with the abstract per-backend runbooks and the 14-step lifecycle alongside it in [`docs/release-management/`](docs/release-management/README.md)).
- - [`AGENTS.md`](AGENTS.md) — agent instructions, placeholder convention, framework conventions.
- - [`CONTRIBUTING.md`](CONTRIBUTING.md) — for framework contributors.
plugins/magpie-security-tools/tools/permission-audit/src/permission_audit/opencode.py · Bundled script · 176 lines · 1 finding marked
- # Licensed to the Apache Software Foundation (ASF) under one
- # or more contributor license agreements. See the NOTICE file
- # distributed with this work for additional information
- # regarding copyright ownership. The ASF licenses this file
- # to you under the Apache License, Version 2.0 (the
- # "License"); you may not use this file except in compliance
- # with the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing,
- # software distributed under the License is distributed on an
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- # KIND, either express or implied. See the License for the
- # specific language governing permissions and limitations
- # under the License.
- """Audit an OpenCode `permission` config for over-permissioning.
- OpenCode's permission model differs in shape from Claude Code's flat
- `permissions.allow[]` list, so the audit is a separate classifier — but the
- *intent* is the same one this tool applies to Claude: flag configuration that
- **auto-approves dangerous shell execution** (the OpenCode analog of the broad
- `FORBIDDEN_PATTERNS` wildcards the Claude audit removes).
- The `permission` value in `opencode.json` is either:
- - a string (`"allow"` / `"ask"` / `"deny"`) applied to every tool, or
- - an object keyed by tool (`bash`, `edit`, `webfetch`, …). The `bash` key may
- itself be an object mapping glob command patterns to a decision, evaluated
- **last-matching-rule-wins** with a `"*"` default
- (per <https://opencode.ai/docs/permissions/>).
- Pure data + classification — no I/O. The CLI layer reads the file and renders.
- """
- from __future__ import annotations
- from dataclasses import dataclass, field
- from fnmatch import fnmatch
- DECISIONS = frozenset({"allow", "ask", "deny"})
- # Canonical dangerous commands. If a config's *effective* bash decision for any
- # of these resolves to "allow", it auto-approves arbitrary or high-blast-radius
- # execution. Kept representative (not exhaustive), the same posture as the
- # Claude `FORBIDDEN_PATTERNS` list.
- DANGEROUS_COMMANDS: tuple[tuple[str, str], ...] = (
- ("git push origin main", "git push (publish to a remote)"),
- ("sudo rm -rf /", "sudo (privilege escalation)"),
- Note: Quoted as data in code: Runs `rm -rf` against a root or home-directory path
- Line 50 on GitHub
- ("curl http://example.com/x", "curl (network fetch / exfiltration)"),
- ("wget http://example.com/x", "wget (network fetch / exfiltration)"),
- ("rm -rf /tmp/x", "rm -rf (destructive delete)"),
- ("aws s3 ls", "aws (cloud credentials)"),
- ("gcloud auth list", "gcloud (cloud credentials)"),
- ("az login", "az (cloud credentials)"),
- ("kubectl get pods", "kubectl (cluster access)"),
- ("docker run alpine sh", "docker run (container-escape surface)"),
- ("ssh host uptime", "ssh (remote shell)"),
- ("eval something", "eval (arbitrary execution)"),
- ("npx cowsay hi", "npx (arbitrary package execution)"),
- ("uvx ruff check", "uvx (arbitrary package execution)"),
- ("python -c print(1)", "python -c (arbitrary code)"),
- ("bash -c echo", "bash -c (arbitrary code)"),
- )
- @dataclass(frozen=True)
- class OpenCodeFinding:
- """A single OpenCode permission finding.
- `kind` is one of ``blanket-allow`` (the whole `permission` is "allow"),
- ``bash-allow-all`` (bash defaults to allow), or ``dangerous-allow`` (a
- specific rule auto-approves a dangerous command family).
- """
- severity: str # always "forbidden" today
- kind: str
- detail: str
- json_pointer: str
- @dataclass
- class OpenCodeAuditResult:
- forbidden: list[OpenCodeFinding] = field(default_factory=list)
- @property
- def has_findings(self) -> bool:
- return bool(self.forbidden)
- def bash_default(bash_cfg: object) -> str | None:
- """The decision applied to a bash command that matches no specific rule.
- A string `bash` value is itself the default; an object's default is its
- `"*"` entry (OpenCode's own built-in default when absent is "ask").
- """
- if isinstance(bash_cfg, str):
- return bash_cfg if bash_cfg in DECISIONS else None
- if isinstance(bash_cfg, dict):
- value = bash_cfg.get("*")
- return value if value in DECISIONS else None
- return None
- def effective_bash_decision(bash_cfg: object, command: str) -> tuple[str | None, str | None]:
- """Return ``(decision, matched_pattern)`` for `command`, last-match-wins."""
- if isinstance(bash_cfg, str):
- return (bash_cfg if bash_cfg in DECISIONS else None), ("*" if bash_cfg in DECISIONS else None)
- if isinstance(bash_cfg, dict):
- decision: str | None = None
- matched: str | None = None
- for pattern, value in bash_cfg.items():
- if not isinstance(pattern, str) or value not in DECISIONS:
- continue
- if fnmatch(command, pattern):
- decision, matched = value, pattern
- return decision, matched
- return None, None
- def audit_opencode(config: dict) -> OpenCodeAuditResult:
- """Classify an ``opencode.json`` dict for dangerous auto-approval."""
- result = OpenCodeAuditResult()
- permission = config.get("permission")
- # 1. The whole permission policy is a blanket "allow".
- if permission == "allow":
- result.forbidden.append(
- OpenCodeFinding(
- "forbidden",
- "blanket-allow",
- '`permission` is "allow" — every tool (bash included) is auto-approved with no gate. '
- 'Use an object policy that gates bash (e.g. {"bash": {"*": "ask"}}).',
- ".permission",
- )
- )
- return result
- if not isinstance(permission, dict):
- # Absent, or the safe "ask"/"deny" strings — nothing to flag.
- return result
- bash_cfg = permission.get("bash")
- default = bash_default(bash_cfg)
- # 2. bash defaults to allow (string "allow", or "*": "allow").
- if default == "allow":
- result.forbidden.append(
- OpenCodeFinding(
- "forbidden",
- "bash-allow-all",
- 'the default `permission.bash` decision is "allow" — every shell command is '
- 'auto-approved. Set the default ("*") to "ask" or "deny".',
- ".permission.bash",
- )
- )
- # 3. Specific rules that auto-approve a dangerous family while the default
- # is stricter (when the default already allows all, #2 covers it).
- if default != "allow":
- seen: set[str] = set()
- for command, label in DANGEROUS_COMMANDS:
- decision, matched = effective_bash_decision(bash_cfg, command)
- if decision == "allow" and matched is not None and matched != "*" and matched not in seen:
- seen.add(matched) # one finding per over-broad rule, not per sample command
- result.forbidden.append(
- OpenCodeFinding(
- "forbidden",
- "dangerous-allow",
- f'{label} is auto-approved by rule {matched!r} = "allow".',
- f'.permission.bash["{matched}"]',
- )
- )
- return result
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.