Validating Telegram Login Widget Hashes in Yii2 to Block Account Impersonation
Telegram's Login Widget authenticates users client-side and then passes identity parameters to a website, so trusting those values directly lets attackers take over accounts by altering the query string. The article recommends verifying the payload's signature on the server using the bot token, rejecting payloads whose auth_date is too old, and mapping the verified Telegram ID to the application's user records. It warns that the Login Widget's verification differs from the Mini App initData method: the secret key is a plain SHA-256 hash of the bot token rather than an HMAC derived with 'WebAppData'. The author provides a reusable Yii2 component, TelegramAuthValidator, that sorts the data-check string, performs constant-time HMAC comparison, and enforces a 24-hour expiry window.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in