Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recovery middleware leaks sensitive cookies, tokens, and headers into logs #1331

Closed
dustin-decker opened this issue Apr 23, 2018 · 5 comments

Comments

@dustin-decker
Copy link
Contributor

dustin-decker commented Apr 23, 2018

Session cookies, API tokens, and authorization headers are all being leaked. The request is dumped if a handler hits a panic when using the recovery middleware:

httprequest, _ := httputil.DumpRequest(c.Request, false)

This is very insecure default behavior, and there appears to be no way to opt out other than not using the middleware.

@dustin-decker dustin-decker changed the title Recovery middleware leaks sensitive cookies and headers into logs Recovery middleware leaks sensitive cookies, headers and body into logs Apr 23, 2018
@chainhelen
Copy link
Contributor

@dustin-decker sorry, how do you define "leadked". This error is just logged in server, why leadked?

@dustin-decker
Copy link
Contributor Author

dustin-decker commented May 25, 2018

It can make sensitive headers readable in plaintext logs. No production HTTP server I know of does this by default, though some can be configured to do this.
If you ship server logs somewhere for processing, aggregation, and viewing, then the problem becomes much more severe, and a lot of companies do this.

Twitter and Github recently publicly disclosed that they've accidentally logged passwords and advised people to change them: https://arstechnica.com/information-technology/2018/05/twitter-advises-users-to-reset-passwords-after-bug-posts-passwords-to-internal-log/

I will open a PR in a few minutes to address this issue in gin.

(Edited posts because I noticed that it does not log the body, but does log the other parts of the request)

@dustin-decker dustin-decker changed the title Recovery middleware leaks sensitive cookies, headers and body into logs Recovery middleware leaks sensitive cookies, and headers into logs May 25, 2018
@dustin-decker dustin-decker changed the title Recovery middleware leaks sensitive cookies, and headers into logs Recovery middleware leaks sensitive cookies, tokens, and headers into logs May 25, 2018
dustin-decker referenced this issue May 25, 2018
- request context
- red colouring
@chainhelen
Copy link
Contributor

@dustin-decker In my opinion, This is just a log middleware.

custom-middleware

func Logger() gin.HandlerFunc {
	return func(c *gin.Context) {
		t := time.Now()

		// Set example variable
		c.Set("example", "12345")

		// before request

		c.Next()

		// after request
		latency := time.Since(t)
		log.Print(latency)

		// access the status we are sending
		status := c.Writer.Status()
		log.Println(status)
	}
}

func main() {
	r := gin.New()
	r.Use(Logger())

	r.GET("/test", func(c *gin.Context) {
		example := c.MustGet("example").(string)

		// it would print: "12345"
		log.Println(example)
	})

	// Listen and serve on 0.0.0.0:8080
	r.Run(":8080")
}

I think it depend on developer,but not web framework.
En, just my opinion.Maybe you are right, wait for the explain of gin's member.

@appleboy
Copy link
Member

ping @javierprovecho @thinkerou

@thinkerou
Copy link
Member

thinkerou commented May 31, 2018

Generally, we set username/password in body, as you say, we not log request body. If user set username/password in query param, user should encrypt self-user. As @dustin-decker pull request, remove log dump, I think it's ok, because we have had panic stack. This's my option.

appleboy pushed a commit that referenced this issue Sep 23, 2018
Fixes #1331

HTTP logging leaks sensitive request information.

This PR removes HTTP request logging during panics.
justinfx pushed a commit to justinfx/gin that referenced this issue Nov 3, 2018
Fixes gin-gonic#1331

HTTP logging leaks sensitive request information.

This PR removes HTTP request logging during panics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants