Menu

Prevent Session Injection in Telegram Mini Apps with PHP initData HMAC Checks
📰

Prevent Session Injection in Telegram Mini Apps with PHP initData HMAC Checks

DEV Community: php·Serhii·6 days ago
#XiIDb1D8
#devto#dev#telegram#user#string
Long article (2153 words) — no AI summary yet.
Reading 0:00
15s threshold

Building a Telegram Mini App often starts smoothly on the frontend. You load https://telegram.org/js/telegram-web-app.js , open the SDK inside Telegram, and instantly access window.Telegram.WebApp.initDataUnsafe . From initDataUnsafe , you get a pre-populated JavaScript object containing the user's Telegram ID, first name, username, and query parameters.

It is tempting to grab initDataUnsafe.user.id , send it directly to your PHP backend via fetch() , and immediately start processing bookings, loading private user data, or crediting account balances. Doing this introduces a critical vulnerability: initDataUnsafe can be manipulated by anyone with browser developer tools.

Because a Telegram Mini App runs inside an embedded web view, any user can open devtools, rewrite window.Telegram.WebApp.initDataUnsafe.user.id to match a target victim's ID, and send forged requests to your server.…

Continue reading — create a free account

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