claude code review changes
This commit is contained in:
@@ -64,6 +64,10 @@ func init() {
|
||||
// where "random" is a base62 random string that uniquely identifies this go
|
||||
// process, and where the last number is an atomically incremented request
|
||||
// counter.
|
||||
// maxRequestIDLen is the maximum length of an incoming request ID header
|
||||
// to prevent log injection or memory abuse from malicious clients.
|
||||
const maxRequestIDLen = 200
|
||||
|
||||
func RequestID(next http.Handler) http.Handler {
|
||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
@@ -71,6 +75,8 @@ func RequestID(next http.Handler) http.Handler {
|
||||
if requestID == "" {
|
||||
myid := reqid.Add(1)
|
||||
requestID = fmt.Sprintf("%s-%06d", prefix, myid)
|
||||
} else if len(requestID) > maxRequestIDLen {
|
||||
requestID = requestID[:maxRequestIDLen]
|
||||
}
|
||||
ctx = context.WithValue(ctx, RequestIDKey, requestID)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
||||
Reference in New Issue
Block a user