The Real Fullstack

The Mass Assignment

The admin field isn't in the form. How did a customer become an administrator?

مهندس7 دقيقةتحدي الشيفرةمختبر تصحيح الأخطاء
spring-bootjpaexpressjson

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Choose the server-side checks that let legitimate clients (web and mobile) update their own profile, and nothing else.السياق · أهداف التعلّم ▾

Wrenly's profile endpoint binds the JSON body straight onto the User entity and copies every property. The web form only shows name and email, so the team assumed the other fields were safe. A support log shows a customer with role ADMIN and a credit balance of 9,999.

المهمة: Choose the server-side checks that let legitimate clients (web and mobile) update their own profile, and nothing else.

أهداف التعلّم

  • Understand mass assignment (over-posting).
  • Prefer allow-listed request DTOs to deny-listing sensitive fields.
  • Check object ownership on every update.
المحاكاةمحاكاة

شغّل المحاكاة لترى المخرجات.

تشغيل المحاكاة
@PatchMapping("/users/{id}")User update(@PathVariable String id, @RequestBody User body) {  User u = repo.findById(id).orElseThrow();  BeanUtils.copyProperties(body, u, "id");      // copies role, creditBalance, …  return repo.save(u);}

تبسيط

Six requests with fixed attributes. Real APIs also validate formats, lengths and rate-limit profile changes. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

تحديات ذات صلة

المراجع