DEV Community

🛡️ حل احترافي لثغرة Prototype Pollution في protobufjs

🛡️ حل ثغرة Prototype Pollution في protobufjs

درع زايد - مؤسسة الرئاسة | Zayed Shield - Presidential Office


📋 ملخص الثغرة | Vulnerability Summary

المعلومة Information التفاصيل Details
الحزمة Package protobufjs npm
النوع Type Prototype Pollution Critical
CVE CVE CVE-2023-36665 (differs from CVE-2022-25878)
الإصدارات المتأثرة Affected 6.10.0 - 6.11.3, 7.0.0 - 7.2.3
الإصدار الآمن Patched 6.11.4+, 7.2.5+
الخطورة Severity 🔴 High/Critical

⚠️ وصف الثغرة | Vulnerability Description

تسمح الثغرة للمهاجم بتلويث Object.prototype عبر رسالة protobuf خبيثة، مما يؤدي إلى:

  • تعديل سلوك التطبيق بالكامل
  • تنفيذ كود عشوائي (RCE)
  • تجاوز الحماية الأمنية
  • الوصول غير المصرح به للبيانات

طرق الاستغلال:

  1. استخدام parse() لتحليل رسائل protobuf
  2. تحميل ملفات .proto عبر load()/loadSync()
  3. إدخال بيانات غير موثوقة في setParsedOption() أو util.setProperty()

🔧 الحل السريع | Quick Fix

1️⃣ تحديث مباشر | Direct Update

# فحص الإصدار الحالي
pnpm list protobufjs

# تحديث إلى الإصدار الآمن
pnpm update protobufjs@^7.2.5

# أو إجباري
pnpm add protobufjs@latest
Enter fullscreen mode Exit fullscreen mode

2️⃣ تعديل package.json

