Skip to content

fix(api): send a ClickStack User-Agent on generic alert webhooks - #3767

Merged
kodiakhq[bot] merged 3 commits into
mainfrom
warren/alert-issue-HDX-6170
Nov 23, 2026
Merged

kodiakhq[bot] merged 3 commits into
mainfrom
warren/alert-issue-HDX-6170

Conversation

@wrn14897

@wrn14897 wrn14897 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Generic and incident.io alert webhooks have sent User-Agent: undici since #3588 moved delivery to undici's fetch (for DNS-pinned SSRF checks). Node's built-in fetch sent node. Some receivers' WAFs block undici. They return an HTML 403 Forbidden before the request reaches the receiving service, so every alert to them fails.

Webhook delivery now sends User-Agent: ClickStack-Alerts/<CODE_VERSION>, or ClickStack-Alerts when no version is set. A User-Agent in the webhook's headers still wins. The check ignores case, so a user's user-agent is not sent next to the default.

The webhook test route uses the same function, so test sends get the new header too. Slack does not use undici and is unaffected.

Not changed here: a user's lowercase content-type is still sent next to the default Content-Type. That predates this PR.

Unit tests in transports/__tests__/generic.test.ts cover the default, an override, and a lowercase override. I did not run the integration suite locally. The existing checkAlerts.int.test.ts header assertion uses expect.objectContaining, so the new header should not break it.

How to reproduce

Starting point: yarn dev (alerts and webhooks need the API).

On main:

  1. Create a Generic webhook pointing at a request inspector such as https://webhook.site.
  2. Send a test notification from the webhook form.
  3. The inspector shows User-Agent: undici.

On this branch:

  1. Repeat the steps above. The inspector shows User-Agent: ClickStack-Alerts/<version>.
  2. Add {"User-Agent": "custom"} under the webhook's headers and send again. The inspector shows custom.

How to test on Vercel preview

N/A — non-UI change

References

@wrn14897
wrn14897 requested a review from a team as a code owner November 23, 2026 10:21
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 23, 2026 10:45am UTC
hyperdx-storybook Ready Ready Preview Nov 23, 2026 10:45am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 39d9e0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Additional context: touches background tasks or the delivery pipeline lightly (16 lines, under the 30-line bar for Tier 4)

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 2
  • Production lines changed: 16 (+ 40 in test files, excluded from tier calculation)
  • Branch: warren/alert-issue-HDX-6170
  • Author: wrn14897

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.13%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 P0/P1 · 🟡 0 P2 · 🔵 1 P3

No inline comments. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/api/src/tasks/checkAlerts/transports/__tests__/generic.test.ts:336 — The default User-Agent test compares the code's output to the same constant, so the versioned format is never checked → The test compares the sent header to WEBHOOK_USER_AGENT and only checks the ClickStack-Alerts prefix. In unit tests CODE_VERSION is usually '' (config.ts:16), so the ClickStack-Alerts/<version> branch in tasks/util.ts:6 never runs. A regression such as a missing slash, a hyperdx prefix, or a dropped version would still pass. Fix: add a test that mocks @/config with a version (for example CODE_VERSION: '1.2.3'), as tasks/__tests__/index.test.ts already does, and assert the literal 'ClickStack-Alerts/1.2.3'.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a small, well-scoped change: outbound generic/incident.io alert webhooks now send a default User-Agent: ClickStack-Alerts/<CODE_VERSION> (falling back to ClickStack-Alerts) instead of undici's undici, with a case-insensitive check so a webhook's own User-Agent still wins. The header-merge ordering, case-insensitivity, and empty-version fallback are all correct, and the new tests cover the default, exact-case override, and lowercase override (including asserting no duplicate User-Agent key).

🟡 P2 -- recommended

  • packages/api/src/tasks/util.ts:5 -- The version-suffixed arm of WEBHOOK_USER_AGENT is never exercised: the test environment leaves CODE_VERSION empty (config.ts:16), so only the bare ClickStack-Alerts branch runs, and the default test compares the sent header against the same imported constant, so a broken `ClickStack-Alerts/${CODE_VERSION}` interpolation would go undetected.
    • Fix: Add a unit test on the derivation that sets a non-empty CODE_VERSION and asserts the resulting value equals ClickStack-Alerts/<version>.
    • testing, kieran-typescript, reliability

Reviewers (7): correctness, testing, maintainability, security, reliability, kieran-typescript, previous-comments.

Testing gaps:

  • No test asserts that a CODE_VERSION containing CR/LF or control characters is rejected before reaching the fetch headers; delivery currently relies on undici's header-value validation and on CODE_VERSION being trusted build-time config (low risk, not end-user input).
  • The non-string-value drop branch of toStringHeaderRecord (generic.ts:179) remains untested; only string-valued header paths are exercised (pre-existing).

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

The undici fetch adopted for DNS-pinned webhook delivery defaults to
User-Agent: undici, which some receiver WAFs block with a 403. Send
ClickStack-Alerts/<version> unless the webhook sets its own User-Agent,
matched case-insensitively.

Refs HDX-6170
@wrn14897
wrn14897 force-pushed the warren/alert-issue-HDX-6170 branch from c85fb9c to 62f91cd Compare November 23, 2026 10:28
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 475 passed • 1 skipped • 1080s

Status Count
✅ Passed 475
❌ Failed 0
⚠️ Flaky 9
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@kodiakhq
kodiakhq Bot merged commit 272a461 into main Nov 23, 2026
28 checks passed
@kodiakhq
kodiakhq Bot deleted the warren/alert-issue-HDX-6170 branch November 23, 2026 10:51

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 39d9e0bd Deployed Nov 23, 2026 by vercel[bot]
Preview – hyperdx-storybook — 39d9e0bd Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants