role=admin or is_verified=true) that the application blindly assigns to the data model.Why It Matters for AI-Coded Apps
AI code generators love mass assignment because it produces clean, concise code. When prompted to build CRUD operations, LLMs generate User.create(req.body) or user.update(**request.data) which blindly accepts all user-submitted fields, including privileged ones like role, permissions, or billing status.
Real-World Example
A registration endpoint uses User.create(req.body). The expected input is {name, email, password}. An attacker sends {name: 'Evil', email: 'evil@test.com', password: '123', role: 'admin', is_verified: true}. The database creates an admin account because all fields were bound without filtering.
How to Detect and Prevent It
Explicitly define which fields can be set by users (allowlist approach). Use DTOs or serializers that only accept permitted fields. In Rails, use strong_parameters. In Django, use serializer fields. In Express, destructure only expected fields: const {name, email, password} = req.body. Never pass raw request bodies to database operations.
Frequently Asked Questions
What is the difference between mass assignment and IDOR?
Do ORMs prevent mass assignment?
strict mode, Django REST Framework has serializer fields, and Rails has strong_parameters. However, AI-generated code often uses these ORMs in their most permissive configuration, bypassing built-in protections.