How to Prevent Mass Assignment Vulnerabilities in Vibe-Coded Apps
OverMCP Team
Quick answer
Mass assignment vulnerabilities occur when AI-generated code blindly accepts user input and maps it directly to database fields, allowing attackers to modify fields they shouldn't (like isAdmin or role). To prevent this in vibe-coded apps, you must explicitly whitelist allowed parameters on every model update or creation endpoint. Use tools like OverMCP's free AI app security scanner to detect these flaws before deployment.
What are mass assignment vulnerabilities?
When you build an app with AI coding tools like Cursor or Bolt.new, the generated code often follows the path of least resistance. A common pattern is:
// AI-generated: dangerous pattern
app.put('/api/user/:id', async (req, res) => {
const user = await User.findById(req.params.id);
Object.assign(user, req.body); // mass assignment!
await user.save();
res.json(user);
});This code takes every field from req.body and copies it onto the user object. If your User model has fields like isAdmin, role, or accountBalance, an attacker can modify them by sending those fields in the request body.
Why vibe-coded apps are especially vulnerable
AI coding tools are trained to produce functional code quickly, not secure code. They often:
Object.assign, spread operator, Model.update() without field whitelisting)A real-world example: An indie maker built a task management app with Lovable.dev. The User model included a isPremium boolean. The AI generated an update profile endpoint that accepted any body fields. A user sent {"isPremium": true} and gained premium features without paying.
What to check first
Before you ship, run this checklist:
Object.assign(user, req.body) or user.update(req.body)?Model.create(req.body) without filtering?Step-by-step fix
1. Identify all endpoints that accept user input to update/create resources
Search your codebase for patterns like:
req.body used in update/create operationsObject.assign or spread operator with req.bodyuser.field = req.body.field in loops2. Implement field whitelisting
Use a library or manual whitelist. Example with Mongoose (Node.js):
const ALLOWED_UPDATES = ['name', 'email', 'bio'];
app.put('/api/user/:id', async (req, res) => {
const updates = {};
for (let field of ALLOWED_UPDATES) {
if (req.body[field] !== undefined) {
updates[field] = req.body[field];
}
}
const user = await User.findByIdAndUpdate(req.params.id, updates, {
new: true,
runValidators: true
});
res.json(user);
});For Express + Sequelize (SQL):
const ALLOWED_FIELDS = ['username', 'displayName'];
app.put('/api/user/:id', async (req, res) => {
const user = await User.findByPk(req.params.id);
if (!user) return res.status(404).send('User not found');
ALLOWED_FIELDS.forEach(field => {
if (req.body[field] !== undefined) {
user[field] = req.body[field];
}
});
await user.save();
res.json(user);
});3. Use ORM/ODM protection features
Model.create() and Model.findByIdAndUpdate() with the second parameter as an object of allowed fields, or use the $set operator.Model.update() with a fields option.update() with a data object that only includes allowed fields.4. Add authorization checks
Ensure the user can only update their own resources:
app.put('/api/user/:id', async (req, res) => {
if (req.user.id !== req.params.id) {
return res.status(403).send('Forbidden');
}
// ... proceed with whitelisted update
});5. Run a security scan
Use OverMCP's continuous security monitoring to automatically detect mass assignment and other OWASP Top 10 vulnerabilities in your vibe-coded app.
Common mistakes
Mistake 1: Relying on frontend validation
AI-generated frontends often add client-side checks (e.g., hiding admin fields in the UI), but attackers can send raw HTTP requests with tools like curl or Postman. Always validate on the server.
Mistake 2: Using `findByIdAndUpdate` with the entire body
// Dangerous
await User.findByIdAndUpdate(id, req.body);This allows any field to be updated. Always whitelist.
Mistake 3: Not running model validators on updates
If your model has validators (e.g., email format), they may not run on findByIdAndUpdate unless you pass { runValidators: true }.
Mistake 4: Exposing internal fields in API responses
Even if you prevent writes, if your API returns isAdmin in user profiles, it leaks information. Use toJSON transforms or projection to exclude sensitive fields.
Mistake 5: Forgetting about nested objects
Mass assignment can also happen with nested documents (e.g., updating address.city). Whitelist at each level or use libraries like lodash.pick.
How OverMCP helps
OverMCP is built specifically for vibe-coded apps. It scans your codebase for mass assignment patterns and other vulnerabilities. After connecting your GitHub repo or Vercel project via the Vercel security scanner, you get a report highlighting dangerous patterns like Object.assign with req.body and missing authorization checks. It's like having a security reviewer on every pull request.
FAQ
What is a mass assignment vulnerability?
It's when an attacker adds extra fields to a request that get written to the database, modifying data they shouldn't have access to (e.g., setting isAdmin: true).
How do I find mass assignment in my vibe-coded app?
Search for req.body used directly in update or create operations. Also look for Object.assign, spread operator, or Model.create(req.body). Use an automated scanner like OverMCP's free AI app security scanner to catch these quickly.
Can mass assignment happen in NoSQL databases?
Yes. In MongoDB, Mongoose's Model.create() and findByIdAndUpdate() are common vectors. In Firebase Realtime Database, if you use update() with user input directly, it's also vulnerable.
---
By following this guide, you'll close one of the most common security gaps in AI-generated apps. Scan your project with OverMCP before your next deployment to catch mass assignment and other vulnerabilities.