Frappe Framework ERPNext 13.4.0 contains a sandbox escape vulnerability in RestrictedPython that allows authenticated users with System Manager role to execute arbitrary code by exploiting frame introspection. Attackers can create a server script via the /app/server-script endpoint and access the gi_frame attribute to traverse the call stack and invoke os.popen to execute system commands.
ERPNext 13.4.0 contains a critical sandbox escape vulnerability allowing authenticated System Manager users to execute arbitrary system commands through frame introspection in RestrictedPython. This vulnerability poses severe risk to Saudi organizations using ERPNext for ERP operations, as compromised or malicious administrators can gain full system control. Immediate action is required to restrict System Manager role assignments and implement compensating controls.
IMMEDIATE ACTIONS:
1. Audit all System Manager role assignments and remove unnecessary users immediately
2. Enable comprehensive logging for server-script endpoint access and RestrictedPython execution
3. Implement network segmentation to restrict ERPNext server access to authorized networks only
4. Review audit logs for suspicious server-script creation or execution patterns
COMPENSATING CONTROLS (until patch available):
5. Disable server-script functionality entirely if not critical to operations via bench command: bench set-config server_script_enabled 0
6. Implement application-level access controls restricting /app/server-script endpoint to specific IP addresses
7. Deploy Web Application Firewall (WAF) rules to block server-script POST requests from unauthorized sources
8. Enforce multi-factor authentication for all System Manager accounts
9. Implement real-time monitoring for os.popen, subprocess, and exec function calls within ERPNext processes
DETECTION RULES:
- Monitor for DocType 'Server Script' creation/modification in audit logs
- Alert on any frame introspection attempts (gi_frame attribute access)
- Track execution of system commands from ERPNext application user context
- Monitor for unusual child process spawning from ERPNext bench processes
الإجراءات الفورية:
1. تدقيق جميع تعيينات دور مدير النظام وإزالة المستخدمين غير الضروريين فوراً
2. تفعيل تسجيل شامل لوصول نقطة نهاية server-script وتنفيذ RestrictedPython
3. تنفيذ تقسيم الشبكة لتقييد وصول خادم ERPNext إلى الشبكات المصرح بها فقط
4. مراجعة سجلات التدقيق للبحث عن أنماط مريبة في إنشاء أو تنفيذ server-script
الضوابط التعويضية (حتى توفر التصحيح):
5. تعطيل وظيفة server-script بالكامل إذا لم تكن حرجة للعمليات عبر أمر bench: bench set-config server_script_enabled 0
6. تنفيذ ضوابط الوصول على مستوى التطبيق لتقييد نقطة نهاية /app/server-script على عناوين IP محددة
7. نشر قواعد جدار الحماية لتطبيقات الويب (WAF) لحظر طلبات server-script POST من مصادر غير مصرح بها
8. فرض المصادقة متعددة العوامل لجميع حسابات مدير النظام
9. تنفيذ المراقبة في الوقت الفعلي لوظائف os.popen و subprocess و exec داخل عمليات ERPNext
قواعد الكشف:
- مراقبة إنشاء/تعديل DocType 'Server Script' في سجلات التدقيق
- التنبيه على أي محاولات استكشاف إطار (وصول سمة gi_frame)
- تتبع تنفيذ أوامر النظام من سياق مستخدم تطبيق ERPNext
- مراقبة توليد عمليات فرعية غير عادية من عمليات bench في ERPNext