Menu

Telegram token in VITE_ or NEXT_PUBLIC_? It's in your bundle
📰

Telegram token in VITE_ or NEXT_PUBLIC_? It's in your bundle

DEV Community: vite·Formgong·about 9 hours ago
#NuJkK5tD
#devtovite#devto#dev#token#form
Long article (1348 words) — no AI summary yet.
Reading 0:00
15s threshold

If your site was built with Lovable, or with anything else on Vite, or it's a Next.js app on Vercel, and its contact form sends messages to Telegram, look at what the bot token variable is called. If it's VITE_TELEGRAM_BOT_TOKEN or NEXT_PUBLIC_TELEGRAM_BOT_TOKEN , the token is in the JavaScript that every visitor downloads. Your .env file stays private. The build copies the value out of it and into the public bundle anyway.

Both frameworks say this in their docs. Lovable's page on secrets says "Anything prefixed with VITE_ is a build-time, browser-exposed value." The Next.js docs say a NEXT_PUBLIC_ value "will be inlined into any JavaScript sent to the browser."

We checked it ourselves anyway. A minimal Vite 8.3.1 app read import.meta.env.VITE_TELEGRAM_BOT_TOKEN , with a fake token 1234567890:AAFAKE-not-a-real-token-for-this-test in .env . After vite build , searching dist/assets/ turned up the full fake token in the one JS file.…

Continue reading — create a free account

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