Skip to content

Harden bot key authentication against a blank token (release-1.5) - #448

Merged
flavorjones merged 1 commit into
release-1.5from
card-5441-blank-bot-token-release-1-5
Nov 20, 2026
Merged

flavorjones merged 1 commit into
release-1.5from
card-5441-blank-bot-token-release-1-5

Conversation

@flavorjones

Copy link
Copy Markdown
Member

Backports #447 to release-1.5, so that the next 1.5.x release carries it. User.authenticate_bot on release-1.5 is identical to the method on main before #447, and the commit cherry-picks cleanly.

A bot key with no token after the id (12 or 12-) left the token nil, and the lookup then matched a bot whose bot_token is NULL. A key such as 12--x gave an empty token, which matched a bot whose bot_token is "". authenticate_bot now returns nil when the token is blank.

`User.authenticate_bot` searched with a missing or empty token, so a key
holding only a bot's id matched that bot if its `bot_token` was `NULL`,
and a key with an empty token segment matched a `bot_token` of `""`.
Return `nil` when the token is blank.

(cherry picked from commit 00373e1)
Copilot AI balanced review requested due to automatic review settings November 20, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests lack a regression case for a whitespace-only stored token, which could still permit authentication despite coverage for nil and empty tokens.

1 open issue
What changed in this PR

Backports bot-key authentication hardening to release-1.5, preventing blank tokens from matching bot records with blank stored tokens.

Changes:

  • Requires a non-blank token before looking up an active bot.
  • Adds regression tests for missing and empty tokens.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
test/​models/​user/​bot_test.rb Tests rejection of missing and empty bot tokens.
app/​models/​user/​bot.rb Guards authentication with a token presence check.

Review effort: Balanced

Comment thread test/models/user/bot_test.rb Resolved
@flavorjones
flavorjones merged commit 32d5256 into release-1.5 Nov 20, 2026
10 checks passed
@flavorjones
flavorjones deleted the card-5441-blank-bot-token-release-1-5 branch November 20, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants