Repository navigation
Harden bot key authentication against a blank token (release-1.5) - #448
Merged
Merged
Conversation
`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)
Contributor
There was a problem hiding this comment.
🟡 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 rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Backports #447 to
release-1.5, so that the next 1.5.x release carries it.User.authenticate_botonrelease-1.5is identical to the method onmainbefore #447, and the commit cherry-picks cleanly.A bot key with no token after the id (
12or12-) left the tokennil, and the lookup then matched a bot whosebot_tokenisNULL. A key such as12--xgave an empty token, which matched a bot whosebot_tokenis"".authenticate_botnow returnsnilwhen the token is blank.