TL;DR
Replit is a cloud development environment with AI built in. Your code runs on shared infrastructure, which makes secrets management the thing to get right first. Put every key in Replit's Secrets rather than in a file, remember that a free Repl is readable by anyone, and set up authentication before you deploy. Deployments run in their own environment, separate from the Repl you develop in.
Understanding Replit's Environment
Replit bundles an online IDE, an AI assistant, a database, and hosting into one tab. That's convenient. It also makes four things true about your project that wouldn't be if it lived on your laptop:
- Cloud-based: Your code lives on Replit's servers, not your local machine
- Public by default: Free Repls are publicly visible unless you pay for private
- Shared infrastructure: Development environments run on shared resources
- AI assistance: Replit's AI can see your code context
Important: If you're on a free plan, anyone can view your Repl's code. Never put secrets in code files on public Repls.
Secrets Management in Replit
Using Replit Secrets (The Right Way)
Replit has a Secrets panel that keeps values out of your files and out of view. Use it for anything you'd be unhappy to see printed:
import os
# Secrets are accessed via environment variables
api_key = os.environ.get('STRIPE_API_KEY')
db_password = os.environ.get('DATABASE_PASSWORD')
# Always check if the secret exists
if not api_key:
raise ValueError('STRIPE_API_KEY is not set in Secrets')
// Secrets are available in process.env
const apiKey = process.env.STRIPE_API_KEY;
const dbPassword = process.env.DATABASE_PASSWORD;
if (!apiKey) {
throw new Error('STRIPE_API_KEY is not set in Secrets');
}
How to Add Secrets
- Open the Tools panel in your Repl
- Click "Secrets"
- Add key-value pairs for your sensitive data
- Access them via environment variables in your code
Never do this: Don't put API keys, passwords, or tokens directly in your code files. Even in private Repls, it's bad practice.
Public vs Private Repls
| Feature | Public Repl (Free) | Private Repl (Paid) |
|---|---|---|
| Code visibility | Anyone can view | Only you and collaborators |
| Secrets visibility | Hidden from viewers | Hidden from viewers |
| Fork ability | Anyone can fork | Only collaborators |
| Search indexed | May appear in search | Not indexed |
Note: Even in public Repls, Secrets values are hidden from viewers. But your code logic, file structure, and non-secret configuration are visible.
Replit Deployments Security
Deploying runs your project in a separate environment from the Repl you've been editing. That distinction matters: the two don't share state, and a secret you added in one isn't automatically in the other.
Deployment Types
- Static: For HTML/CSS/JS sites without backend
- Autoscale: For apps with variable traffic
- Reserved VM: For apps needing consistent resources
Deployment Security Checklist
Before Deploying
All secrets are in Replit Secrets, not in code
No debug mode or verbose logging in production
Authentication is implemented for protected routes
Database has proper access controls
HTTPS is being used (Replit provides this)
CORS is configured to allow only your domains
Error messages don't expose internal details
Rate limiting is configured for APIs
Replit Database Security
Replit ships a built-in key-value database, handy for getting something working. Two things to know before you rely on it.
from replit import db
# The database is tied to your Repl
# It's not accessible from other Repls
# Store data
db["user_123"] = {"name": "John", "email": "john@example.com"}
# Retrieve data
user = db.get("user_123")
# Important: Replit DB is not encrypted at rest
# Don't store highly sensitive data like passwords or payment info
# Use a proper database for production apps
Limitation: Replit DB is built for prototypes, not production. Once real users show up, connect a real database instead: Supabase, PlanetScale, or MongoDB Atlas all work fine from a Repl.
Common Security Mistakes in Replit
These three come up constantly in the projects we scan. The first one is the easiest to ship without noticing.
1. Hardcoded API Keys
# DON'T DO THIS
import openai
openai.api_key = "sk-abc123..." # Anyone can see this!
import os
import openai
openai.api_key = os.environ.get('OPENAI_API_KEY')
2. Exposed Admin Routes
# BAD: No authentication
@app.route('/admin/delete-user/<user_id>')
def delete_user(user_id):
db.delete_user(user_id)
return "User deleted"
# GOOD: With authentication
from functools import wraps
def require_admin(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.headers.get('Authorization')
if not verify_admin_token(auth):
return jsonify({"error": "Unauthorized"}), 401
return f(*args, **kwargs)
return decorated
@app.route('/admin/delete-user/<user_id>')
@require_admin
def delete_user(user_id):
db.delete_user(user_id)
return "User deleted"
3. SQL Injection in Database Queries
# BAD: String concatenation
query = f"SELECT * FROM users WHERE email = '{user_email}'"
cursor.execute(query)
# GOOD: Parameterized query
query = "SELECT * FROM users WHERE email = ?"
cursor.execute(query, (user_email,))
Replit AI Security Considerations
The AI reads your code to make suggestions, which is the point of it. That access is worth keeping in mind:
- Don't paste a secret into chat or leave one in a comment so the AI will "remember" it
- Read AI-generated code before you ship it, particularly anything touching auth or a database
- Watch for hardcoded example values. Placeholder strings have a way of surviving into production
Are my Replit Secrets really secure?
Replit Secrets are stored encrypted and don't appear in your code files or to anyone viewing a public Repl. The catch: anyone who can run your Repl can read them from code, since that's how your own app reads them. The real control is who you let in. For anything sensitive, use a private Repl and keep the collaborator list short.
Can other Replit users access my data?
Your Repl's data (files, database, secrets) is isolated from other users. Other users can view your code in public Repls but can't access your Secrets or modify your files unless you add them as collaborators.
Should I use Replit for production apps?
Yes, for smaller applications. Replit Deployments are real hosting. Have these in place first: a private Repl, your keys in Secrets, authentication on anything that isn't public, and an external database instead of Replit DB for data you'd hate to lose.
What happens to my code when I delete a Repl?
Deleting a Repl removes the code and its data from Replit's servers. Forks are a different story: if the Repl was public, someone else's copy doesn't go anywhere when yours does. Rotate any secret that ever lived in a deleted Repl. It costs a minute.
Building on Replit?
Scan your Replit project for security vulnerabilities before going live.