Skip to content
Back to search

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.

Checked today

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
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/apache--magpie/badge.svg)](/listings/apache--magpie)

HTML

<a href="/listings/apache--magpie"><img src="/api/listings/apache--magpie/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

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
  1. {
  2. "name": "apache-magpie",
  3. "owner": {
  4. "name": "Apache Magpie",
  5. "url": "https://magpie.apache.org/"
  6. },
  7. "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.",
  8. "plugins": [
  9. {
  10. "name": "magpie-adversarial-review",
  11. "source": "./plugins/magpie-adversarial-review",
  12. "version": "0.9.0.dev202611180540",
  13. "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."
  14. },
  15. {
  16. "name": "magpie-agent-guard",
  17. "source": "./plugins/magpie-agent-guard",
  18. "version": "0.9.0.dev202611180540",
  19. "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."
  20. },
  21. {
  22. "name": "magpie-security-tools",
  23. "source": "./plugins/magpie-security-tools",
  24. "version": "0.9.0.dev202611180540",
  25. "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."
  26. },
  27. {
  28. "name": "magpie-vetted-ops",
  29. "source": "./plugins/magpie-vetted-ops",
  30. "version": "0.9.0.dev202611180540",
  31. "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."
  32. },
  33. {
  34. "name": "magpie-contributor-growth",
  35. "source": "./plugins/magpie-contributor-growth",
  36. "version": "0.9.0.dev202611180540",
  37. "description": "Apache Magpie contributor-growth family (9 skills)."
  38. },
  39. {
  40. "name": "magpie-issue",
  41. "source": "./plugins/magpie-issue",
  42. "version": "0.9.0.dev202611180540",
  43. "description": "Apache Magpie issue family (8 skills)."
  44. },
  45. {
  46. "name": "magpie-mentoring",
  47. "source": "./plugins/magpie-mentoring",
  48. "version": "0.9.0.dev202611180540",
  49. "description": "Apache Magpie mentoring family (4 skills)."
  50. },
  51. {
  52. "name": "magpie-pairing",
  53. "source": "./plugins/magpie-pairing",
  54. "version": "0.9.0.dev202611180540",
  55. "description": "Apache Magpie pairing family (2 skills)."
  56. },
  57. {
  58. "name": "magpie-pr-management",
  59. "source": "./plugins/magpie-pr-management",
  60. "version": "0.9.0.dev202611180540",
  61. "description": "Apache Magpie pr-management family (10 skills)."
  62. },
  63. {
  64. "name": "magpie-release-management",
  65. "source": "./plugins/magpie-release-management",
  66. "version": "0.9.0.dev202611180540",
  67. "description": "Apache Magpie release-management family (10 skills)."
  68. },
  69. {
  70. "name": "magpie-repo-health",
  71. "source": "./plugins/magpie-repo-health",
  72. "version": "0.9.0.dev202611180540",
  73. "description": "Apache Magpie repo-health family (8 skills)."
  74. },
  75. {
  76. "name": "magpie-security",
  77. "source": "./plugins/magpie-security",
  78. "version": "0.9.0.dev202611180540",
  79. "description": "Apache Magpie security family (16 skills)."
  80. },
  81. {
  82. "name": "magpie-setup",
  83. "source": "./plugins/magpie-setup",
  84. "version": "0.9.0.dev202611180540",
  85. "description": "Apache Magpie setup family (12 skills)."
  86. },
  87. {
  88. "name": "magpie-utilities",
  89. "source": "./plugins/magpie-utilities",
  90. "version": "0.9.0.dev202611180540",
  91. "description": "Apache Magpie utilities family (6 skills)."
  92. }
  93. ]
  94. }
