MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / normalizeResourceRoute

Function normalizeResourceRoute

internal/pluginhost/management.go:186–222  ·  view source on GitHub ↗
(pluginID string, item pluginapi.ResourceRoute)

Source from the content-addressed store, hash-verified

184}
185
186func normalizeResourceRoute(pluginID string, item pluginapi.ResourceRoute) (string, bool) {
187 if item.Handler == nil {
188 return "", false
189 }
190 pluginID = strings.TrimSpace(pluginID)
191 if pluginID == "" {
192 return "", false
193 }
194
195 path := strings.TrimSpace(item.Path)
196 if path == "" {
197 return "", false
198 }
199 if !strings.HasPrefix(path, "/") {
200 path = "/" + path
201 }
202
203 pluginBasePath := resourcePluginBasePath + "/" + pluginID
204 if strings.HasPrefix(path, pluginBasePath+"/") {
205 path = strings.TrimPrefix(path, pluginBasePath)
206 } else if strings.HasPrefix(path, legacyPluginRoutePrefix+"/"+pluginID+"/") {
207 path = strings.TrimPrefix(path, legacyPluginRoutePrefix+"/"+pluginID)
208 }
209 path = strings.TrimRight(path, "/")
210 if path == "" {
211 return "", false
212 }
213
214 fullPath := pluginBasePath + path
215 if !strings.HasPrefix(fullPath, pluginBasePath+"/") {
216 return "", false
217 }
218 if strings.ContainsAny(fullPath, " \t\r\n") || strings.Contains(fullPath, ":") || strings.Contains(fullPath, "*") || strings.Contains(fullPath, "..") {
219 return "", false
220 }
221 return fullPath, true
222}
223
224func managementRouteKey(method, path string) string {
225 return strings.ToUpper(strings.TrimSpace(method)) + " " + strings.TrimSpace(path)

Callers 1

registerResourceRouteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected