Skip to content

Commit

Permalink
Don't log requests (gin-gonic#1370)
Browse files Browse the repository at this point in the history
Fixes gin-gonic#1331

HTTP logging leaks sensitive request information.

This PR removes HTTP request logging during panics.
  • Loading branch information
dustin-decker authored and justinfx committed Nov 3, 2018
1 parent 1e326a1 commit 5548cc3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ func RecoveryWithWriter(out io.Writer) HandlerFunc {
}
}
if logger != nil {
stack := stack(3)
httprequest, _ := httputil.DumpRequest(c.Request, false)
if brokenPipe {
logger.Printf("%s\n%s%s", err, string(httprequest), reset)
} else {
} else if IsDebugging() {
logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s",
timeFormat(time.Now()), string(httprequest), err, stack(3), reset)
timeFormat(time.Now()), string(httprequest), err, stack, reset)
} else {
logger.Printf("[Recovery] %s panic recovered:\n%s\n%s%s",
timeFormat(time.Now()), err, stack, reset)
}
}

Expand Down
12 changes: 11 additions & 1 deletion recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ func TestPanicInHandler(t *testing.T) {
w := performRequest(router, "GET", "/recovery")
// TEST
assert.Equal(t, http.StatusInternalServerError, w.Code)
assert.Contains(t, buffer.String(), "GET /recovery")
assert.Contains(t, buffer.String(), "panic recovered")
assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")
assert.Contains(t, buffer.String(), "TestPanicInHandler")
assert.NotContains(t, buffer.String(), "GET /recovery")

// Debug mode prints the request
SetMode(DebugMode)
// RUN
w = performRequest(router, "GET", "/recovery")
// TEST
assert.Equal(t, http.StatusInternalServerError, w.Code)
assert.Contains(t, buffer.String(), "GET /recovery")

}

// TestPanicWithAbort assert that panic has been recovered even if context.Abort was used.
Expand Down

0 comments on commit 5548cc3

Please sign in to comment.