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

Function DetectXSS

internal/waf/injectionutils/utils_xss.go:53–82  ·  view source on GitHub ↗

DetectXSS detect XSS in string

(input string, isStrict bool)

Source from the content-addressed store, hash-verified

51
52// DetectXSS detect XSS in string
53func DetectXSS(input string, isStrict bool) bool {
54 if len(input) == 0 {
55 return false
56 }
57
58 if detectXSSOne(input, isStrict) {
59 return true
60 }
61
62 // 兼容 /PATH?URI
63 if (input[0] == '/' || strings.HasPrefix(input, "http://") || strings.HasPrefix(input, "https://")) && len(input) < 1024 {
64 var argsIndex = strings.Index(input, "?")
65 if argsIndex > 0 {
66 var args = input[argsIndex+1:]
67 unescapeArgs, err := url.QueryUnescape(args)
68 if err == nil && args != unescapeArgs {
69 return detectXSSOne(args, isStrict) || detectXSSOne(unescapeArgs, isStrict)
70 } else {
71 return detectXSSOne(args, isStrict)
72 }
73 }
74 } else {
75 unescapedInput, err := url.QueryUnescape(input)
76 if err == nil && input != unescapedInput {
77 return detectXSSOne(unescapedInput, isStrict)
78 }
79 }
80
81 return false
82}
83
84func detectXSSOne(input string, isStrict bool) bool {
85 if len(input) == 0 {

Callers 6

TestDetectXSSFunction · 0.92
TestDetectXSS_StrictFunction · 0.92
BenchmarkDetectXSS_MISSFunction · 0.92
BenchmarkDetectXSS_HITFunction · 0.92
DetectXSSCacheFunction · 0.85

Calls 1

detectXSSOneFunction · 0.85

Tested by 5

TestDetectXSSFunction · 0.74
TestDetectXSS_StrictFunction · 0.74
BenchmarkDetectXSS_MISSFunction · 0.74
BenchmarkDetectXSS_HITFunction · 0.74