Bug: DingTalk notification builds JSON by string concatenation, echoes the token, leaks resp.Body and swallows errors

Open Beginner friendly
#84 0 comments 0 reactions 0 assignees View on GitHub

@linuxsuren-fs is already working on this.

Since Nov 17, 2026.

  • #93 by @linuxsuren-fs — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, json
Domain
backend

Research direction

Open cmd/pull_request.go at sendToDingDing (around line 103) and read it together with the goroutines launched in runE (lines 92-97). Fix the three self-contained items first: replace the string-concatenated payload with json.Marshal, delete the fmt.Println that echoes api, and defer resp.Body.Close() after the http.Post; leave the error-swallowing/--strict question as a separate discussion. A unit test can assert the marshalled body is valid JSON for a message containing quotes and newlines, and a passing go test ./cmd/... plus go vet is the done signal.

Written by the indexing model from the issue text.

Description

bug

Description

sendToDingDing in cmd/pull_request.go:103 has four defects:

1. JSON payload is built by string concatenation (line 111):

payload := strings.NewReader(`{"msgtype": "text", "text": {"content": "` + formattedMsg + `"}}`)

Any --msg containing a double quote, backslash or newline produces invalid JSON (or injects arbitrary fields), so DingTalk rejects the request. The message is a Go template over PR data, so quotes are entirely realistic. It should use json.Marshal:

payload, _ := json.Marshal(map[string]any{
    "msgtype": "text",
    "text":    map[string]string{"content": formattedMsg},
})

2. Access token is echoed to stdout (line 112):

fmt.Println(`{"msgtype"...`, api)

api contains ?access_token=…, so the robot token leaks into CI logs. This debug print should be removed.

3. resp.Body is never closed — leaks a connection per notification.

4. Errors are swallowed — the goroutines in runE (lines 92–97) ignore the returned error, and sendToDingDing itself only writes to a writer; a fully failed notification batch still exits 0. If failing silently is intentional for notifications, consider an explicit flag (e.g. --strict) so pipelines can opt into failing on delivery errors.

Items 1–3 are small, self-contained fixes with easy unit tests.

Dominant language
Go
Stars
19
Forks
3
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LinuxSuRen/gogit

All issues in LinuxSuRen/gogit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.