Code RoomAPI key comparison timing-sensitive
MediumPrep Room Coding #1678

API key comparison timing-sensitive

Code reviewSecurityMid–Senior~25 min

Review this Go middleware that authenticates internal service-to-service calls with a shared API key.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1func requireAPIKey(next http.Handler) http.Handler {
2 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3 provided := r.Header.Get("X-Api-Key")
4 if provided == os.Getenv("INTERNAL_API_KEY") {
5 next.ServeHTTP(w, r)
6 return
7 }
8 http.Error(w, "forbidden", http.StatusForbidden)
9 })
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.