MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / DetectXSSCache

Function DetectXSSCache

internal/waf/injectionutils/utils_xss.go:22–50  ·  view source on GitHub ↗
(input string, isStrict bool, cacheLife utils.CacheLife)

Source from the content-addressed store, hash-verified

20)
21
22func 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
53func DetectXSS(input string, isStrict bool) bool {

Callers 2

TestMethod · 0.92

Calls 5

NowFunction · 0.92
DetectXSSFunction · 0.85
UnixMethod · 0.80
ReadMethod · 0.65
WriteMethod · 0.65

Tested by 1