LangChain versions up to and including 0.3.1 contain a regular expression denial-of-service (ReDoS) vulnerability in the MRKLOutputParser.parse() method (libs/langchain/langchain/agents/mrkl/output_parser.py). The parser applies a backtracking-prone regular expression when extracting tool actions from model output. An attacker who can supply or influence the parsed text (for example via prompt injection in downstream applications that pass LLM output directly into MRKLOutputParser.parse()) can trigger excessive CPU consumption by providing a crafted payload, causing significant parsing delays and a denial-of-service condition.
CVE-2024-58340 is a Regular Expression Denial-of-Service (ReDoS) vulnerability in LangChain versions up to 0.3.1 affecting the MRKLOutputParser.parse() method. An attacker can exploit this through prompt injection to cause excessive CPU consumption and service disruption. This vulnerability is particularly critical for Saudi organizations deploying LLM-based applications in production environments, as it enables denial-of-service attacks with minimal technical barriers.
IMMEDIATE ACTIONS:
1. Identify all applications using LangChain versions ≤0.3.1 in your environment
2. Assess exposure: determine if user-controlled input can reach MRKLOutputParser.parse()
3. Implement input validation and sanitization before parser invocation
PATCHING GUIDANCE:
1. Upgrade LangChain to version 0.3.2 or later immediately
2. Test upgraded versions in staging environment before production deployment
3. Verify no breaking changes in your LLM agent implementations
COMPENSATING CONTROLS (if immediate patching not possible):
1. Implement request timeout mechanisms (set aggressive timeouts on parser operations)
2. Deploy rate limiting on LLM output processing endpoints
3. Add CPU/memory monitoring with automatic circuit breakers for parser operations
4. Implement prompt injection detection and filtering before LLM output reaches parser
5. Use Web Application Firewall (WAF) rules to detect ReDoS patterns in requests
DETECTION RULES:
1. Monitor for parser execution times exceeding 5 seconds
2. Alert on CPU spikes coinciding with LangChain parser operations
3. Log and analyze MRKLOutputParser.parse() inputs for suspicious regex patterns
4. Implement SIEM rules detecting repeated failed parsing attempts
5. Monitor for patterns like excessive backslashes, nested quantifiers in tool action outputs
الإجراءات الفورية:
1. حدد جميع التطبيقات التي تستخدم إصدارات LangChain ≤0.3.1 في بيئتك
2. قيّم التعرض: حدد ما إذا كان يمكن للمدخلات التي يتحكم بها المستخدم الوصول إلى MRKLOutputParser.parse()
3. طبّق التحقق من صحة المدخلات والتنظيف قبل استدعاء المحلل
إرشادات التصحيح:
1. قم بترقية LangChain إلى الإصدار 0.3.2 أو أحدث على الفور
2. اختبر الإصدارات المرقاة في بيئة التجريب قبل نشرها في الإنتاج
3. تحقق من عدم وجود تغييرات كسر في تطبيقات وكيل LLM الخاصة بك
الضوابط البديلة (إذا لم يكن التصحيح الفوري ممكناً):
1. طبّق آليات انتهاء المهلة الزمنية على عمليات المحلل
2. نشّر تحديد معدل على نقاط نهاية معالجة مخرجات LLM
3. أضف مراقبة CPU/الذاكرة مع قواطع دوائر تلقائية لعمليات المحلل
4. طبّق الكشف عن حقن الأوامر والتصفية قبل وصول مخرجات LLM إلى المحلل
5. استخدم قواعد جدار الحماية لتطبيقات الويب للكشف عن أنماط ReDoS
قواعد الكشف:
1. راقب أوقات تنفيذ المحلل التي تتجاوز 5 ثوان
2. تنبيهات على ارتفاعات CPU المتزامنة مع عمليات محلل LangChain
3. سجل وحلل مدخلات MRKLOutputParser.parse() بحثاً عن أنماط regex مريبة
4. طبّق قواعد SIEM للكشف عن محاولات التحليل الفاشلة المتكررة
5. راقب الأنماط مثل الشرطات المائلة المفرطة والمحددات المتداخلة في مخرجات الأدوات