Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-05-24 - Unhandled json.Marshal Errors Lead to Silent Failures
**Vulnerability:** Calls to `json.Marshal` in API handlers (e.g., `internal/api/handlers.go`) ignored returned errors using the blank identifier `_`. If marshaling fails, this results in an invalid, empty, or incorrectly processed payload without triggering an immediate, visible error to the user or system logs.
**Learning:** This existed because `json.Marshal` is often assumed to never fail, especially on simple maps or structs. However, if the payload contains unserializable data types (e.g., channels, functions, unsupported nested maps), it will fail silently, leading to subtle data corruption or job execution issues down the line.
**Prevention:** Always check and explicitly handle errors returned by `json.Marshal`. Log the error and return an appropriate HTTP status code (e.g., `http.StatusInternalServerError`) to fail securely and notify the caller.
16 changes: 14 additions & 2 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ func (s *Server) handlePipelineTrigger(w http.ResponseWriter, r *http.Request) {
// Wrap payload for handle command
enqueuePayload := req.Payload
if d.Command == "handle" {
enqueuePayload, _ = json.Marshal(event)
var err error
enqueuePayload, err = json.Marshal(event)
if err != nil {
s.logger.Error("failed to marshal event for enqueue", "pipeline", pipelineName, "plugin", d.Plugin, "error", err)
s.writeError(w, http.StatusInternalServerError, "failed to serialize payload")
return
}
}

jobID, err := s.queue.Enqueue(r.Context(), queue.EnqueueRequest{
Expand Down Expand Up @@ -409,7 +415,13 @@ func (s *Server) handlePluginTrigger(w http.ResponseWriter, r *http.Request) {
return
}
}
enqueuePayload, _ = json.Marshal(event)
var err error
enqueuePayload, err = json.Marshal(event)
if err != nil {
s.logger.Error("failed to marshal event for enqueue", "plugin", pluginName, "command", commandName, "error", err)
s.writeError(w, http.StatusInternalServerError, "failed to serialize payload")
return
}
}

jobID, err := s.queue.Enqueue(r.Context(), queue.EnqueueRequest{
Expand Down
Loading