أمان الرفع
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
name the main upload risks.
الموضوعات المخطط لها
- Path traversal: a name like
../../etc/passwdescapes the folder. Prevent it by never using the client name in a path; if you must resolve a path,normalize()it and check it stays inside the base directory. - Oversized files: exhaust disk or memory. Enforce limits.
- Content sniffing: a browser may guess a type and run a file as script. Send the right
Content-Type, andX-Content-Type-Options: nosniff. - Trusting the declared type: verify signatures for important types.
- Serve uploads only through your controller, with access checks.
تفاصيل المخطط المبدئي
عرض عملي
Path target = base.resolve(storedName).normalize();
if (!target.startsWith(base)) throw new IllegalArgumentException("Bad path");اختبر فهمك
Which input should never be part of a path?
أظهر الإجابة
The client's filename.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.