README.md · README · 229 lines
  1. <!-- SPDX-License-Identifier: Apache-2.0
  2. https://www.apache.org/licenses/LICENSE-2.0 -->
  3. <!-- START doctoc generated TOC please keep comment here to allow auto update -->
  4. <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
  5. **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
  6. - [Apache Magpie](#apache-magpie)
  7. - [See it in action](#see-it-in-action)
  8. - [Install](#install)
  9. - [Usage](#usage)
  10. - [Update / maintain](#update--maintain)
  11. - [Skill families](#skill-families)
  12. - [External skill sources](#external-skill-sources)
  13. - [Acknowledgements](#acknowledgements)
  14. - [Cross-references](#cross-references)
  15. <!-- END doctoc generated TOC please keep comment here to allow auto update -->
  16. <!-- SPDX-License-Identifier: Apache-2.0
  17. https://www.apache.org/legal/release-policy.html -->
  18. # Apache Magpie
  19. [![Magpie](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/apache/magpie/main/assets/badge.json)](https://magpie.apache.org/)
  20. **Adopt a Magpie.** Magpie is a curated set of skills for the AI agent you
  21. already use — Claude Code, Codex, Antigravity, Copilot and others — that take
  22. on the repetitive parts of running an open-source project: triaging issues and
  23. pull requests, reviewing code, mentoring contributors, drafting fixes, and
  24. handling security reports end to end.
  25. **Three things make it different from a folder of prompts:**
  26. - **Nothing is sent in your name.** Every comment, email, label and PR is
  27. *drafted* by the agent and posted by a person. There is no autonomous mode.
  28. - **The agent is confined before it reads anything real.** A filesystem and
  29. network sandbox, a credential-stripped environment, and a deterministic
  30. guard that inspects each shell command *before* it runs and denies the ones
  31. that break a hard rule — not a prompt asking it nicely.
  32. - **It is an Apache project, not a product.** Apache-2.0, vendor-neutral
  33. across agents, no account and no service in the middle. Telemetry is opt-in
  34. per project and off by default — install it and never run a skill, and it
  35. generates no outbound traffic at all.
  36. Magpie is currently in development for ASF projects + Python Core team
  37. friendlies. Testers welcome!
  38. ## See it in action
  39. One security report, start to finish — installed from the marketplace, the
  40. agent sandboxed and guarded, then the report imported, triaged against the
  41. project's history, fixed, and published as a CVE:
  42. ![Installing Magpie from the marketplace, running the secure-agent and privacy setup, then importing two security reports, triaging one as a high-severity path traversal and the other as not a vulnerability, drafting the fix as a scrubbed public PR, and publishing the CVE](assets/quickstart/demo.svg)
  43. *Illustrative — a written transcript, rendered deterministically, not a
  44. recording.* The [**interactive version**](https://magpie.apache.org/#see-it-in-action)
  45. on the project site steps through the same story with the full output of each
  46. command.
  47. > [!IMPORTANT]
  48. > The motivation, scope, and design commitments behind this work
  49. > live in [`MISSION.md`](MISSION.md) — the founding mission of the
  50. > Apache Magpie Top-Level Project, originally filed as its
  51. > establishment proposal. Read that for the *why*; this README is
  52. > the *how* once you've decided to install.
  53. ## Install
  54. **Start here → [Quick start](docs/quick-start.md)** — a handful of commands,
  55. in the agent you already use. Nothing is written to your repository.
  56. ```text
  57. /plugin marketplace add apache/magpie # Claude Code
  58. /plugin install magpie-setup@apache-magpie # install this one first
  59. /plugin install magpie-vetted-ops@apache-magpie # always: the skills run on it
  60. /plugin install magpie-agent-guard@apache-magpie # the baseline:
  61. /plugin install magpie-utilities@apache-magpie # take all four
  62. /plugin install magpie-pr-management@apache-magpie # + the families you need
  63. /plugin install magpie-security-tools@apache-magpie # + the framework tools the families run
  64. ```
  65. Those first four are the **baseline** — and the same set a project commits as
  66. its floor when it adopts Magpie, so taking them is taking what a project would
  67. recommend to every contributor. After that, install **one plugin per family you
  68. actually want**: every installed skill costs context on every turn, used or
  69. not (~0.2–2.0k tokens a family), so there is deliberately no
  70. install-everything plugin.
  71. Once `magpie-setup` is in, you never type these again — ask in plain language
  72. (*"install the Magpie families for PR review"*) and the setup skill runs the
  73. installs for you.
  74. Codex, VS Code / Copilot, Antigravity, Pi and Goose are short too — the
  75. [quick start](docs/quick-start.md) has each of them, plus what to run next to put
  76. the agent in its sandbox. Nothing is committed to your repository.
  77. **Fallback — the pinned snapshot install.** Use it when a marketplace is not
  78. an option or not enough: your agent has no plugin mechanism, you need the
  79. signed ASF source release rather than a git clone, or the project wants every
  80. contributor and CI job pinned to one committed version with drift detection.
  81. 1. [Download / pin a release](https://magpie.apache.org/downloads/)
  82. 2. Set up the symlinks and git-ignores — see
  83. [`docs/setup/install-recipes.md`](docs/quick-start/other-install-methods.md)
  84. 3. Ask your agent to complete the install: `/magpie-setup:setup install`
  85. The two are complementary, not exclusive.
  86. ## Usage
  87. Magpie is used by interacting with your AI agents. You'll use plain-language
  88. prompts like
  89. > review PR #5193
  90. or
  91. > triage the latest security reports
  92. or skill calls starting with a slash, like
  93. > /magpie-repo-health:dependency-vulnerability-audit
  94. (the family-plugin form, assuming the recommended marketplace install above —
  95. see [Skill names differ by install method](docs/setup/marketplace.md#skill-names-differ-by-install-method)
  96. if you're on the pinned-snapshot fallback instead).
  97. ## Update / maintain
  98. **Upgrading is one command on every install:** say *"upgrade magpie"*, or run `/magpie-setup:upgrade` on the marketplace install.
  99. It moves to the new version when it has to, then checks this machine and this project and applies the fixes you approve.
  100. After Magpie changes, every skill asks whether to upgrade until you have.
  101. Each agent's spelling and update command: [Upgrading Magpie](docs/setup/marketplace.md#upgrading-magpie).
  102. **Marketplace install** (the recommended path above):
  103. - `/plugin marketplace update apache-magpie` then
  104. `/plugin update <plugin>@apache-magpie` — refresh the marketplace
  105. metadata, then bump the installed plugin(s) to its latest.
  106. Auto-update does the same in the background once enabled.
  107. - Reconciliation needs no extra step.
  108. Each skill checks itself on its first run after an upgrade and proposes any fixes your configuration or overrides need.
  109. To check the whole project at once, run `/magpie-setup:setup reconcile`.
  110. See [Reconciliation when a skill first runs after an upgrade](docs/setup/marketplace.md#reconciliation-when-a-skill-first-runs-after-an-upgrade).
  111. - If you use the secure agent setup, the same pre-flight proposes
  112. `/magpie-setup:isolated-setup-update` after an upgrade that changed its files, and weekly otherwise.
  113. Run it directly to check now.
  114. See [Automatic reminders from the pre-flight](docs/setup/secure-agent-setup.md#automatic-reminders-from-the-pre-flight).
  115. - Add or drop families by installing or uninstalling their plugin —
  116. there is no separate "pick families" step once you're on a
  117. marketplace install.
  118. **Pinned-snapshot install** (the fallback):
  119. - the `upgrade` skill (`magpie-setup-upgrade` on this install) — refresh the snapshot to the version the
  120. committed lock pins (it runs `/magpie-setup update`), reconcile any
  121. overrides against the new framework structure, then check and fix
  122. this machine and project.
  123. - `/magpie-setup verify` — read-only health check (snapshot
  124. intact, symlinks live, `.gitignore` correct, etc.).
  125. - `/magpie-setup:setup override <framework-skill>` — open or
  126. scaffold an override file for a framework skill.
  127. ## Skill families
  128. The following skill families ship in the framework, all at `experimental` or
  129. `stable`, and each skill declares its family in a `family:` frontmatter
  130. key. On the recommended marketplace install, you choose families by which
  131. per-family plugin(s) you install (see [Install](#install) above) — install
  132. or uninstall a plugin at any time to add or drop a family. On the
  133. pinned-snapshot fallback, `/magpie-setup` offers the **opt-in** families —
  134. and the optional **MCP servers** (`ponymail`, `apache-projects`,
  135. `gmail-plaintext`) — in a single install choice, and symlinks for the picked
  136. families land in the skill directory. Either way, the two **always-on**
  137. families (`setup`, `utilities`) are wired unconditionally and never prompted
  138. for.
  139. The **Modes** column maps each family to the MISSION agent-assistance
  140. taxonomy — see [`docs/modes.md`](docs/modes.md) for what each mode
  141. means and which modes are still proposed vs. shipping today.
  142. | Family | Type | Modes | Purpose | Detail |
  143. |---|---|---|---|---|
  144. | [**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/) |
  145. | [**Skill tools**](docs/utilities/README.md) | always-on | (meta) | Framework meta-skills for discovering, authoring, and maintaining skills, and reporting framework bugs. | 5 skills |
  146. | [**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/) |
  147. | [**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) |
  148. | [**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) |
  149. | [**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/) |
  150. | [**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/) |
  151. | [**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) |
  152. | [**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) |
  153. | [**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) |
  154. ### External skill sources
  155. Skill families or individual skills can be pulled
  156. from a **trusted external source** — a repo other than `apache/magpie` that
  157. ships Magpie-shaped skills (with their evals and tests). Where a skill
  158. directory would sit, a `skills/<name>/source.md` **redirect** names a
  159. pinned, verified source the adopter has vouched for; `/magpie-setup` fetches
  160. it into the gitignored snapshot and wires it in exactly like a framework
  161. skill. Nothing is fetched unless the adopter commits the pin — see
  162. [`docs/skill-sources/`](docs/skill-sources/README.md),
  163. [`PRINCIPLES.md` §14](PRINCIPLES.md#14-one-easy-install-that-upgrades-and-reconciles-never-vendored-copies),
  164. and [`RFC-AI-0006`](docs/rfcs/RFC-AI-0006.md).
  165. ## Acknowledgements
  166. Apache Magpie was first developed and proven inside **Apache Airflow**, and was
  167. maintained for a time as the `apache/airflow-steward` repository under the
  168. Airflow PMC before being renamed and established as its own project. It also
  169. incorporates early skill work contributed by way of the **Apache Groovy**
  170. community. All of that code carries the same rightsholder — Copyright The Apache
  171. Software Foundation, under the Apache License 2.0 — so it is not a third-party
  172. inclusion; the required attribution lines from the originating projects' NOTICE
  173. files are reproduced in [`NOTICE`](NOTICE).
  174. ## Cross-references
  175. - [`MISSION.md`](MISSION.md) — founding mission of the established TLP: motivation, scope, design commitments, initial PMC composition target.
  176. - [`docs/setup/agentic-overrides.md`](docs/setup/agentic-overrides.md) — the contract between adopters who write overrides and framework skills that read them.
  177. - [`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.).
  178. - [`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.
  179. - [`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)).
  180. - [`AGENTS.md`](AGENTS.md) — agent instructions, placeholder convention, framework conventions.
  181. - [`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
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Audit an OpenCode `permission` config for over-permissioning.
  18. OpenCode's permission model differs in shape from Claude Code's flat
  19. `permissions.allow[]` list, so the audit is a separate classifier — but the
  20. *intent* is the same one this tool applies to Claude: flag configuration that
  21. **auto-approves dangerous shell execution** (the OpenCode analog of the broad
  22. `FORBIDDEN_PATTERNS` wildcards the Claude audit removes).
  23. The `permission` value in `opencode.json` is either:
  24. - a string (`"allow"` / `"ask"` / `"deny"`) applied to every tool, or
  25. - an object keyed by tool (`bash`, `edit`, `webfetch`, …). The `bash` key may
  26. itself be an object mapping glob command patterns to a decision, evaluated
  27. **last-matching-rule-wins** with a `"*"` default
  28. (per <https://opencode.ai/docs/permissions/>).
  29. Pure data + classification — no I/O. The CLI layer reads the file and renders.
  30. """
  31. from __future__ import annotations
  32. from dataclasses import dataclass, field
  33. from fnmatch import fnmatch
  34. DECISIONS = frozenset({"allow", "ask", "deny"})
  35. # Canonical dangerous commands. If a config's *effective* bash decision for any
  36. # of these resolves to "allow", it auto-approves arbitrary or high-blast-radius
  37. # execution. Kept representative (not exhaustive), the same posture as the
  38. # Claude `FORBIDDEN_PATTERNS` list.
  39. DANGEROUS_COMMANDS: tuple[tuple[str, str], ...] = (
  40. ("git push origin main", "git push (publish to a remote)"),
  41. ("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
  42. ("curl http://example.com/x", "curl (network fetch / exfiltration)"),
  43. ("wget http://example.com/x", "wget (network fetch / exfiltration)"),
  44. ("rm -rf /tmp/x", "rm -rf (destructive delete)"),
  45. ("aws s3 ls", "aws (cloud credentials)"),
  46. ("gcloud auth list", "gcloud (cloud credentials)"),
  47. ("az login", "az (cloud credentials)"),
  48. ("kubectl get pods", "kubectl (cluster access)"),
  49. ("docker run alpine sh", "docker run (container-escape surface)"),
  50. ("ssh host uptime", "ssh (remote shell)"),
  51. ("eval something", "eval (arbitrary execution)"),
  52. ("npx cowsay hi", "npx (arbitrary package execution)"),
  53. ("uvx ruff check", "uvx (arbitrary package execution)"),
  54. ("python -c print(1)", "python -c (arbitrary code)"),
  55. ("bash -c echo", "bash -c (arbitrary code)"),
  56. )
  57. @dataclass(frozen=True)
  58. class OpenCodeFinding:
  59. """A single OpenCode permission finding.
  60. `kind` is one of ``blanket-allow`` (the whole `permission` is "allow"),
  61. ``bash-allow-all`` (bash defaults to allow), or ``dangerous-allow`` (a
  62. specific rule auto-approves a dangerous command family).
  63. """
  64. severity: str # always "forbidden" today
  65. kind: str
  66. detail: str
  67. json_pointer: str
  68. @dataclass
  69. class OpenCodeAuditResult:
  70. forbidden: list[OpenCodeFinding] = field(default_factory=list)
  71. @property
  72. def has_findings(self) -> bool:
  73. return bool(self.forbidden)
  74. def bash_default(bash_cfg: object) -> str | None:
  75. """The decision applied to a bash command that matches no specific rule.
  76. A string `bash` value is itself the default; an object's default is its
  77. `"*"` entry (OpenCode's own built-in default when absent is "ask").
  78. """
  79. if isinstance(bash_cfg, str):
  80. return bash_cfg if bash_cfg in DECISIONS else None
  81. if isinstance(bash_cfg, dict):
  82. value = bash_cfg.get("*")
  83. return value if value in DECISIONS else None
  84. return None
  85. def effective_bash_decision(bash_cfg: object, command: str) -> tuple[str | None, str | None]:
  86. """Return ``(decision, matched_pattern)`` for `command`, last-match-wins."""
  87. if isinstance(bash_cfg, str):
  88. return (bash_cfg if bash_cfg in DECISIONS else None), ("*" if bash_cfg in DECISIONS else None)
  89. if isinstance(bash_cfg, dict):
  90. decision: str | None = None
  91. matched: str | None = None
  92. for pattern, value in bash_cfg.items():
  93. if not isinstance(pattern, str) or value not in DECISIONS:
  94. continue
  95. if fnmatch(command, pattern):
  96. decision, matched = value, pattern
  97. return decision, matched
  98. return None, None
  99. def audit_opencode(config: dict) -> OpenCodeAuditResult:
  100. """Classify an ``opencode.json`` dict for dangerous auto-approval."""
  101. result = OpenCodeAuditResult()
  102. permission = config.get("permission")
  103. # 1. The whole permission policy is a blanket "allow".
  104. if permission == "allow":
  105. result.forbidden.append(
  106. OpenCodeFinding(
  107. "forbidden",
  108. "blanket-allow",
  109. '`permission` is "allow" — every tool (bash included) is auto-approved with no gate. '
  110. 'Use an object policy that gates bash (e.g. {"bash": {"*": "ask"}}).',
  111. ".permission",
  112. )
  113. )
  114. return result
  115. if not isinstance(permission, dict):
  116. # Absent, or the safe "ask"/"deny" strings — nothing to flag.
  117. return result
  118. bash_cfg = permission.get("bash")
  119. default = bash_default(bash_cfg)
  120. # 2. bash defaults to allow (string "allow", or "*": "allow").
  121. if default == "allow":
  122. result.forbidden.append(
  123. OpenCodeFinding(
  124. "forbidden",
  125. "bash-allow-all",
  126. 'the default `permission.bash` decision is "allow" — every shell command is '
  127. 'auto-approved. Set the default ("*") to "ask" or "deny".',
  128. ".permission.bash",
  129. )
  130. )
  131. # 3. Specific rules that auto-approve a dangerous family while the default
  132. # is stricter (when the default already allows all, #2 covers it).
  133. if default != "allow":
  134. seen: set[str] = set()
  135. for command, label in DANGEROUS_COMMANDS:
  136. decision, matched = effective_bash_decision(bash_cfg, command)
  137. if decision == "allow" and matched is not None and matched != "*" and matched not in seen:
  138. seen.add(matched) # one finding per over-broad rule, not per sample command
  139. result.forbidden.append(
  140. OpenCodeFinding(
  141. "forbidden",
  142. "dangerous-allow",
  143. f'{label} is auto-approved by rule {matched!r} = "allow".',
  144. f'.permission.bash["{matched}"]',
  145. )
  146. )
  147. return result

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.