| 20 | ) |
| 21 | |
| 22 | func DetectXSSCache(input string, isStrict bool, cacheLife utils.CacheLife) bool { |
| 23 | var l = len(input) |
| 24 | |
| 25 | if l == 0 { |
| 26 | return false |
| 27 | } |
| 28 | |
| 29 | if cacheLife <= 0 || l < 512 || l > utils.MaxCacheDataSize { |
| 30 | return DetectXSS(input, isStrict) |
| 31 | } |
| 32 | |
| 33 | var hash = xxhash.Sum64String(input) |
| 34 | var key = "WAF@XSS@" + strconv.FormatUint(hash, 10) |
| 35 | if isStrict { |
| 36 | key += "@1" |
| 37 | } |
| 38 | var item = utils.SharedCache.Read(key) |
| 39 | if item != nil { |
| 40 | return item.Value == 1 |
| 41 | } |
| 42 | |
| 43 | var result = DetectXSS(input, isStrict) |
| 44 | if result { |
| 45 | utils.SharedCache.Write(key, 1, fasttime.Now().Unix()+cacheLife) |
| 46 | } else { |
| 47 | utils.SharedCache.Write(key, 0, fasttime.Now().Unix()+cacheLife) |
| 48 | } |
| 49 | return result |
| 50 | } |
| 51 | |
| 52 | // DetectXSS detect XSS in string |
| 53 | func DetectXSS(input string, isStrict bool) bool { |