waf

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package waf 实现基于 Coraza 与 OWASP 核心规则集(CRS)的 Web 应用防火墙, 以实例形式供 Web 服务的站点引用。

Index

Constants

View Source
const (
	RuleCRS    = "crs"
	RuleCustom = "custom"
)

规则集类型

View Source
const (
	ModeBlock  = "block"
	ModeDetect = "detect"
)

工作模式

View Source
const ID = "waf"

ID 是模块标识。

Variables

This section is empty.

Functions

func CRSFiles

func CRSFiles() []string

CRSFiles 返回内置 CRS 的规则文件列表。

Types

type Instance

type Instance struct {
	Key    string `json:"key"`
	Name   string `json:"name"`
	Enable bool   `json:"enable"`
	Mode   string `json:"mode"`
	// Paranoia 为 CRS 偏执等级 1~4,越高越严格、误报越多
	Paranoia          int       `json:"paranoia"`
	InboundThreshold  int       `json:"inboundThreshold"`
	OutboundThreshold int       `json:"outboundThreshold"`
	RuleSets          []RuleSet `json:"ruleSets"`
	Remark            string    `json:"remark"`
}

Instance 是一个 WAF 实例。

func (*Instance) Validate

func (in *Instance) Validate() error

Validate 校验实例并补全默认值。

type InstanceInfo

type InstanceInfo struct {
	Key  string `json:"key"`
	Name string `json:"name"`
}

InstanceInfo 是供其他模块选择实例的简要信息。

type InstanceView

type InstanceView struct {
	Instance
	Error   string `json:"error,omitempty"`
	Blocked int64  `json:"blocked"`
	Matched int64  `json:"matched"`
}

InstanceView 是带统计的实例。

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module 是 WAF 模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) ImportLucky

func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)

ImportLucky 实现 luckyimport.Importer。沿用 Lucky 的实例 key,使 Web 服务站点的引用保持有效。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Instances

func (m *Module) Instances() []InstanceInfo

Instances 返回实例列表。

func (*Module) Middleware

func (m *Module) Middleware(key string, next http.Handler) http.Handler

Middleware 返回经过指定实例检查的处理器。实例不存在、停用或编译失败时直接放行, 每次请求时读取最新实例,修改 WAF 配置后无需重启 Web 服务。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Summary

func (m *Module) Summary() []module.SummaryItem

Summary 实现 module.Summarizer。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type RuleSet

type RuleSet struct {
	Enable bool   `json:"enable"`
	Remark string `json:"remark"`
	Type   string `json:"type"`
	// Param:CRS 类型为规则文件名列表(每行一个,留空表示全部);自定义类型为 SecLang 指令
	Param string `json:"param"`
}

RuleSet 是实例中的一组规则。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL