Telegram Mini Apps run inside a WebView within the Telegram client, communicating with your backend API through HTTP requests. When a user opens your Mini App, Telegram exposes the window.Telegram.WebApp.initData and window.Telegram.WebApp.initDataUnsafe JavaScript objects containing user identity details like user ID, username, and language preferences.
Treating initDataUnsafe as an authentication token is a major security flaw. Because initDataUnsafe is parsed directly on the client side, any user can open Chrome DevTools, modify the JSON values in memory, and send an HTTP request to your PHP backend pretending to be another user or an administrator. If your backend relies on the user ID inside initDataUnsafe to grant session access or read database records, an attacker can access arbitrary user accounts by sending spoofed request payloads.
To prevent identity spoofing, Telegram signs the query parameters contained in window.Telegram.WebApp.initData using a hash derived from your Telegram Bot Token.…