ctrlwebinc/security-headers-checker
Composer 安装命令:
composer require ctrlwebinc/security-headers-checker
包简介
A Laravel package to check HTTP security headers
README 文档
README
A Laravel 12 package to check HTTP security headers.
Detects missing, misconfigured, and deprecated security headers, exposes an Artisan command and a REST API endpoint, and returns a security score.
Requirements
- PHP 8.5+
- Laravel 12
Installation
composer require ctrlwebinc/security-headers-checker
The package auto-discovers itself via Laravel's package auto-discovery. No manual registration needed.
Publish the config (optional)
php artisan vendor:publish --tag=security-headers-checker-config
This creates config/security-headers-checker.php where you can customize headers, timeouts, SSL verification, route prefix, and middleware.
Usage
Artisan command
# Basic check php artisan security-headers:check https://example.com # With all options php artisan security-headers:check https://example.com \ --information \ --caching \ --deprecated \ --json # Custom port php artisan security-headers:check https://example.com --port=8443 # With cookie and proxy php artisan security-headers:check https://example.com \ --cookie="session=abc123" \ --proxy=http://127.0.0.1:8080 # Custom request header (repeatable) php artisan security-headers:check https://example.com \ --add-header="Authorization: Bearer mytoken" \ --add-header="X-Custom: value" # Disable SSL verification php artisan security-headers:check https://self-signed.example.com --disable-ssl # Use GET instead of HEAD php artisan security-headers:check https://example.com --use-get
Available options
| Option | Short | Description |
|---|---|---|
--port= |
-p |
Custom port |
--cookie= |
-c |
Cookie string |
--add-header= |
-a |
Extra header (repeatable) |
--disable-ssl |
-d |
Skip SSL/TLS verification |
--use-get |
-g |
GET instead of HEAD |
--json |
-j |
JSON output |
--information |
-i |
Show informational headers |
--caching |
-x |
Show cache headers |
--deprecated |
-k |
Show deprecated headers |
--proxy= |
Proxy URL |
REST API
The package registers a single endpoint:
POST /api/security-headers-checker/analyze
Content-Type: application/json
Request body
{
"url": "https://example.com",
"use_get": false,
"disable_ssl": false,
"cookies": "session=abc123",
"headers": { "Authorization": "Bearer token" },
"proxy": "http://127.0.0.1:8080",
"show_information": false,
"show_caching": false,
"show_deprecated": false
}
Response
{
"success": true,
"data": {
"url": "https://example.com",
"status_code": 200,
"score": 75,
"present": [
{ "header": "Strict-Transport-Security", "value": "max-age=31536000", "flag": null }
],
"missing": [
{ "header": "Content-Security-Policy", "flag": "warning" }
],
"insecure": [
{
"header": "X-Frame-Options",
"value": "ALLOWALL",
"reason": "Value 'ALLOWALL' is not DENY or SAMEORIGIN."
}
],
"deprecated": [],
"information": [],
"caching": []
}
}
To disable the built-in routes and define your own:
// config/security-headers-checker.php 'routes' => [ 'enabled' => false, ],
Then in routes/api.php:
use Ctrlwebinc\SecurityHeadersChecker\Http\Controllers\SecurityHeadersController; Route::post('/my-path/analyze', [SecurityHeadersController::class, 'analyze']);
Facade
use Ctrlwebinc\SecurityHeadersChecker\Facades\SecurityHeadersChecker; $result = SecurityHeadersChecker::analyze('https://example.com', options: [ 'disable_ssl' => true, ], showInformation: true); $score = SecurityHeadersChecker::score($result);
Dependency injection
use Ctrlwebinc\SecurityHeadersChecker\Services\SecurityHeadersService; class MyController extends Controller { public function __construct(private SecurityHeadersService $checker) {} public function check(Request $request): JsonResponse { $result = $this->checker->analyze($request->input('url')); return response()->json(['score' => $this->checker->score($result)]); } }
Configuration
After publishing, edit config/security-headers-checker.php:
return [ 'routes' => [ 'enabled' => true, 'prefix' => 'api/security-headers-checker', 'middleware' => ['api'], ], 'http' => [ 'timeout' => 15, 'verify_ssl' => true, 'use_get' => false, ], // Customize which headers are checked and their severity: // null = critical, 'warning' = best practice, 'deprecated' = should be removed 'security_headers' => [ 'Strict-Transport-Security' => null, 'Content-Security-Policy' => 'warning', 'Expect-CT' => 'deprecated', // ... ], ];
Environment variables:
SECURITY_HEADERS_CHECKER_ROUTES_ENABLED=true SECURITY_HEADERS_CHECKER_ROUTE_PREFIX=api/security-headers-checker SECURITY_HEADERS_CHECKER_TIMEOUT=15 SECURITY_HEADERS_CHECKER_VERIFY_SSL=true
Security score
The score (0–100) is calculated as:
score = (present_critical_headers / total_critical_headers) × 100 − (insecure_count × 10)
| Score | Rating |
|---|---|
| 70–100 | ✅ Good |
| 40–69 | ⚠️ Needs improvement |
| 0–39 | ❌ Insufficient |
Headers checked
Critical (absence = failure)
Strict-Transport-SecurityX-Frame-OptionsX-Content-Type-OptionsX-XSS-Protection
Warning (absence = best-practice warning)
Content-Security-PolicyReferrer-PolicyPermissions-PolicyCross-Origin-Embedder-PolicyCross-Origin-Resource-PolicyCross-Origin-Opener-Policy
Deprecated (presence = warning)
X-Permitted-Cross-Domain-PoliciesExpect-CT
Informational (shown with --information)
Server,X-Powered-By,X-AspNet-Version,X-AspNetMvc-Version
Cache (shown with --caching)
Cache-Control,Pragma,Last-Modified,Expires,ETag
Testing
composer install ./vendor/bin/phpunit
License
MIT
Author
Daniel Le Blanc — daniel.leblanc@ctrlweb.ca — ctrlweb.ca
ctrlwebinc/security-headers-checker 适用场景与选型建议
ctrlwebinc/security-headers-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「security」 「headers」 「laravel」 「security-headers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ctrlwebinc/security-headers-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ctrlwebinc/security-headers-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ctrlwebinc/security-headers-checker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Permissions-Policy (Feature-Policy) header builder and middleware for Laravel
Provide a way to secure accesses to all routes of an symfony application.
PHP polyfill for the Apache Functions. The aim is to provides functions as the PHP way in order to get them available even if PHP is not running as an Apache module.
Helper bundle, configure the request headers from a given base URL.
It's a barebone security class written on PHP
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-23