Skip to content

notify/pushover: trim whitespace from token and user key files - #5398

Open
dpacgdm wants to merge 1 commit into
prometheus:mainfrom
dpacgdm:fix/pushover-trim-secret-file-newlines
Open

notify/pushover: trim whitespace from token and user key files#5398
dpacgdm wants to merge 1 commit into
prometheus:mainfrom
dpacgdm:fix/pushover-trim-secret-file-newlines

Conversation

@dpacgdm

@dpacgdm dpacgdm commented Jul 21, 2026

Copy link
Copy Markdown

Summary

  • Trim trailing whitespace/newlines when reading token_file and user_key_file (same pattern as pagerduty/slack/etc.).
  • Editors like vim append a newline by default; Pushover then rejects the credentials with HTTP 400.

Related to #3641

Test plan

  • go test ./notify/pushover/ -count=1
  • Existing file-backed secret tests now write secrets with a trailing \n and still succeed

Editors often append a trailing newline; Pushover rejects those values as invalid credentials. Match other notifiers that already TrimSpace file-backed secrets.
@dpacgdm
dpacgdm requested a review from a team as a code owner July 21, 2026 15:04
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3f956ca2-e52a-4b95-95be-2dd7191e54f0

📥 Commits

Reviewing files that changed from the base of the PR and between 949777a and ed59328.

📒 Files selected for processing (2)
  • notify/pushover/pushover.go
  • notify/pushover/pushover_test.go

📝 Walkthrough

Walkthrough

Pushover now trims whitespace from credentials read through TokenFile and UserKeyFile. Tests write newline-terminated credentials to temporary files and explicitly close them.

Changes

Pushover credential handling

Layer / File(s) Summary
Trim file credentials and validate newline handling
notify/pushover/pushover.go, notify/pushover/pushover_test.go
File-loaded tokens and user keys are passed through strings.TrimSpace; tests cover credentials with trailing newlines and check temporary file closure.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and matches the main change to Pushover file-backed credentials.
Description check ✅ Passed The description covers the summary, issue link, and test plan, with only minor template sections like release notes omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BradKollmyer

Copy link
Copy Markdown

Confirming from production on 0.33.1, with one detail I don't see recorded here
or in #3641: this fails completely silently, and it kills paging fleet-wide.

Three-site Prometheus/Alertmanager fleet, zero pages delivered for six days —
1242 failed notifications on one site alone. Targets up, rules evaluating,
alerts firing and visible in the UI; they just never left the building. The only
trace is a notify error in the journal, which nobody reads because the thing
that tells you to look is the thing that's broken.

The trigger is moving credentials from inline token/user_key into
token_file/user_key_file — inline, YAML strips the newline; via the file,
nothing does. So it specifically punishes the more secure option.

Small clarification on the API: Pushover accepts a trailing space and
rejects only the newline ({"token":"invalid"}, or {"user":"invalid"} for
the user key). TrimSpace covers both, so the fix here is unchanged — but it's
why the file looks fine under inspection, since you see 30 plausible characters.
The tell is wc -c reporting 31.

Also worth noting for review: prometheus/common's FileSecret.Fetch already
TrimSpaces file-backed secrets, and this same file TrimSpaces the message
body ~20 lines below. The credentials are the exception.

#3641 has been open since December 2023 and this is 8 lines with tests — would
be great to see it land.

@TheMeier

Copy link
Copy Markdown
Contributor

I think it makes sense to add a separate new test instead of modifing the existing one because files without an extra newline are not properly covered anymore. Also Commit signature is missing. Please use the existing PR template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants