SQL Injection in Bolt AI-Generated Database Queries
Your Bolt.new application contains SQL injection vulnerabilities in its database queries. The AI-generated code concatenates user input directly into SQL strings instead of using parameterized queries, allowing attackers to manipulate your database.
An attacker can exploit this by entering specially crafted input into form fields, search boxes, or URL parameters. For example, entering ' OR 1=1 -- into a login form could bypass authentication entirely, or entering '; DROP TABLE users; -- could delete your entire users table.
This vulnerability is particularly dangerous because it can go completely unnoticed during normal use. The app works perfectly with legitimate input, but an attacker with basic SQL knowledge can read, modify, or delete any data in your database.
Error Messages You Might See
Common Causes
- String concatenation in queries — Bolt generated code like `SELECT * FROM users WHERE id = '${userId}'` instead of using parameterized queries
- Raw SQL with template literals — Using Prisma's $queryRawUnsafe or Supabase's rpc with unsanitized user input
- Dynamic table or column names — Building queries with user-controlled table names or sort columns without whitelisting
- Search functionality with LIKE — Search queries built by concatenating user input: WHERE name LIKE '%${searchTerm}%'
- Filter parameters passed directly — URL query parameters inserted into WHERE clauses without sanitization
How to Fix It
- Use parameterized queries everywhere — Replace string concatenation with parameterized queries: prisma.$queryRaw`SELECT * FROM users WHERE id = ${userId}`
- Use Prisma's query builder — Let Prisma handle parameterization: prisma.user.findMany({ where: { name: { contains: searchTerm } } })
- Whitelist dynamic identifiers — If you need dynamic column names, validate them against an allowlist: const allowed = ['name', 'date', 'price']; if (!allowed.includes(sortBy)) throw new Error('Invalid sort')
- Use Supabase client safely — The Supabase JS client automatically parameterizes: supabase.from('users').select().eq('id', userId)
- Test with SQLi payloads — Enter ' OR 1=1 -- into your form fields and search boxes to check if they return unexpected results
- Add input validation — Validate and sanitize all user inputs with a library like zod or validator.js before they reach any query
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
Is Prisma safe from SQL injection by default?
Prisma's query builder (findMany, create, etc.) is safe by default. However, Prisma's $queryRaw requires tagged template literals for safety. Using $queryRawUnsafe or string concatenation with $queryRaw bypasses protection.
How can I test my app for SQL injection?
Enter these payloads in text fields: ' OR 1=1 --, '; DROP TABLE test; --, and ' UNION SELECT null, null --. If the app behaves unexpectedly (returns all records, errors with SQL syntax), you have a vulnerability.