flawopen.com/Mass Assignment/व्याख्या
Mass Assignment: जोखिम और सुरक्षित field allowlist
Model को user-editable fields और staff-only controls वाले फ़ॉर्म की तरह समझें। पूरी request bind करने से ग्राहक account owner, approval या role भी भर सकता है। Editable fields server में तय करें और record तथा operation अलग authorize करें।
# Rails: request keys reach model attributes User.new(params[:user]) // Node / Mongoose: request object used as update await User.findByIdAndUpdate(id, req.body); // Express + Sequelize: request object used as create values await User.create(req.body); # Django: request keys passed as model fields User.objects.create(**request.POST.dict())
# Rails — permit only user-editable fields attrs = params.require(:user).permit(:name, :email) user = User.new(attrs) // Node — construct an allowlisted update const { name, email } = req.body; await User.findByIdAndUpdate(id, { name, email }); # Django — explicit ModelForm fields class UserForm(ModelForm): class Meta: model = User fields = ["name", "email"] // .NET — bind a DTO, then map explicitly user.Name = input.Name; user.Email = input.Email;
Server-side allowlist क्यों जरूरी है
“role के अलावा सब स्वीकारें” जैसी denylist नया sensitive field जुड़ने पर चूक सकती है। Allowlist में नया field तब तक editable नहीं होता जब तक code अनुमति न दे। Rails Strong Parameters mass assignment में गैर-अनुमत attributes रोकता है; controller को action के लिए सही fields ही permit करने चाहिए। DTO या स्पष्ट field list यही सीमा देते हैं।
Allowlist request द्वारा set attributes सीमित करती है; record बदलने की अनुमति नहीं देती। Record को authenticated principal तक सीमित करें, operation authorize करें और privileged बदलाव अलग server flow में रखें।
संवेदनशील fields की श्रेणियाँ
Model attributes, nested serializers और update endpoints में जाँचें:
- ✓Ownership और tenant keys — user_id, account_id, tenant_id। Server पर ownership जाँचें; client के owner पर भरोसा न करें।
- ✓Roles, permissions और workflow state — role, is_admin, email_verified, status। केवल अधिकृत server workflow से बदलें।
- ✓Financial और nested/system fields — balance, discount, credits, relations, timestamps और IDs नियमों या update scope को बदल सकते हैं। हर field को सोचकर permit और validate करें।
अक्सर पूछे जाने वाले प्रश्न
ये अलग कमजोरियाँ हैं। Mass assignment input को object पर अनचाहे attributes set करने देता है। Prototype pollution object prototype की properties बदलता है, जिससे अन्य objects की lookup प्रभावित हो सकती है। असुरक्षित merge इसका रास्ता बना सकता है; Mass Assignment properties के उपयोग पर निर्भर है। prototype pollution देखें।
नहीं। GraphQL mutation व्यापक input स्वीकार सकती है। Input types में केवल client-editable fields रखें और resolver या service में object तथा operation authorize करें।
नहीं। Form HTTP client के fields नहीं रोकता। हर field को attacker-controlled मानें, server पर structure validate करें और action के अपेक्षित fields ही स्वीकारें।