Menu

Block Impersonated Mini App Sessions by Enforcing Strict initData HMAC Verification in PHP
📰

Block Impersonated Mini App Sessions by Enforcing Strict initData HMAC Verification in PHP

DEV Community: php·Serhii·about 10 hours ago
#Ks9okpPl
#devto#dev#telegram#user#initdata
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.