Download the PHP package zxf/security without Composer

On this page you can find all versions of the php package zxf/security. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package security

![Security's Logo](./resources/images/security.jpg)

zxf/security - Laravel / ThinkPHP 安全中间件

PHP Laravel ThinkPHP

简洁、高效、智能的跨框架安全防护中间件

同时支持 Laravel 11+ThinkPHP 8+,通过统一的桥接层自动适配当前运行框架。


特性


快速开始

安装

Laravel 配置

编辑 .env

Laravel 11+ 中间件注册(推荐)

由于 Laravel 11+ 调整了 Router::middleware() 的行为,ServiceProvider 的自动全局注册在 Laravel 11+ 下会降级为组级注册(web / api)。强烈建议在 bootstrap/app.php 中手动注册全局中间件,确保所有路由(包括非 web/api 路由)都受到保护:

⚠️ Laravel 11+ 注意事项

  • bootstrap/app.php 手动注册是唯一可靠的全局中间件注册方式
  • ServiceProvider 仍会自动将中间件推入 webapi 组作为兜底
  • 如果存在 global 中间件组,也会自动推入

✅ 支持 Laravel 11、12、13

ThinkPHP 8+ 配置

  1. 发布配置文件

    vendor/zxf/security/config/security.php 复制到项目 config/security.php

  2. 注册中间件

    app/middleware.php 中添加:

    或者通过服务类自动注册(在 app/AppService.phpinit() 中):

  3. 配置环境变量

    ThinkPHP 下在 .env 中添加:

📖 详细 ThinkPHP 使用指南:docs/thinkphp.md

内存优化(v5.1+)

本包默认正则模式已从配置文件迁移至独立数据文件,实现延迟加载

添加自定义检测模式:通过 custom_patterns 配置指定额外的模式数据文件,会自动与内置模式合并(也可在运行时调用 PatternService::registerCustomPattern()):

自定义模式数据文件返回与内置一致的数组结构(类型分组或扁平数组均可):

若仅需临时追加/排除某条规则,优先使用 intercept_rules / intercept_rules_exclude 配置,无需新建数据文件。


核心功能

功能 说明
IP白名单 可信IP跳过所有检查
IP黑名单 恶意IP直接拦截
URL路径攻击检测 直接检测URL中的路径遍历等攻击
多重编码检测 检测空字节、UTF-8过度编码、多重URL编码等绕过技术
User-Agent检查 封禁已知恶意扫描器
HTTP头检查 验证Host头、禁止的头信息、CRLF注入检测
请求体大小限制 防止内存溢出攻击
速率限制 防止暴力破解、CC攻击(IP+路由组合key)
SQL注入检测 UNION注入、堆叠查询、时间盲注、错误注入
命令注入检测 系统命令执行防护
路径遍历检测 ../../../etc/passwd
NoSQL注入检测 MongoDB等NoSQL数据库注入防护
SSTI检测 服务器端模板注入防护
SSRF检测 内网IP访问、云元数据、危险协议
CRLF/Header注入检测 HTTP头注入和响应拆分攻击
XSS防护 智能识别Markdown代码块
文件上传检查 禁止WebShell上传
安全响应头 拦截响应添加 X-Content-Type-Options 等安全头

拦截示例

html


拦截回调(高级功能)

通过 before_block_callback 配置,你可以在拦截前执行自定义逻辑:

回调返回值说明

返回值 行为
false 放行 - 请求继续处理
true / null 拦截 - 返回拦截响应给用户

InterceptionContext 对象

回调接收的上下文对象包含以下信息:

使用场景

  1. 动态放行策略 - 根据业务规则临时放行某些请求
  2. 威胁日志记录 - 将拦截事件记录到数据库或外部系统
  3. 实时告警通知 - 发送钉钉/企业微信/短信告警
  4. 威胁情报分析 - 收集攻击数据用于后续分析

自定义拦截页面

通过 response.view 配置自定义拦截视图:

方法1:使用 Blade 视图

创建视图 resources/views/errors/security.blade.php

方法2:使用闭包函数

视图可用变量

变量 类型 说明
$message string 拦截提示消息
$blocked bool 是否被拦截
$threats array 威胁类型数组
$matched_pattern string 匹配的正则模式
$matched_content string 匹配的内容片段

文档


许可证

MIT License - 详见 LICENSE 文件


All versions of security with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-mbstring Version *
ext-json Version *
ext-pcre Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zxf/security contains the following files

Loading the files please wait ...