Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
only allow me on users
  • Loading branch information
coadler committed Apr 1, 2022
commit da23bf548aaeaf8d9a0b1d8fcfc036640fbbc3d0
2 changes: 1 addition & 1 deletion coderd/httpmw/httpmw.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func parseUUID(rw http.ResponseWriter, r *http.Request, param string) (uuid.UUID
}

// Automatically set uuid.Nil to the acting users id.
if rawID == "me" {
if param == UserKey && rawID == "me" {
key := APIKey(r)
return key.UserID, true
}
Expand Down
4 changes: 3 additions & 1 deletion coderd/httpmw/userparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/coder/coder/coderd/httpapi"
)

const UserKey = "user"

type userParamContextKey struct{}

// UserParam returns the user from the ExtractUserParam handler.
Expand All @@ -24,7 +26,7 @@ func UserParam(r *http.Request) database.User {
func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
userID, ok := parseUUID(rw, r, "user")
userID, ok := parseUUID(rw, r, UserKey)
if !ok {
return
}
Expand Down