Skip to content

Commit

Permalink
pkg/web: avoid shared middleware slice (grafana#58458)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakjur authored Nov 8, 2022
1 parent 2e6761b commit 7570169
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/web/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ func mwFromHandler(handler Handler) Middleware {
}

func (m *Macaron) createContext(rw http.ResponseWriter, req *http.Request) *Context {
// NOTE: we have to explicitly copy the middleware chain here to avoid
// passing a shared slice to the *Context, which leads to racy behavior in
// case of later appends
mws := make([]Middleware, len(m.mws))
copy(mws, m.mws)

c := &Context{
mws: m.mws,
mws: mws,
Resp: NewResponseWriter(req.Method, rw),
}

Expand Down

0 comments on commit 7570169

Please sign in to comment.