Skip to content

feat(coderd/x/chatd/chatwebhook): add bearer, github and standard_webhooks verifiers - #32062

Merged
ThomasK33 merged 7 commits into
mainfrom
tk/automations-webhook-verifiers
Nov 12, 2026
Merged

ThomasK33 merged 7 commits into
mainfrom
tk/automations-webhook-verifiers

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Why

An automation webhook must prove that a request comes from the holder of the automation's secret before Coder parses the JSON body. The approved RFC (Automations for Coder Agents, Webhooks section) puts that check behind one WebhookVerifier interface with three schemes. This PR adds those verifiers as a pure Go package. The webhook route that calls them comes in a later PR.

Part of CODAGT-1135.

What changed

New leaf package coderd/x/chatd/chatwebhook:

  • WebhookVerifier, with the three methods exactly as the RFC writes them, and three verifiers: bearer (constant-time token compare, one or more spaces after Bearer as in RFC 6750 section 2.1), github (HMAC-SHA256 of the raw body in X-Hub-Signature-256) and standard_webhooks (HMAC-SHA256 of webhook-id.webhook-timestamp.body, v1, entries in webhook-signature, five-minute timestamp window, whsec_ secret).
  • Scheme with the three RFC enum strings, and NewVerifier(Scheme). The package does not import coderd/database.
  • Every Verify failure wraps ErrRejected, so the route can answer 401. Every Verify and ValidateSecret error is built from a fixed string: it never holds the secret, the received token or a signature. The package does not log. Only the NewVerifier error names the unknown scheme.
  • GenerateSecret reads 32 bytes from crypto/rand for bearer and github. For standard_webhooks it returns ok=false, and ValidateSecret checks the pasted whsec_ secret.

Scope

  • No database, no HTTP route, no wiring, no new Go module. Nothing imports the package yet, so main behaves as before with the chat-automations experiment off.
  • The map from the database enum to a verifier, and its "every enum value has a verifier" test, belong to the route PR. It can call NewVerifier(chatwebhook.Scheme(automation.WebhookAuth)). A NewVerifier error is a server error, not a 401.
  • No deduplication by webhook-id, as in the RFC. The same valid request verifies every time.

Tradeoffs

  • A pasted whsec_ secret has no length bound. The spec describes sender secrets of 24 to 64 bytes, but it does not tell a receiver to reject others. A bound would lock out a sender that deviates, and it protects only the owner from the sender's own key.
  • The bearer verifier accepts one or more spaces between Bearer and the token, as RFC 6750 section 2.1 and the API key middleware do. It rejects a tab and an empty token. It also rejects trailing whitespace after the token when it receives it, but an HTTP request cannot deliver that: net/http strips trailing whitespace from the header value before the verifier runs, so such a request is accepted with the right token.
  • The signed Standard Webhooks content uses the webhook-timestamp text as received. The reference Go library signs the reformatted number instead. The two differ only for a timestamp with leading zeros, which a conforming sender does not send.
  • A webhook-id that contains . is rejected. The spec asks senders to avoid it, because it makes id.timestamp.body ambiguous. A repeated Authorization, X-Hub-Signature-256, webhook-id or webhook-timestamp line is rejected for the same reason. Several webhook-signature lines are read as one list.
  • TestSecretComparisonsAreConstantTime reads the package source and fails on ==, bytes.Equal and similar on secrets. A correct early-exit compare gives the same answers as a constant-time one, so a request-level test cannot tell them apart. The scan is a guard against the likely mistake, not a proof.

Verification

  • Test vectors come from the GitHub docs and from TestWebhookSign in the Standard Webhooks Go library. The tests cite the URL beside each vector.
  • Live lane: none. No route, CLI or UI reaches this code yet, so there is no surface to exercise.

Generated with xum • Model: anthropic:claude-sonnet-5-5 • Thinking: xhigh

…hooks verifiers

Pure Go verifiers for the automation webhook route. No database, no HTTP route.
…d in the bearer verifier

The empty-token check already rejects an empty secret. A mutation of the guard left every test green.
@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 21:15 — with GitHub Actions Inactive
@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown

CODAGT-1135

@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 21:15 — with GitHub Actions Inactive
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T21:51:23.914307Z 27d0ba8 Manual request
🔒 Security Review ✅ Completed 2026-11-11T21:51:20.830911Z 27d0ba8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 8b3119a89b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8b3119a89b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

CI revive unhandled-error flags mac.Write. Use the repo idiom _, _ = mac.Write.
RFC 6750 section 2.1 defines credentials as "Bearer" 1*SP b64token, and the API key middleware accepts it. Trailing whitespace, tabs, an empty token and other schemes stay rejected.
…ify and ValidateSecret

The NewVerifier error names the unknown scheme.
@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 21:48 — with GitHub Actions Inactive
@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 21:48 — with GitHub Actions Inactive
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 27d0ba8617

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 27d0ba8617

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 22:17 — with GitHub Actions Inactive
@ThomasK33
ThomasK33 temporarily deployed to main November 11, 2026 22:27 — with GitHub Actions Inactive

@ethanndickson ethanndickson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only complaint is the ratio of test to product code

@ThomasK33
ThomasK33 merged commit 85e689c into main Nov 12, 2026
41 checks passed
@ThomasK33
ThomasK33 deleted the tk/automations-webhook-verifiers branch November 12, 2026 01:49
@ThomasK33
ThomasK33 temporarily deployed to main November 12, 2026 01:49 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026

This branch was previously deployed

1 inactive deployment
main — 27d0ba86 Deployed Nov 12, 2026 by ThomasK33 via cla #254586
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants