Skip to content

Commit

Permalink
fix(runner): check token
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jan 7, 2024
1 parent 1ae8eb1 commit 5596943
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/runners/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
func RunnerMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

token := r.Header.Get("X-API-Token")

runnerID, err := helpers.GetIntParam("runner_id", w, r)

if err != nil {
Expand All @@ -26,6 +28,13 @@ func RunnerMiddleware(next http.Handler) http.Handler {

runner, err := store.GetGlobalRunner(runnerID)

if runner.Token != token {
helpers.WriteJSON(w, http.StatusUnauthorized, map[string]string{
"error": "Invalid token",
})
return
}

if err != nil {
helpers.WriteJSON(w, http.StatusNotFound, map[string]string{
"error": "Runner not found",
Expand Down

0 comments on commit 5596943

Please sign in to comment.