Skip to content
Myr

Don't log requests (#1370)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #1331 HTTP logging leaks sensitive request information. This PR removes HTTP request logging during panics.

authored by Dustin Decker · committed by Bo-Yi Wu · parent 5a75dc7 · Browse files · 2 files+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−3 removed

  • other:+17 added−3 removed

2 files+17 added−3 removed

modified:recovery_test.go+11 added-1 removed
22 unmodified lines
23 // RUN24 w := performRequest(router, "GET", "/recovery")25 // TEST26 assert.Equal(t, http.StatusInternalServerError, w.Code)27 assert.Contains(t, buffer.String(), "GET /recovery")27 assert.Contains(t, buffer.String(), "panic recovered")28 assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")29 assert.Contains(t, buffer.String(), "TestPanicInHandler")30 assert.NotContains(t, buffer.String(), "GET /recovery")3132 // Debug mode prints the request33 SetMode(DebugMode)34 // RUN35 w = performRequest(router, "GET", "/recovery")36 // TEST37 assert.Equal(t, http.StatusInternalServerError, w.Code)38 assert.Contains(t, buffer.String(), "GET /recovery")3940}4142// TestPanicWithAbort assert that panic has been recovered even if context.Abort was used.43func TestPanicWithAbort(t *testing.T) {
31 unmodified lines
modified:recovery.go+6 added-2 removed
37 unmodified lines
38 defer func() {39 if err := recover(); err != nil {40 if logger != nil {41 stack := stack(3)42 if IsDebugging() {42 httprequest, _ := httputil.DumpRequest(c.Request, false)43 logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s", timeFormat(time.Now()), string(httprequest), err, stack, reset)43 httprequest, _ := httputil.DumpRequest(c.Request, false)44 logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s", timeFormat(time.Now()), string(httprequest), err, stack, reset)45 } else {46 logger.Printf("[Recovery] %s panic recovered:\n%s\n%s%s", timeFormat(time.Now()), err, stack, reset)47 }48 }49 c.AbortWithStatus(http.StatusInternalServerError)50 }51 }()
69 unmodified lines