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

Function DetectSQLInjectionCache

internal/waf/injectionutils/utils_sqli.go:24–49  ·  view source on GitHub ↗

DetectSQLInjectionCache detect sql injection in string with cache

(input string, isStrict bool, cacheLife utils.CacheLife)

Source from the content-addressed store, hash-verified

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

Calls 5

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