Bolt.new App Security Hardening Guide
Bolt.new lets you scaffold and deploy full-stack apps to Netlify in minutes, but default Vite templates ship public sourcemaps, wide-open CORS headers on helper functions, and unhardened database tables.
During rapid in-browser WebContainer prototyping, Bolt.new often adds Access-Control-Allow-Origin: * to silence browser CORS errors and puts temporary credentials in .env files that get bundled into client JS.
- Public JS sourcemaps reveal original TypeScript code, prompt logic, and internal endpoints
- Wildcard CORS on serverless functions allows malicious websites to call your APIs
- Missing security headers in netlify.toml leave apps open to clickjacking and XSS
Vulnerable Pattern vs. Production Fix
// vite.config.ts — Leaks full source code in production!
export default defineConfig({
plugins: [react()],
build: {
sourcemap: true, // Exposes original TypeScript to every visitor
},
});# netlify.toml — Add production security headers
[[headers]]
for = "/*"
[headers.values]
Strict-Transport-Security = "max-age=31536000; includeSubDomains"
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"
Permissions-Policy = "camera=(), microphone=(), geolocation=()"
Content-Security-Policy = "default-src 'self'; object-src 'none'; frame-ancestors 'none';"Copy-Paste AI Fix Prompt (Cursor · Lovable · Bolt · Claude Code)
Harden this Bolt.new project for production deployment: 1. Set build.sourcemap = false in vite.config.ts. 2. Add a netlify.toml (or vercel.json) with Strict-Transport-Security, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, Referrer-Policy, Permissions-Policy, and a working Content-Security-Policy. 3. Audit all API/serverless functions to replace Access-Control-Allow-Origin: * with our exact production origin and verify user authentication. 4. Move any private API keys out of VITE_* env vars into server-only environment variables.
How to Verify Your Fix Worked
- 1Deploy the updated build and scan your live URL with VibeSecCheck.
- 2Verify `//# sourceMappingURL=` no longer appears in production JS assets.
- 3Confirm security headers return cleanly with `curl -I https://your-bolt-app.netlify.app`.
Frequently Asked Questions
Why does Bolt.new leave sourcemaps enabled?
Sourcemaps help debug React stack traces in WebContainers, so templates sometimes leave build.sourcemap enabled when exporting to production.
Are Bolt.new .env files safe on Netlify?
Only server-side Netlify Functions keep non-VITE_ variables secret. Anything prefixed with VITE_ is embedded directly into the public JavaScript bundle.
Does Netlify add security headers automatically?
No. You must explicitly configure CSP, X-Frame-Options, nosniff, and Permissions-Policy inside netlify.toml or a public/_headers file.