承接 psalm/plugin-laravel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

psalm/plugin-laravel

Composer 安装命令:

composer require --dev psalm/plugin-laravel

包简介

Psalm plugin for Laravel

README 文档

README

Laravel static analysis with built-in security scanning.

Psalm Laravel Example

Packagist version Packagist downloads Type coverage Tests

The only free tool that combines deep Laravel type analysis with taint-based vulnerability detection. Catches SQL injection, XSS, SSRF, shell injection, file traversal, and open redirects, without running your code.

Note

Already using Larastan? psalm-laravel complements it with security analysis that PHPStan cannot provide.

Security scanning

Plugin ships Laravel-specific taint stubs that track user input from source to sink across your entire codebase. Unlike pattern-matching tools, Psalm follows dataflow across function boundaries, catching vulnerabilities that simpler scanners miss.

// psalm-laravel catches this:
Route::get('/search', function (Request $request) {
    $sortByColumn = $request->input('sort'); // Tainted source: user input from HTTP request
    User::where('name', $request->input('name'))
        ->orderBy($sortByColumn) // 🚨 Tainted sink: unvalidated user input used in query builder
        ->get();

// Psalm output:
// ERROR TaintedSql: Detected tainted SQL
});

Taint analysis also works across helper functions, service classes, and any number of call layers.

// UserController.php
$user->siteSettings['articles_sort'] = $request->input('sort'); // Tainted source: user input from HTTP request
$user->save();

// ArticlesConstoller.php
Articles::query()
    ->orderBy($user->siteSettings['articles_sort']) // 🚨 Tainted sink: unvalidated user input used in query builder
    ->get();

// Psalm output:
// ERROR TaintedSql: Detected tainted SQL

You can read more about how the plugin's taint analysis works and what vulnerabilities it detects in docs/security.md.

Quickstart

Step 1: Install

Since Psalm 7.x is currently in beta, allow dev (or beta) packages first:

composer config minimum-stability dev && composer config prefer-stable true
composer require --dev psalm/plugin-laravel:^4.14

Step 2: Generate a Laravel-tailored psalm.xml

./vendor/bin/psalm-laravel init

This writes a psalm.xml at the project root with the plugin already enabled, sensible errorLevel, and Laravel-friendly issue handler defaults. Pass --level 1 (strictest) through --level 8 (most lenient) to pick a starting strictness. Pass --force to overwrite an existing psalm.xml without prompting.

Step 3: Run

./vendor/bin/psalm-laravel analyze

analyze delegates to vendor/bin/psalm and passes the exit code through, so you can also invoke ./vendor/bin/psalm directly. Security taint analysis runs automatically, no extra flags needed.

Existing projects: the first run will likely report many issues. Create a baseline to suppress them and focus only on new code:

./vendor/bin/psalm --set-baseline=psalm-baseline.xml

From here, gradually increase errorLevel (start at 4, work toward 1) and shrink the baseline over time.

Optional: wire up CI in one command

./vendor/bin/psalm-laravel add github

Writes a ready-to-commit .github/workflows/psalm.yml that runs the plugin on every push and pull request. See docs/github-actions.md for what the generated workflow does and how to customize it.

Configuration

You can customize Psalm configuration using XML config and/or cli parameters.

See docs/config.md for all configuration options.

Custom checks

The plugin ships advanced Laravel-aware static analysis checks that extend Psalm's built-in diagnostics. See docs/issues/index.md for the full catalog.

Versions & Dependencies

Maintained versions:

Laravel Psalm Plugin Laravel Psalm Plugin Status
4.x 12, 13 7-beta Stable
3.x (upgrade to v4) 11, 12, 13 6 Stable
2.x (upgrade to v3) 9, 10, 11 5, 6 Legacy

(Older versions of Laravel, PHP, and Psalm were supported by version 1.x of the plugin, but they are no longer maintained)

See releases for more details about supported PHP, Laravel and Psalm versions.

How it works

Under the hood it reads Laravel's native @method annotations on facade classes and generates alias stubs based on Illuminate\Foundation\AliasLoader (including aliases from your config/app.php and package discovery). It also ships hand-crafted stubs for taint analysis and special cases.

It also parses SQL schema dumps (php artisan schema:dump) and PHP migration files to infer column names and types in your database models.

Psalm-Laravel or Larastan?

Use both. They solve different problems:

  • Larastan excels at Laravel-specific type rules: model-property validation, view-string checks, and 17+ custom rules.
  • Psalm-Laravel in addition to type checks, it provides taint-based security analysis that PHPStan structurally cannot offer, plus deep type support for auth guards, Eloquent attributes, scopes, attributes, etc.

Psalm and PHPStan use almost the same annotation syntax, so they work side by side without conflicts.

Larastan checks your types. We check your security. Use both.

Contributing

Maintained by @alies-dev. There are contributing docs that may help you (and your agents) with contributions.

Areas where help is especially needed:

  • Taint analysis coverage: adding a stub is 5 to 15 lines of annotations and protects thousands of apps. See the authoring guide.
  • Type inference for Laravel magic (Eloquent, Facades, Collections).
  • New checks that enforce Laravel best practices.

psalm/plugin-laravel 适用场景与选型建议

psalm/plugin-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.3M 次下载、GitHub Stars 达 334, 最近一次更新时间为 2019 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「dev」 「psalm」 「psalm-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 psalm/plugin-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 psalm/plugin-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 psalm/plugin-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.3M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 335
  • 点击次数: 33
  • 依赖项目数: 326
  • 推荐数: 1

GitHub 信息

  • Stars: 334
  • Watchers: 7
  • Forks: 79
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-18