MCPcopy
hub / github.com/gin-gonic/gin / secureRequestDump

Function secureRequestDump

recovery.go:98–107  ·  view source on GitHub ↗

secureRequestDump returns a sanitized HTTP request dump where the Authorization header, if present, is replaced with a masked value ("Authorization: *") to avoid leaking sensitive credentials. Currently, only the Authorization header is sanitized. All other headers and request data remain unchanged

(r *http.Request)

Source from the content-addressed store, hash-verified

96//
97// Currently, only the Authorization header is sanitized. All other headers and request data remain unchanged.
98func secureRequestDump(r *http.Request) string {
99 httpRequest, _ := httputil.DumpRequest(r, false)
100 lines := strings.Split(bytesconv.BytesToString(httpRequest), "\r\n")
101 for i, line := range lines {
102 if strings.HasPrefix(line, "Authorization:") {
103 lines[i] = "Authorization: *"
104 }
105 }
106 return strings.Join(lines, "\r\n")
107}
108
109func defaultHandleRecovery(c *Context, _ any) {
110 c.AbortWithStatus(http.StatusInternalServerError)

Callers 2

TestSecureRequestDumpFunction · 0.85
CustomRecoveryWithWriterFunction · 0.85

Calls 1

BytesToStringFunction · 0.92

Tested by 1

TestSecureRequestDumpFunction · 0.68