Files
EdgeCommon/pkg/serverconfigs/firewallconfigs/http_firewall_checkpoints.go

440 lines
11 KiB
Go
Raw Normal View History

2020-10-08 11:11:29 +08:00
package firewallconfigs
import (
"github.com/iwind/TeaGo/maps"
"regexp"
)
2021-07-19 11:01:43 +08:00
// AllCheckpoints all check points list
2020-10-08 11:11:29 +08:00
var AllCheckpoints = []*HTTPFirewallCheckpointDefinition{
{
Name: "通用请求报头长度限制",
Prefix: "requestGeneralHeaderLength",
Description: "通用报头比如Cache-Control、Accept之类的长度限制防止缓冲区溢出攻击。",
IsRequest: true,
IsComposed: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
},
{
Name: "通用响应报头长度限制",
Prefix: "responseGeneralHeaderLength",
Description: "通用报头比如Cache-Control、Date之类的长度限制防止缓冲区溢出攻击。",
IsRequest: false,
IsComposed: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
},
2020-10-08 11:11:29 +08:00
{
Name: "客户端地址IP",
Prefix: "remoteAddr",
Description: "试图通过分析X-Forwarded-For等报头获取的客户端地址比如192.168.1.100,存在伪造的可能。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "客户端源地址IP",
Prefix: "rawRemoteAddr",
2023-12-08 15:09:32 +08:00
Description: "直接连接的客户端地址比如192.168.1.100。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "客户端端口",
Prefix: "remotePort",
2023-12-08 15:09:32 +08:00
Description: "直接连接的客户端地址端口。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "客户端用户名",
Prefix: "remoteUser",
2023-12-08 15:09:32 +08:00
Description: "通过BasicAuth登录的客户端用户名。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求URI",
Prefix: "requestURI",
2023-12-08 15:09:32 +08:00
Description: "包含URL参数的请求URI类似于 /hello/world?lang=go不包含域名部分。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求路径",
Prefix: "requestPath",
2023-12-08 15:09:32 +08:00
Description: "不包含URL参数的请求路径类似于 /hello/world不包含域名部分。",
2022-06-09 19:43:52 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2022-06-09 19:43:52 +08:00
},
{
2022-06-14 17:37:32 +08:00
Name: "请求完整URL",
2022-06-09 19:43:52 +08:00
Prefix: "requestURL",
2023-12-08 15:09:32 +08:00
Description: "完整的请求URL包含协议、域名、请求路径、参数等类似于 https://example.com/hello?name=lily 。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求内容长度",
Prefix: "requestLength",
Description: "请求报头中的Content-Length。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求体内容",
Prefix: "requestBody",
2023-12-08 15:09:32 +08:00
Description: "通常在POST或者PUT等操作时会附带请求体最大限制32M。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 5,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求URI和请求体组合",
Prefix: "requestAll",
2023-12-08 15:09:32 +08:00
Description: "${requestURI}和${requestBody}组合。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 5,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求表单参数",
Prefix: "requestForm",
2023-12-08 15:09:32 +08:00
Description: "获取POST或者其他方法发送的表单参数最大请求体限制32M。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 5,
2020-10-08 11:11:29 +08:00
},
{
Name: "上传文件",
Prefix: "requestUpload",
2023-12-08 15:09:32 +08:00
Description: "获取POST上传的文件信息最大请求体限制32M。",
2020-10-08 11:11:29 +08:00
Params: []*KeyValue{
NewKeyValue("最小文件尺寸", "minSize"),
NewKeyValue("最大文件尺寸", "maxSize"),
NewKeyValue("扩展名(如.txt)", "ext"),
NewKeyValue("原始文件名", "name"),
NewKeyValue("表单字段名", "field"),
},
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 20,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求JSON参数",
Prefix: "requestJSON",
2023-12-08 15:09:32 +08:00
Description: "获取POST或者其他方法发送的JSON最大请求体限制32M使用点.)符号表示多级数据。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 5,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求方法",
Prefix: "requestMethod",
2023-12-08 15:09:32 +08:00
Description: "比如GET、POST。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求协议",
Prefix: "scheme",
2023-12-08 15:09:32 +08:00
Description: "比如http或https。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "HTTP协议版本",
Prefix: "proto",
2023-12-08 15:09:32 +08:00
Description: "比如HTTP/1.1。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "主机名",
Prefix: "host",
Description: "比如example.com。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "CNAME",
Prefix: "cname",
Description: "当前网站服务CNAME比如38b48e4f.example.com。",
IsRequest: true,
Priority: 100,
},
{
Name: "是否为CNAME",
Prefix: "isCNAME",
2023-12-08 15:09:32 +08:00
Description: "是否为CNAME值为1或0。",
IsRequest: true,
Priority: 100,
DataType: "bool",
},
2020-10-08 11:11:29 +08:00
{
2023-12-24 10:03:01 +08:00
Name: "请求来源",
Prefix: "refererOrigin",
Description: "请求报头中的Referer和Origin值。",
IsRequest: true,
Priority: 100,
Version: "1.3.2",
},
{
Name: "请求来源Referer",
2020-10-08 11:11:29 +08:00
Prefix: "referer",
Description: "请求报头中的Referer值。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "客户端信息",
Prefix: "userAgent",
2023-12-08 15:09:32 +08:00
Description: "比如Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "内容类型",
Prefix: "contentType",
Description: "请求报头的Content-Type。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "所有cookie组合字符串",
Prefix: "cookies",
2023-12-08 15:09:32 +08:00
Description: "比如sid=IxZVPFhE&city=beijing&uid=18237。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "单个cookie值",
Prefix: "cookie",
2023-12-08 15:09:32 +08:00
Description: "单个cookie值。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "所有URL参数组合",
Prefix: "args",
2023-12-08 15:09:32 +08:00
Description: "比如name=lu&age=20。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "单个URL参数值",
Prefix: "arg",
2023-12-08 15:09:32 +08:00
Description: "单个URL参数值。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "所有请求报头内容",
2020-10-08 11:11:29 +08:00
Prefix: "headers",
Description: "使用换行符(\\n隔开的报头内容字符串每行均为\"NAME: VALUE格式\"。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "所有请求报头名称",
Prefix: "headerNames",
Description: "使用换行符(\\n隔开的报头名称字符串每行一个名称。",
IsRequest: true,
Priority: 100,
2023-12-24 10:03:01 +08:00
Version: "1.3.2",
},
{
Name: "单个请求报头值",
2020-10-08 11:11:29 +08:00
Prefix: "header",
Description: "单个报头值。",
2020-10-08 11:11:29 +08:00
IsRequest: true,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "请求报头最大长度",
Prefix: "headerMaxLength",
Description: "最长的请求报头的长度。",
IsRequest: true,
HasParams: false,
Priority: 100,
},
{
Name: "国家/地区名称",
Prefix: "geoCountryName",
Description: "当前客户端所处国家/地区名称。",
IsRequest: true,
HasParams: false,
2022-10-24 17:56:37 +08:00
Priority: 90,
},
{
Name: "省份名称",
Prefix: "geoProvinceName",
Description: "当前客户端所处中国省份名称。",
IsRequest: true,
HasParams: false,
2022-10-24 17:56:37 +08:00
Priority: 90,
},
{
Name: "城市名称",
Prefix: "geoCityName",
Description: "当前客户端所处中国城市名称。",
IsRequest: true,
HasParams: false,
2022-10-24 17:56:37 +08:00
Priority: 90,
},
{
Name: "ISP名称",
Prefix: "ispName",
Description: "当前客户端所处ISP名称。",
IsRequest: true,
HasParams: false,
2022-10-24 17:56:37 +08:00
Priority: 90,
},
2020-10-08 11:11:29 +08:00
{
2021-07-19 14:28:56 +08:00
Name: "CC统计",
2021-07-19 11:01:43 +08:00
Prefix: "cc2",
2023-12-08 15:09:32 +08:00
Description: "对统计对象进行统计。",
2021-07-19 11:01:43 +08:00
HasParams: false,
IsRequest: true,
IsComposed: true,
2022-10-24 17:56:37 +08:00
Priority: 10,
2021-07-19 11:01:43 +08:00
},
2021-10-19 11:38:39 +08:00
{
Name: "防盗链",
Prefix: "refererBlock",
2023-12-08 15:09:32 +08:00
Description: "对统计对象进行统计。",
2021-10-19 11:38:39 +08:00
HasParams: false,
IsRequest: true,
IsComposed: true,
2022-10-24 17:56:37 +08:00
Priority: 20,
2021-10-19 11:38:39 +08:00
},
2021-07-19 11:01:43 +08:00
{
Name: "CC统计",
2020-10-08 11:11:29 +08:00
Prefix: "cc",
2023-12-08 15:09:32 +08:00
Description: "统计某段时间段内的请求信息不推荐再使用请使用新的CC2统计代替。",
HasParams: true,
2020-10-08 11:11:29 +08:00
Params: []*KeyValue{
NewKeyValue("请求数", "requests"),
},
Options: []OptionInterface{
&FieldOption{
Type: "field",
Name: "统计周期",
Code: "period",
Value: "60",
IsRequired: false,
Size: 8,
Comment: "",
Placeholder: "",
RightLabel: "秒",
MaxLength: 8,
Validate: func(value string) (ok bool, message string) {
2023-08-08 15:12:28 +08:00
if regexp.MustCompile(`^\d+$`).MatchString(value) {
2020-10-08 11:11:29 +08:00
ok = true
return
}
message = "周期需要是一个整数数字"
return
},
},
&OptionsOption{
Type: "options",
Name: "用户识别读取来源",
Code: "userType",
Value: "",
IsRequired: false,
Size: 10,
Comment: "",
RightLabel: "",
Validate: nil,
Options: []maps.Map{
{
"name": "IP",
"value": "ip",
},
{
"name": "Cookie",
"value": "cookie",
},
{
"name": "URL参数",
"value": "get",
},
{
"name": "POST参数",
"value": "post",
},
{
"name": "HTTP Header",
"value": "header",
},
},
},
&FieldOption{
Type: "field",
Name: "用户识别字段",
Code: "userField",
Comment: "识别用户的唯一性字段在用户读取来源不是IP时使用",
},
&FieldOption{
Type: "field",
Name: "字段读取位置",
Code: "userIndex",
Size: 5,
MaxLength: 5,
Comment: "读取用户识别字段的位置从0开始比如user12345的数字ID 12345的位置就是5在用户读取来源不是IP时使用",
},
},
IsRequest: true,
2022-10-24 17:56:37 +08:00
Priority: 10,
2020-10-08 11:11:29 +08:00
},
{
Name: "响应状态码",
Prefix: "status",
2023-12-08 15:09:32 +08:00
Description: "响应状态码比如200、404、500。",
2020-10-08 11:11:29 +08:00
IsRequest: false,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "响应报头",
2020-10-08 11:11:29 +08:00
Prefix: "responseHeader",
Description: "响应报头值。",
2020-10-08 11:11:29 +08:00
IsRequest: false,
HasParams: true,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
{
Name: "响应内容",
Prefix: "responseBody",
2023-12-08 15:09:32 +08:00
Description: "响应内容字符串。",
2020-10-08 11:11:29 +08:00
IsRequest: false,
2022-10-24 17:56:37 +08:00
Priority: 5,
2020-10-08 11:11:29 +08:00
},
{
Name: "响应内容长度",
Prefix: "bytesSent",
Description: "响应内容长度通过响应的报头Content-Length获取。",
2020-10-08 11:11:29 +08:00
IsRequest: false,
2022-10-24 17:56:37 +08:00
Priority: 100,
2020-10-08 11:11:29 +08:00
},
}
// FindCheckpointDefinition 查找Checkpoint定义
2020-10-08 11:11:29 +08:00
func FindCheckpointDefinition(prefix string) *HTTPFirewallCheckpointDefinition {
for _, checkpoint := range AllCheckpoints {
if checkpoint.Prefix == prefix {
return checkpoint
2020-10-08 11:11:29 +08:00
}
}
return nil
}
// CheckCheckpointIsComposed 判断Checkpoint是否为组合的
func CheckCheckpointIsComposed(prefix string) bool {
for _, checkpoint := range AllCheckpoints {
if checkpoint.Prefix == prefix {
return checkpoint.IsComposed
}
}
return false
}