Search by

winplaybox / composer-plugin-guard

Winplaybox

Offline CI audit of the locked Composer plugin set against a reviewed allowlist, with baselines, type-change detection and SARIF output.

Package info

github.com/winplaybox-npm/composer-plugin-guard

pkg:composer/winplaybox/composer-plugin-guard

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-30 15:59 UTC

This package is auto-updated.

Last update: 2026-11-30 20:39:41 UTC


README

CI Packagist

Offline CI check of the locked Composer plugin set against a reviewed allowlist. It runs before composer install, so a transitive dependency cannot quietly become an executable Composer plugin.

It reads composer.json and composer.lock as data only. Composer, plugins and scripts never run, and the tool makes no network requests.

Why

Composer plugins ("type": "composer-plugin") run code inside Composer on every install and update. Composer's config.allow-plugins is the real gate, and this tool complements it:

  • It fails CI when a new plugin appears in the lock file, or when a package changes type from library to plugin.
  • It flags allow-plugins: true, cross-vendor wildcards, and plugins with no decision.
  • It keeps one reviewed policy in version control, which is useful for open-source projects and for teams without Private Packagist plugin restrictions.

It is not a vulnerability scanner or malware detector. Use composer audit and Composer's dependency policies for that.

Install

composer require --dev winplaybox/composer-plugin-guard

Requires PHP 8.2+. Reads Composer 2.2+ lock files.

Usage

vendor/bin/composer-plugin-guard check --locked                     # uses .composer-plugin-guard.json if present
vendor/bin/composer-plugin-guard check --policy ci/plugins.json --format sarif -o plugins.sarif
vendor/bin/composer-plugin-guard check --report-only                # onboarding: never fail
vendor/bin/composer-plugin-guard check --write-baseline             # record reviewed package types
41 locked package(s), 2 plugin(s)
  plugin composer/installers v2.3.0 (composer-plugin)
  plugin php-http/discovery 1.20.0 (composer-plugin)
error[CPG003] dependency-plugin: composer.lock: php-http/discovery changed type from "library" (1.14.3) to "composer-plugin" (1.20.0) and can now execute during Composer runs
note[CPG010] root-script: composer.json: root script "post-install-cmd" defines 1 command(s) and runs automatically on this Composer event; root scripts are your own code, unlike dependency plugins
1 error(s), 0 warning(s), 1 note(s)

Exit codes: 0 ok, 1 findings at or above --fail-on (default error), 2 usage or input error (missing or malformed files).

Without a policy file every plugin is reported as a warning (CPG001), so the first run does not fail. Add a policy to enforce the allowlist.

Since the tool only reads files, run it before composer install in CI:

- run: composer global require winplaybox/composer-plugin-guard
- run: ~/.composer/vendor/bin/composer-plugin-guard check --locked --format sarif -o plugins.sarif
- uses: github/codeql-action/upload-sarif@v4
  if: always()
  with:
    sarif_file: plugins.sarif
- run: composer install

Policy (.composer-plugin-guard.json)

{
  "version": 1,
  "allow": ["composer/installers", "php-http/discovery", "phpstan/*"],
  "deny": ["evil-vendor/*"],
  "wildcards": "report",
  "baseline": ".composer-plugin-guard.baseline.json",
  "includeDev": true,
  "reportScripts": true,
  "reportRepositories": true,
  "severity": { "CPG004": "error", "CPG010": "off" }
}
  • allow / deny: exact vendor/package names, or wildcards limited to one literal vendor (acme/*, acme/composer-*). * and */x are rejected. Deny wins over allow.
  • wildcards: how broad allow-plugins wildcards in composer.json are treated: report (warning), deny (error) or allow (ignored).
  • baseline: relative to the policy file. Write it with --write-baseline and commit it.
  • severity: per-rule error, warning, note or off.
  • Unknown keys and malformed entries are rejected.

Rules

ID Name Category Default
CPG001 plugin-not-allowed dependency-plugin error (warning without a policy)
CPG002 plugin-denied dependency-plugin error
CPG003 plugin-type-changed dependency-plugin error
CPG004 new-plugin dependency-plugin warning
CPG005 allow-plugins-true configuration error
CPG006 broad-wildcard configuration warning
CPG007 missing-decision configuration warning
CPG008 blocked-by-composer configuration note
CPG009 custom-repository repository note
CPG010 root-script root-script note
CPG011 legacy-installer dependency-plugin warning
CPG012 baseline-missing configuration note
CPG013 stale-decision configuration note
CPG014 plugin-removed dependency-plugin note

IDs are stable. JSON and SARIF findings include rule ID, category, severity, file, package, version and type. Output is sorted, so it is deterministic.

Execution surfaces

  • Dependency plugins (composer-plugin, legacy composer-installer) run code from vendor/ inside Composer when allow-plugins permits it. This is the main target of the tool.
  • Root scripts (scripts in your own composer.json) run on Composer events. They are reported as notes for review, with event name and command count only. Script bodies are never printed.
  • Custom repositories (vcs, path, artifact, package, non-Packagist composer) decide where code comes from. Credentials in URLs are masked.

Baseline review

  1. Run --write-baseline and commit the file.
  2. Each PR that adds a plugin (CPG004) or turns a library into a plugin (CPG003) is reported.
  3. After reviewing, update allow and re-run --write-baseline in the same PR.

Library

use Winplaybox\ComposerPluginGuard\{Audit, Policy, Severity};

$report = Audit::run('composer.json', 'composer.lock', Policy::fromFile('.composer-plugin-guard.json'));
if ($report->failsAt(Severity::Error)) {
    echo $report->toText();
}

False positives

  • A plugin you trust: add it to allow.
  • A rule you don't need: set it to off under severity.
  • Dev-only plugins: set "includeDev": false or pass --no-dev.

Safety

  • Parses JSON with size (32 MiB) and depth limits, and rejects malformed or ambiguous lock files, such as a package locked twice.
  • No subprocesses, no network access, no telemetry, and no environment variables are read. A test checks the source for process and network calls.
  • The only file it writes is the baseline, and only with --write-baseline.

License

MIT