修复WAF中反斜杠符号(\)有可能解析错误的Bug

This commit is contained in:
刘祥超
2022-12-14 12:27:07 +08:00
parent 42d0d63cf4
commit ebb6ebd10c
3 changed files with 130 additions and 11 deletions

View File

@@ -13,6 +13,10 @@ var cache = ttlcache.NewCache()
// MatchStringCache 正则表达式匹配字符串,并缓存结果
func MatchStringCache(regex *re.Regexp, s string) bool {
if regex == nil {
return false
}
// 如果长度超过4096大概率是不能重用的
if len(s) > 4096 {
return regex.MatchString(s)
@@ -35,6 +39,10 @@ func MatchStringCache(regex *re.Regexp, s string) bool {
// MatchBytesCache 正则表达式匹配字节slice并缓存结果
func MatchBytesCache(regex *re.Regexp, byteSlice []byte) bool {
if regex == nil {
return false
}
// 如果长度超过4096大概率是不能重用的
if len(byteSlice) > 4096 {
return regex.Match(byteSlice)