MCPcopy
hub / github.com/gofiber/fiber / match

Method match

middleware/csrf/helpers.go:63–97  ·  view source on GitHub ↗
(o string)

Source from the content-addressed store, hash-verified

61}
62
63func (s subdomain) match(o string) bool {
64 isValid, normalizedOrigin := normalizeOrigin(o)
65 if !isValid || normalizedOrigin != o {
66 return false
67 }
68
69 // Not a subdomain if not long enough for a dot separator.
70 if len(o) < len(s.prefix)+len(s.suffix)+1 {
71 return false
72 }
73
74 if !strings.HasPrefix(o, s.prefix) || !strings.HasSuffix(o, s.suffix) {
75 return false
76 }
77
78 // Check for the dot separator and validate that there is at least one
79 // non-empty label between prefix and suffix. Empty labels like
80 // "https://.example.com" or "https://..example.com" should not match.
81 suffixStartIndex := len(o) - len(s.suffix)
82 if suffixStartIndex <= len(s.prefix) {
83 return false
84 }
85 if o[suffixStartIndex-1] != '.' {
86 return false
87 }
88
89 // Extract the subdomain part (without the trailing dot) and ensure it
90 // doesn't contain empty labels.
91 sub := o[len(s.prefix) : suffixStartIndex-1]
92 if sub == "" || strings.HasPrefix(sub, ".") || strings.HasSuffix(sub, ".") || strings.Contains(sub, "..") {
93 return false
94 }
95
96 return true
97}

Callers 4

TestSubdomainMatchFunction · 0.45
originMatchesHostFunction · 0.45
refererMatchesHostFunction · 0.45

Calls 2

ContainsMethod · 0.80
normalizeOriginFunction · 0.70

Tested by 2

TestSubdomainMatchFunction · 0.36