{
  "dependencies": {
    "protobufjs": ">=7.2.5"
  },
  "overrides": {
    "protobufjs": ">=7.2.5"
  },
  "pnpm": {
    "overrides": {
      "protobufjs": ">=7.2.5"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

3️⃣ حل التبعية المتعدية | Transitive Dependency Fix

# تحديث firebase الذي يعتمد على protobufjs
pnpm update firebase@latest

# فرض الإصدار الآمن
pnpm add protobufjs@7.2.5 --save-exact
Enter fullscreen mode Exit fullscreen mode

🔒 الحل الشامل | Comprehensive Solution

خطوة 1: النسخ الاحتياطي

# نسخ احتياطي لملفات القفل
cp pnpm-lock.yaml pnpm-lock.yaml.backup
cp package.json package.json.backup
Enter fullscreen mode Exit fullscreen mode

خطوة 2: التنظيف

# حذف الحزم القديمة
rm -rf node_modules
rm pnpm-lock.yaml
Enter fullscreen mode Exit fullscreen mode

خطوة 3: التحديث

في package.json:

{
  "dependencies": {
    "firebase": "^10.7.1",
    "protobufjs": "^7.2.5"
  },
  "resolutions": {
    "protobufjs": "7.2.5"
  },
  "pnpm": {
    "overrides": {
      "protobufjs": "7.2.5"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

خطوة 4: إعادة التثبيت

# تثبيت نظيف
pnpm install

# التحقق من الثغرات
pnpm audit

# فحص شامل
pnpm audit --audit-level moderate
Enter fullscreen mode Exit fullscreen mode

✅ التحقق من الحل | Solution Verification

1️⃣ فحص الإصدار

# التحقق من protobufjs
pnpm list protobufjs

# يجب أن تكون النتيجة:
# protobufjs@7.2.5 ✓
Enter fullscreen mode Exit fullscreen mode

2️⃣ فحص الثغرات

# فحص أمني شامل
pnpm audit

# النتيجة المطلوبة:
# found 0 vulnerabilities ✓
Enter fullscreen mode Exit fullscreen mode

3️⃣ اختبار التطبيق

# تشغيل الاختبارات
pnpm test

# تشغيل التطبيق
pnpm start

# التحقق من عدم وجود أخطاء
Enter fullscreen mode Exit fullscreen mode

🧪 مراجعة الحل | Solution Review

✅ Checklist المراجعة

  • [ ] تم تحديث protobufjs إلى 7.2.5+
  • [ ] تم تحديث firebase إلى أحدث إصدار
  • [ ] تم تعديل package.json بـ overrides/resolutions
  • [ ] تم حذف node_modules وإعادة التثبيت
  • [ ] pnpm audit يُظهر 0 vulnerabilities
  • [ ] pnpm list protobufjs يُظهر النسخة الآمنة فقط
  • [ ] الاختبارات تعمل بنجاح
  • [ ] التطبيق يعمل بدون أخطاء
  • [ ] تم النسخ الاحتياطي للملفات
  • [ ] تم توثيق التغييرات في Git

📊 مراجعة ما بعد الحل | Post-Fix Review

المراجعة الفنية | Technical Review

# 1. التحقق من شجرة التبعيات
pnpm list --depth=5 | grep protobufjs

# يجب أن تظهر فقط النسخ الآمنة

# 2. فحص pnpm-lock.yaml
grep -A 5 "protobufjs" pnpm-lock.yaml

# تأكد من أن جميع الإصدارات ≥7.2.5

# 3. فحص متقدم
npx audit-ci --moderate
Enter fullscreen mode Exit fullscreen mode

اختبار الأمان | Security Testing

# استخدام Snyk للفحص
npx snyk test

# استخدام npm audit
npm audit --production

# فحص يدوي
pnpm outdated
Enter fullscreen mode Exit fullscreen mode

🔍 الفحص النهائي | Final Inspection

سكريبت فحص شامل

#!/bin/bash
echo "🛡️ درع زايد - فحص ثغرة protobufjs"
echo "================================"

# 1. فحص الإصدار
echo "1️⃣ فحص الإصدار..."
VERSION=$(pnpm list protobufjs --depth=0 2>/dev/null | grep protobufjs | awk '{print $2}')
if [[ "$VERSION" =~ ^7\.2\.[5-9]|7\.[3-9]|[8-9]\. ]]; then
    echo "✅ الإصدار آمن: $VERSION"
else
    echo "❌ الإصدار غير آمن: $VERSION"
    exit 1
fi

# 2. فحص التبعيات المتعدية
echo "2️⃣ فحص التبعيات المتعدية..."
TRANSITIVE=$(pnpm list protobufjs --depth=10 2>/dev/null | grep -c "6\.11\.[0-3]\|6\.10\|7\.[0-2]\.[0-4]")
if [ "$TRANSITIVE" -eq 0 ]; then
    echo "✅ لا توجد تبعيات متعدية غير آمنة"
else
    echo "⚠️ تحذير: توجد $TRANSITIVE تبعية متعدية تحتاج مراجعة"
fi

# 3. فحص الثغرات
echo "3️⃣ فحص الثغرات..."
VULNS=$(pnpm audit --json 2>/dev/null | grep -c "protobufjs")
if [ "$VULNS" -eq 0 ]; then
    echo "✅ لا توجد ثغرات في protobufjs"
else
    echo "❌ توجد ثغرات: $VULNS"
    exit 1
fi

echo "================================"
echo "✅ النظام آمن - اكتمل الفحص بنجاح"
Enter fullscreen mode Exit fullscreen mode

📝 التوثيق | Documentation

تقرير Git Commit

git add package.json pnpm-lock.yaml
git commit -m "🔒 Security: Fix protobufjs CVE-2023-36665 (Prototype Pollution)

- Updated protobufjs from 6.11.2 to 7.2.5
- Updated firebase to latest version
- Added pnpm overrides to force secure version
- Verified 0 vulnerabilities in audit

Refs: CVE-2023-36665, Dependabot Alert
Tested: ✅ All tests passing
Security: ✅ pnpm audit clean"
Enter fullscreen mode Exit fullscreen mode

تقرير مؤسسي

## تقرير الحل الأمني
**المشروع**: درع زايد
**التاريخ**: $(date +%Y-%m-%d)
**المسؤول**: asrar-mared

### الإجراءات المتخذة:
1. ✅ تحديث protobufjs إلى 7.2.5
2. ✅ فرض الإصدار الآمن عبر pnpm overrides
3. ✅ تحديث firebase إلى أحدث إصدار
4. ✅ إعادة تثبيت جميع التبعيات
5. ✅ فحص شامل (0 vulnerabilities)

### النتيجة: النظام آمن 🛡️
Enter fullscreen mode Exit fullscreen mode

🚀 الوقاية المستقبلية | Future Prevention

1️⃣ إعداد GitHub Dependabot

.github/dependabot.yml:

version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "daily"
    open-pull-requests-limit: 10
    reviewers:
      - "asrar-mared"
Enter fullscreen mode Exit fullscreen mode

2️⃣ إضافة فحص تلقائي

package.json:

{
  "scripts": {
    "preinstall": "npx npm-force-resolutions",
    "postinstall": "pnpm audit --audit-level moderate",
    "security-check": "pnpm audit && npx snyk test"
  }
}
Enter fullscreen mode Exit fullscreen mode

3️⃣ CI/CD Security Check

.github/workflows/security.yml:

name: Security Scan
on: [push, pull_request]
jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
      - run: pnpm install
      - run: pnpm audit
      - run: npx snyk test
Enter fullscreen mode Exit fullscreen mode

📞 جهات الاتصال | Contact

مؤسسة الرئاسة - مشروع درع زايد

Developer: asrar-mared

Email: nike49424@proton.me


🛡️ الختام

"نحمي... ندافع... ننتصر"

We Protect... We Defend... We Win

الثغرة تم حلها بنجاح

النظام آمن ومحمي

جاهز للإنتاج

Top comments (0)