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

Function DetectSQLInjection

internal/waf/injectionutils/utils_sqli.go:52–93  ·  view source on GitHub ↗

DetectSQLInjection detect sql injection in string

(input string, isStrict bool)

Source from the content-addressed store, hash-verified

50
51// DetectSQLInjection detect sql injection in string
52func DetectSQLInjection(input string, isStrict bool) bool {
53 if len(input) == 0 {
54 return false
55 }
56
57 if !isStrict {
58 if len(input) > 1024 {
59 if !utf8.ValidString(input[:1024]) && !utf8.ValidString(input[:1023]) && !utf8.ValidString(input[:1022]) {
60 return false
61 }
62 } else {
63 if !utf8.ValidString(input) {
64 return false
65 }
66 }
67 }
68
69 if detectSQLInjectionOne(input) {
70 return true
71 }
72
73 // 兼容 /PATH?URI
74 if (input[0] == '/' || strings.HasPrefix(input, "http://") || strings.HasPrefix(input, "https://")) && len(input) < 1024 {
75 var argsIndex = strings.Index(input, "?")
76 if argsIndex > 0 {
77 var args = input[argsIndex+1:]
78 unescapeArgs, err := url.QueryUnescape(args)
79 if err == nil && args != unescapeArgs {
80 return detectSQLInjectionOne(args) || detectSQLInjectionOne(unescapeArgs)
81 } else {
82 return detectSQLInjectionOne(args)
83 }
84 }
85 } else {
86 unescapedInput, err := url.QueryUnescape(input)
87 if err == nil && input != unescapedInput {
88 return detectSQLInjectionOne(unescapedInput)
89 }
90 }
91
92 return false
93}
94
95func detectSQLInjectionOne(input string) bool {
96 if len(input) == 0 {

Calls 1

detectSQLInjectionOneFunction · 0.85