Menu

Stop User ID Spoofing in React Telegram Mini Apps with PHP HMAC Auth
📰

Stop User ID Spoofing in React Telegram Mini Apps with PHP HMAC Auth

DEV Community: php·Serhii·1 day ago
#WDukXEF7
#devto#dev#telegram#initdata#token
Reading 0:00
15s threshold

When developers build a Telegram Mini App—whether it is a digital storefront, a seat booking system, or a lead capture workflow—they often fall into a critical security trap. The Telegram WebApp SDK exposes an object named window.Telegram.WebApp.initDataUnsafe . This object conveniently contains parsed information about the current Telegram user, including their numeric id , first_name , username , and language_code .

Because this object is readily available in JavaScript, frontend developers frequently inspect initDataUnsafe.user.id and send it directly in POST requests to their API endpoints (e.g., fetch('/api/orders', { body: JSON.stringify({ userId: user.id, cart }) }) ).

This architecture is fundamentally broken. Anyone opening your React application in a standard desktop web browser or inspecting network traffic via Chrome DevTools can alter the JavaScript runtime state or send raw HTTP requests directly to your backend.…

Continue reading — create a free account

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