vet README

项目的 README,来自 github.com/laravel/vet。合并为一个 markdown 文件:README.md。

Vet example

[!WARNING] Laravel Vet is archived and gets no more updates. Composer now does this work itself. Read Moving To Composer.

Laravel Vet is a dependency audit for PHP. It shows you the code that composer update is about to write into vendor/, and records the packages you trust in a vet.json file.

Vet runs as a Composer plugin, on every install and update, in any PHP project:

❯ composer update

  to review (1)

  carbonphp/carbon-doctrine-types 3.1.0 → 3.2.0 ............... 1 file changed
  │
  │   ~ src/Carbon/Doctrine/DateTimeType.php
  │     @@ -17,7 +17,7 @@
  │     -    public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTime
  │     +    public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Carbon
  │

  Packages: 1 to review, 124 trusted

   ERROR  [1] package is not trusted. Read every change with [./vendor/bin/vet -v]. Run [./vendor/bin/vet] in a terminal to pick the ones that you trust.

Moving To Composer

Starting with Composer ^2.11, Composer holds back each release younger than a period you choose. Update Composer to the latest version:

composer self-update

Next, move minimum-release-age and minimum-release-age-exclude from vet.json into composer.json:

{
    "config": {
        "policy": {
            "cooldown": {
                "period": "7 days",
                "ignore": {
                    "laravel/*": "We trust the Laravel packages"
                }
            }
        }
    }
}

Composer also blocks each version that Packagist.org flags as malware. Packagist.org takes these flags from Aikido. The block is on by default.

Then remove Vet:

composer remove laravel/vet --dev
rm vet.json

Installation

Requires PHP 8.4+.

You can install Laravel Vet via Composer:

composer require laravel/vet --dev

Next, record the packages you trust today. The --minimum-release-age option holds back every release younger than 7 days:

./vendor/bin/vet --init --minimum-release-age=7
   INFO  Trusted [125] packages, and wrote [vet.json].

   WARN  Vet now holds back each release younger than [7] days. Run [composer update] again to move each package to a release that is old enough.

Run composer update once more, and Composer moves each package to the newest release that is old enough. Commit vet.json.

Auditing Your Dependencies

Run vet to see where you stand:

./vendor/bin/vet
   INFO  All [125] packages are trusted.

Vet exits with a non-zero status when a package is not trusted, so a package that nobody has read fails your build. In a terminal, vet then asks which packages you trust:

 ┌ Which packages do you trust? ────────────────────────────────┐
 │ ◼ acme/logger   1.2.0 → 2.0.0                                │
 │ ◻ acme/tooling  4.1.0 → 4.2.0                                │
 └──────────────────────────────────────────────────────────────┘

   INFO  Recorded [acme/logger] [2.0.0] at [8002bb9cf6c9].

To read every change of one package, pass its name:

./vendor/bin/vet acme/logger

Reviewing With Your Agent

In a terminal, vet asks how you want to review. Pick your coding agent, and it reads the changes of each package and reports back. The agent reads, and you decide:

  acme/logger 1.2.0 → 2.0.0 ................................. 12 files changed
  │  FAIL   src/Ship.php reads .env and sends it to an unknown host

  carbonphp/carbon-doctrine-types 3.1.0 → 3.2.0 .............. 2 files changed
  │  PASS   the changes narrow two return types

PASS means the agent read every file and found no attack. FAIL names each file and the reason. WARN means part of the reading is yours, such as a file too big for the prompt. Vet picks every PASS package in the list for you, so one enter records them, and you read the rest.

The agent runs only when you ask for it. The Composer plugin never asks.

The Trust File

vet.json holds one entry for each package: the version you read, and the hash of its files. When a package ships the same version with different bytes, vet asks you to read the difference:

{
    "require": {
        "carbonphp/carbon-doctrine-types": {
            "version": "3.2.1",
            "hash": "tree-v2:0f158f3b909fc01e691ed5f5121186056232b049031e7d3a914676d49881ece5"
        }
    },
    "require-dev": { … },
    "minimum-release-age": 7,
    "minimum-release-age-exclude": [
        "laravel/*"
    ],
    "ignore": {
        "laravel/framework": [
            "config/cache.php"
        ]
    }
}

minimum-release-age is the number of days a release waits before vet lets it in. A release younger than that fails the audit, even one you trust. Packages under minimum-release-age-exclude skip the wait, and * matches any part of a name. Vet itself always skips it.

ignore lists the paths that a tool rewrites inside vendor/ on purpose, such as the configuration files that Laravel Vapor changes during a deploy. Vet leaves them out of the hash and out of the changes.

To start the trust file again, run ./vendor/bin/vet --fresh. It clears every entry, keeps your settings, and records what vendor/ holds today.

Contributing

Thank you for considering contributing to Laravel! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Vet is open-sourced software licensed under the MIT license.

vet (laravel/vet)

正在搜索数据库…

186 ·GitHub
这是做什么用的?Laravel Vet 是一个 PHP 依赖审计工具:它会把 composer update 即将写入你 vendor/ 目录的代码展示给你看,并把你信任的软件包记录到一个 vet.json 文件里,这样之后的每次更新只会询问有变化的部分。
它只能配合 Laravel 使用,还是任何 PHP 项目都能用?任何带 composer.json 的 PHP 项目都能用:Laravel、Symfony、WordPress 或纯 PHP 项目。虽然名字里有 Laravel,但它其实是一个 Composer 插件,并不是 Laravel 专属的东西。
做代码审查时必须有一个编程智能体吗?不需要——你可以自己阅读依赖的改动。如果你的电脑上已经装了编程智能体(Claude Code、Codex、Gemini、opencode),终端里的第一个问题就会提供它,它替你逐个阅读软件包,但最终决定权仍在你手里。
它稳定吗?还不稳定——目前处于 beta 阶段,README 中警告说在首个正式稳定版发布之前,行为可能会发生变化。
我的代码会离开我的电脑吗?只有在你主动要求智能体审查时才会。Vet 会在发送第一条提示词之前显示提示词的数量和总大小,Composer 插件绝不会自行启动智能体,而且在你做出回答之前,任何内容都不会写入 vet.json。
这个想法是借鉴其他生态的吗?是的——来自 Rust 生态的 cargo vet。README 把 Laravel Vet 描述为同样的思路在 Composer 上的实现:在更新落地之前先阅读它增加了什么,然后记录下你信任哪些软件包。
编程智能体能给出哪些结论?四种:PASS 表示所有文件都已阅读且未发现攻击;FAIL 会列出文件名和原因;WARN 表示部分内容无法阅读(比如过大的文件或 .phar 文件),剩下的要靠你自己;SKIP 表示没有变化或无法发送任何内容。
如果在 CI 中有软件包不受信任,会发生什么?运行会以非零状态码退出,构建会失败,直到有人阅读并信任该软件包。在没有终端的情况下,vet 只会写出报告,不会提出任何问题。
第一次运行会做什么?在 vet.json 存在之前,vet 什么都不会审计,所以第一步是运行 ./vendor/bin/vet --init:它会把 vendor/ 目录中现有的所有软件包记录为受信任。如果你想从一个空的信任文件开始,可以使用 --fresh,并且 vet.json 一旦生成,就应该提交到版本库。
作者
laravel
大小
73.5 MB
星标
186
时长
3个月
提交 · 90 天