π‘οΈ Sentinel: [Medium] Fix unhandled json.Marshal error in API handlers#117
π‘οΈ Sentinel: [Medium] Fix unhandled json.Marshal error in API handlers#117mattjoyce wants to merge 1 commit into
Conversation
In `internal/api/handlers.go`, the returned error from `json.Marshal(event)` was being explicitly ignored (assigned to `_`). This was a security and reliability risk. If marshaling failed, an empty byte slice or `nil` could be added to the queue, which could cause panics or application instability downstream. This commit updates the code to explicitly check for marshaling errors. If an error occurs, it is securely logged using `s.logger.Error`, and an `http.StatusInternalServerError` is returned to the client using `s.writeError`. This ensures the API fails securely without exposing internal data. Co-authored-by: mattjoyce <278869+mattjoyce@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Deploying with Β
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| β
Deployment successful! View logs |
ductile | 3c1e88d | Commit Preview URL Branch Preview URL |
Jun 06 2026, 11:40 AM |
π WalkthroughWalkthroughThis PR fixes unhandled ChangesJSON Marshal Error Handling
Estimated code review effortπ― 2 (Simple) | β±οΈ ~8 minutes Poem
π₯ Pre-merge checks | β 5β Passed checks (5 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ Generate docstrings
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review Summary by QodoFix unhandled json.Marshal errors in API handlers
WalkthroughsDescriptionβ’ Fix unhandled json.Marshal errors in two API handlers β’ Add explicit error checking and logging for marshaling failures β’ Return HTTP 500 on marshal errors instead of silently failing β’ Add security learning documentation to .jules/sentinel.md Diagramflowchart LR
A["json.Marshal call"] -->|"error ignored with _"| B["Empty/invalid payload enqueued"]
B -->|"downstream processing"| C["Worker crash or data corruption"]
A -->|"error now checked"| D["Error logged securely"]
D -->|"HTTP 500 returned"| E["Request fails safely"]
File Changes1. internal/api/handlers.go
|
Code Review by Qodo
Context usedβ
Compliance rules (platform):
46 rules 1. Marshal log missing context
|
CI Feedback π§A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
There was a problem hiding this comment.
Actionable comments posted: 1
π€ Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.jules/sentinel.md:
- Around line 1-4: The markdown heading at the top ("2026-06-06 - Fix unhandled
json.Marshal errors in API handlers") is using an H2 and lacks required
surrounding blank lines; change the "##" to a top-level "#" and ensure there is
a single blank line before and after that heading (i.e., add an empty line above
the heading and one empty line below it) so the file conforms to MD041/MD022
rules.
πͺ Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
βΉοΈ Review info
βοΈ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 91d0fb59-da16-4c89-9d81-f42b5695287a
π Files selected for processing (2)
.jules/sentinel.mdinternal/api/handlers.go
| ## 2026-06-06 - Fix unhandled json.Marshal errors in API handlers | ||
| **Vulnerability:** In `internal/api/handlers.go`, errors from `json.Marshal` were explicitly ignored using `_` when wrapping event payloads. | ||
| **Learning:** Ignoring marshaling errors allows empty or malformed byte slices to be enqueued, which could lead to downstream panics, silent data corruption, or denial-of-service if workers cannot process the invalid payloads. This is a common pattern when developers assume internal structs will always marshal successfully. | ||
| **Prevention:** Always check and handle the `error` returned by `json.Marshal`. If it fails, log the error securely and return a generic 500 Internal Server Error without leaking details to the client. |
There was a problem hiding this comment.
Fix markdownlint heading structure (MD041/MD022).
The file starts with an H2 and lacks the required blank-line spacing around the heading, which matches the static-analysis warnings.
Suggested patch
+# Sentinel Notes
+
## 2026-06-06 - Fix unhandled json.Marshal errors in API handlers
+
**Vulnerability:** In `internal/api/handlers.go`, errors from `json.Marshal` were explicitly ignored using `_` when wrapping event payloads.
**Learning:** Ignoring marshaling errors allows empty or malformed byte slices to be enqueued, which could lead to downstream panics, silent data corruption, or denial-of-service if workers cannot process the invalid payloads. This is a common pattern when developers assume internal structs will always marshal successfully.
**Prevention:** Always check and handle the `error` returned by `json.Marshal`. If it fails, log the error securely and return a generic 500 Internal Server Error without leaking details to the client.π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## 2026-06-06 - Fix unhandled json.Marshal errors in API handlers | |
| **Vulnerability:** In `internal/api/handlers.go`, errors from `json.Marshal` were explicitly ignored using `_` when wrapping event payloads. | |
| **Learning:** Ignoring marshaling errors allows empty or malformed byte slices to be enqueued, which could lead to downstream panics, silent data corruption, or denial-of-service if workers cannot process the invalid payloads. This is a common pattern when developers assume internal structs will always marshal successfully. | |
| **Prevention:** Always check and handle the `error` returned by `json.Marshal`. If it fails, log the error securely and return a generic 500 Internal Server Error without leaking details to the client. | |
| # Sentinel Notes | |
| ## 2026-06-06 - Fix unhandled json.Marshal errors in API handlers | |
| **Vulnerability:** In `internal/api/handlers.go`, errors from `json.Marshal` were explicitly ignored using `_` when wrapping event payloads. | |
| **Learning:** Ignoring marshaling errors allows empty or malformed byte slices to be enqueued, which could lead to downstream panics, silent data corruption, or denial-of-service if workers cannot process the invalid payloads. This is a common pattern when developers assume internal structs will always marshal successfully. | |
| **Prevention:** Always check and handle the `error` returned by `json.Marshal`. If it fails, log the error securely and return a generic 500 Internal Server Error without leaking details to the client. |
π§° Tools
πͺ markdownlint-cli2 (0.22.1)
[warning] 1-1: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 1-1: First line in a file should be a top-level heading
(MD041, first-line-heading, first-line-h1)
π€ Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.jules/sentinel.md around lines 1 - 4, The markdown heading at the top
("2026-06-06 - Fix unhandled json.Marshal errors in API handlers") is using an
H2 and lacks required surrounding blank lines; change the "##" to a top-level
"#" and ensure there is a single blank line before and after that heading (i.e.,
add an empty line above the heading and one empty line below it) so the file
conforms to MD041/MD022 rules.
Source: Linters/SAST tools
π¨ Severity: MEDIUM
π‘ Vulnerability: Unhandled
json.Marshalerrors ininternal/api/handlers.gocould lead to empty or invalid payloads being queued.π― Impact: Workers could crash or behave unpredictably when processing malformed payloads, leading to potential denial of service or data corruption.
π§ Fix: Explicitly check the
json.Marshalerror, log it securely, and returnhttp.StatusInternalServerError.β Verification: Ensure the test suite passes successfully.
PR created automatically by Jules for task 3485135590841703401 started by @mattjoyce
Summary by CodeRabbit
Release Notes