Mako is a template library written in Python. Prior to 1.3.11, TemplateLookup.get_template() is vulnerable to path traversal when a URI starts with // (e.g., //../../../secret.txt). The root cause is an inconsistency between two slash-stripping implementations. Any file readable by the process can be returned as rendered template content when an application passes untrusted input directly to TemplateLookup.get_template(). This vulnerability is fixed in 1.3.11.
Mako template library versions prior to 1.3.11 contain a path traversal vulnerability in TemplateLookup.get_template() that allows attackers to read arbitrary files accessible to the application process. The vulnerability is triggered when URIs starting with // are processed, exploiting inconsistent slash-stripping logic. This could lead to exposure of sensitive configuration files, credentials, and source code in applications using untrusted input with Mako templates.
Immediate Actions:
1. Identify all applications using Mako template library by scanning requirements.txt, setup.py, and dependency manifests
2. Determine current Mako version in production environments
3. Implement input validation: sanitize all user-supplied input before passing to TemplateLookup.get_template(), rejecting URIs containing '//' patterns
4. Apply principle of least privilege: restrict file system permissions for application processes to only necessary directories
Patching Guidance:
1. Upgrade Mako to version 1.3.11 or later when available
2. For immediate deployment, apply vendor patches as released
3. Test thoroughly in staging environment before production deployment
Compensating Controls (if patching delayed):
1. Implement Web Application Firewall (WAF) rules to block requests with '//' in template URI parameters
2. Use chroot/containerization to restrict file system access
3. Monitor application logs for suspicious template requests containing path traversal patterns
4. Implement file integrity monitoring on sensitive configuration files
Detection Rules:
1. Monitor TemplateLookup.get_template() calls with URIs containing '//' or '../' sequences
2. Alert on file access attempts outside designated template directories
3. Log and alert on any template rendering of non-template files (e.g., .conf, .env, .key files)
الإجراءات الفورية:
1. تحديد جميع التطبيقات التي تستخدم مكتبة Mako من خلال مسح requirements.txt و setup.py وملفات التبعيات
2. تحديد إصدار Mako الحالي في بيئات الإنتاج
3. تطبيق التحقق من المدخلات: تنظيف جميع المدخلات المزودة من قبل المستخدم قبل تمريرها إلى TemplateLookup.get_template()، ورفض عناوين URI التي تحتوي على أنماط '//'
4. تطبيق مبدأ أقل صلاحية: تقييد أذونات نظام الملفات لعمليات التطبيق على الدلائل الضرورية فقط
إرشادات التصحيح:
1. ترقية Mako إلى الإصدار 1.3.11 أو أحدث عند توفره
2. للنشر الفوري، تطبيق تصحيحات البائع عند إصدارها
3. الاختبار الشامل في بيئة التجريب قبل نشر الإنتاج
الضوابط البديلة (إذا تأخر التصحيح):
1. تطبيق قواعد جدار حماية تطبيقات الويب (WAF) لحجب الطلبات التي تحتوي على '//' في معاملات URI للقالب
2. استخدام chroot/containerization لتقييد الوصول إلى نظام الملفات
3. مراقبة سجلات التطبيق للطلبات المريبة للقالب التي تحتوي على أنماط اجتياز المسار
4. تطبيق مراقبة سلامة الملفات على ملفات التكوين الحساسة
قواعد الكشف:
1. مراقبة استدعاءات TemplateLookup.get_template() مع عناوين URI تحتوي على '//' أو '../' sequences
2. تنبيه محاولات الوصول إلى الملفات خارج دلائل القالب المعينة
3. تسجيل والتنبيه على أي عرض قالب لملفات غير قالب (مثل .conf و .env و .key files)