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

Function MaskSensitiveQuery

internal/util/provider.go:238–273  ·  view source on GitHub ↗

MaskSensitiveQuery masks sensitive query parameters, e.g. auth_token, within the raw query string.

(raw string)

Source from the content-addressed store, hash-verified

236
237// MaskSensitiveQuery masks sensitive query parameters, e.g. auth_token, within the raw query string.
238func MaskSensitiveQuery(raw string) string {
239 if raw == "" {
240 return ""
241 }
242 parts := strings.Split(raw, "&")
243 changed := false
244 for i, part := range parts {
245 if part == "" {
246 continue
247 }
248 keyPart := part
249 valuePart := ""
250 if idx := strings.Index(part, "="); idx >= 0 {
251 keyPart = part[:idx]
252 valuePart = part[idx+1:]
253 }
254 decodedKey, err := url.QueryUnescape(keyPart)
255 if err != nil {
256 decodedKey = keyPart
257 }
258 if !shouldMaskQueryParam(decodedKey) {
259 continue
260 }
261 decodedValue, err := url.QueryUnescape(valuePart)
262 if err != nil {
263 decodedValue = valuePart
264 }
265 masked := HideAPIKey(strings.TrimSpace(decodedValue))
266 parts[i] = keyPart + "=" + url.QueryEscape(masked)
267 changed = true
268 }
269 if !changed {
270 return raw
271 }
272 return strings.Join(parts, "&")
273}
274
275func shouldMaskQueryParam(key string) bool {
276 key = strings.ToLower(strings.TrimSpace(key))

Callers 2

GinLogrusLoggerFunction · 0.92
captureRequestInfoFunction · 0.92

Calls 2

shouldMaskQueryParamFunction · 0.85
HideAPIKeyFunction · 0.85

Tested by

no test coverage detected