Skip to content

Commit 2ec3b09

Browse files
authored
fix: Fix nil-pointer deref on checkAuthorization (coder#5236)
Remove call to `err.Error()` on a `nil` error in `checkAuthorization`.
1 parent f77a445 commit 2ec3b09

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

coderd/authorize.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ func (api *API) checkAuthorization(rw http.ResponseWriter, r *http.Request) {
192192
case rbac.ResourceGroup.Type:
193193
dbObj, dbErr = api.Database.GetGroupByID(ctx, id)
194194
default:
195+
msg := fmt.Sprintf("Object type %q does not support \"resource_id\" field.", v.Object.ResourceType)
195196
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
196-
Message: fmt.Sprintf("Object type %q does not support \"resource_id\" field.", v.Object.ResourceType),
197-
Validations: []codersdk.ValidationError{{Field: "resource_type", Detail: err.Error()}},
197+
Message: msg,
198+
Validations: []codersdk.ValidationError{{Field: "resource_type", Detail: msg}},
198199
})
199200
return
200201
}
@@ -206,7 +207,7 @@ func (api *API) checkAuthorization(rw http.ResponseWriter, r *http.Request) {
206207
obj = dbObj.RBACObject()
207208
}
208209

209-
err := api.Authorizer.ByRoleName(r.Context(), auth.ID.String(), auth.Roles, auth.Scope.ToRBAC(), auth.Groups, rbac.Action(v.Action), obj)
210+
err := api.Authorizer.ByRoleName(ctx, auth.ID.String(), auth.Roles, auth.Scope.ToRBAC(), auth.Groups, rbac.Action(v.Action), obj)
210211
response[k] = err == nil
211212
}
212213

0 commit comments

Comments
 (0)