FortressCommunity/FortressWAF

GitHub: FortressCommunity/FortressWAF

用 Go 编写的自托管 WAF 与 API 安全网关,通过多协议检测管道为企业 Web 应用提供实时威胁防护。

Stars: 4 | Forks: 2

# FortressWAF [![License](https://img.shields.io/badge/license-AGPL--3.0-blue)](LICENSE) [![Go Version](https://img.shields.io/badge/Go-1.22+-00ADD8?logo=go)](https://go.dev/) **面向现代 API 的自托管 WAF。** FortressWAF 是一个 Go 反向代理,通过可配置的检测 pipeline 来检查 REST、GraphQL、WebSocket、gRPC 和 SOAP 流量。配置采用 YAML 格式,并在 runtime 生效。单一二进制文件,无需外部依赖。 ## 请求流程 ``` flowchart LR C[Client] --> T[TLS Termination
HTTP/2, ACME, OCSP, mTLS] T --> P[Request Parser
Headers, Body, Params] P --> A[Auth Layer
JWT, OAuth, CAPTCHA, API Keys] A --> PL[Protocol Inspection
GraphQL · gRPC · SOAP · WebSocket] PL --> D[Detection Pipeline] subgraph D[ ] direction TB S[SQL Injection] X[XSS] R[RCE] B[Bot Detection] DD[DDoS / Rate Limit] CR[Credential Protection] AP[API Protection] PR[Protocol Anomaly] UF[Upload Security] end D --> SC[Scoring Engine
Block · Challenge · Rate-Limit · Allow] SC --> UP[Proxy Forwarder] UP --> OR[Origin Server] SC -.-> LOG[SIEM Export
Elasticsearch · Splunk · JSON Log] SC -.-> PROM[Prometheus Metrics] SC -.-> ML[Ml Sidecar
Optional · Python] ``` ## 功能 ### 核心检测 | 模块 | 检测内容 | |---|---| | **SQL Injection** | 恒真、UNION、基于时间的盲注、基于错误的注入、堆叠查询、编码变体 | | **Cross-Site Scripting** | 存储型、反射型、DOM、事件处理器、script 标签、混淆的 JS | | **RCE** | Shell 注入、SSTI、EL 注入、反序列化、Log4Shell、文件包含 | | **Path Traversal** | 目录遍历、空字节、编码绕过 | | **API 保护** | OpenAPI schema 强制校验、影子 API 发现、批量赋值 | | **Protocol Anomaly** | HTTP 动词篡改、header 走私、格式错误的请求、方法覆盖 | ### 认证与访问 | 功能 | 实现 | |---|---| | **JWT 校验** | JWKS 缓存、RS256/ES256/HS256、issuer/audience 校验、scope 检查 | | **OAuth 2.0 Introspection** | RFC 7662、token 缓存、scope 和角色验证 | | **mTLS** | CA 校验、policy OID、证书信息提取 | | **CAPTCHA** | reCAPTCHA v2/v3、hCaptcha、可配置的分数阈值 | | **API Key 管理** | 针对已配置 key 的 Bearer token 校验 | ### 流量与速率管理 | 功能 | 详情 | |---|---| | **Rate Limiting** | 令牌桶、漏桶、滑动窗口、固定窗口 — 基于 IP、基于路由、全局 | | **DDoS Protection** | Slow loris 检测、slow POST、缓存破坏、自适应速率限制 | | **Bot 检测** | 已知 bot 列表、无头浏览器检测、JS challenge 生成 | | **IP Reputation** | TOR/proxy/VPN 检测、ASN 过滤、CIDR 允许/阻止列表 | | **Session 跟踪** | 基于带 Redis 后端的 Cookie 的 session 管理 | ### 特定协议检查 | 协议 | 能力 | |---|---| | **GraphQL** | 查询深度限制、成本分析、别名计数、批处理大小、字段限制 | | **WebSocket** | 帧类型校验、rate limiting、消息大小、origin 检查 | | **gRPC** | 按 service 的 rate limiting、消息大小限制、content-type 检测 | | **SOAP/XML** | XML 嵌套深度校验、content-type 强制检查 | ### 凭据保护 - 基于 IP 的指数退避暴力破解检测 - 基于用户 hash 的撞库检测 - 跨账户的密码喷洒检测 - 具有可配置阈值(尝试次数、时间窗口、持续时间)的账户锁定 - 登录路径自动检测(`/login`、`/auth`、`/signin`) ### 可观测性 | 工具 | 集成 | |---|---| | **Prometheus** | 可配置端口/路径上的 metrics endpoint(请求、延迟、决策、活动连接数) | | **Grafana** | 用于概览、安全、合规、ML 的预构建仪表板 | | **Elasticsearch** | SIEM 事件导出,包含 index 模板 | | **Kibana** | 用于安全事件和 ML 异常的仪表板定义 | | **Splunk** | 通过 HTTP event collector 进行事件导出 | | **Health Probes** | 用于 K8s 的 `/health`、`/ready`、`/live` endpoint | ### 内容安全 - 文件上传校验(MIME 签名、扩展名允许/阻止列表、magic bytes) - 针对数据泄露的响应 body 检查 - 每个 endpoint 可配置的请求大小限制 - 通过 TLS 配置的 HTTP/2 - ACME/LetsEncrypt 自动证书管理 - OCSP stapling 占位符 ## 快速开始 ``` git clone https://github.com/FortressWAF/FortressWAF.git cd FortressWAF # 使用你的 upstream 编辑 config cp deploy/config.yaml config.yaml # 运行 go run ./cmd/proxy -config config.yaml # 或者使用 Docker docker compose -f deploy/docker-compose.yml up -d ``` 最小化配置: ``` tls: enabled: true cert_file: cert.pem key_file: key.pem http2_enabled: true admin: port: 8444 api_keys: ["sk-admin"] sites: - name: myapp domains: ["app.example.com"] upstream: "http://127.0.0.1:3000" port: 443 waf_enabled: true ``` ## 架构 完整架构文档:[`docs/architecture.md`](docs/architecture.md) ``` flowchart LR C[Client] --> T[TLS
HTTP/2 · mTLS] T --> P[Parse] P --> A[Auth
JWT · OAuth · CAPTCHA] A --> PL[Protocol
GraphQL · gRPC · SOAP · WS] PL --> D[Detection
18 inspectors] D --> S[Scoring] S --> F[Forwarder] F --> O[Origin] ``` ``` cmd/proxy/ — WAF server entry point internal/ engine/ — Detection pipeline (18 inspector modules) api/ — Management REST API config/ — YAML config with live reload reputation/ — IP reputation and threat feeds ratelimit/ — Rate limiting algorithms session/ — Session tracking siem/ — SIEM event export deploy/ — Docker, Ansible, Terraform, Helm, monitoring docs/ — Documentation dashboard/ — Web dashboard (Next.js) ml-engine/ — ML sidecar (Python/FastAPI) ``` ## 性能 在笔记本电脑(Intel i5-7200U,2 核)上测得。服务器级 CPU 通常快 2-3 倍。 | 设置 | 单核吞吐量 | |---|---| | 直通(无 inspector) | ~80,000 req/s | | 单个 inspector (SQLi/XSS/RCE) | ~5,000,000 inspections/s | | 完整引擎(6+ 个 inspector) | ~2,500 req/s | | RequestContext 创建 | ~80,000 ctx/s | 完整 benchmark:[`benchmark.txt`](benchmark.txt) 单请求延迟开销:在笔记本电脑硬件上使用完整引擎时平均约为 ~400μs。 ## 文档 | 文档 | 内容 | |---|---| | [入门指南](docs/getting-started.md) | 安装和初始配置 | | [架构](docs/architecture.md) | Pipeline 详情和部署模式 | | [配置](docs/configuration.md) | 完整的 YAML 参考 | | [规则语言](docs/rule-language.md) | 规则 DSL 语法 | | [API 参考](docs/api-reference.md) | REST API 文档 | | [部署](docs/deployment.md) | Docker、K8s、云 | | [合规性](docs/compliance.md) | PCI-DSS、SOC2、GDPR 参考 | | [故障排除](docs/troubleshooting.md) | 常见问题 | ## 相关项目 | 仓库 | 描述 | |---|---| | [fortressctl](https://github.com/FortressWAF/fortressctl) | 用于管理 FortressWAF 实例的 CLI 工具 | | [fortresshoneypot](https://github.com/FortressWAF/fortresshoneypot) | 低交互 HTTP/SSH 蜜罐 | ## 许可证 AGPL-3.0
标签:API安全网关, AppImage, CISA项目, DOE合作, EVTX分析, Go, IP 地址批量处理, Ruby工具, Web应用防火墙, 反向代理, 子域名突变, 搜索引擎查询, 日志审计, 流量检测, 网络安全, 自定义请求头, 请求拦截, 逆向工具, 隐私保护