تخطَّ إلى المحتوى

🔐 شرح أمن API وقواعد البيانات

معيار OWASP ASVS

الدرس 21 من 25· ⏱ 6 دقائق قراءة

ما هو OWASP ASVS؟

ASVS (Application Security Verification Standard) هو معيار من OWASP يحدد متطلبات أمان التطبيقات ومستويات الضمان المختلفة. يساعد الفرق على بناء تطبيقات آمنة وتقييم مستوى الأمان الحالي.

ASVS ليس مجرد قائمة فحص - إنه إطار عمل متكامل للأمان التطبيقي:
  - V1: Architecture (المعمارية)
  - V2: Authentication (المصادقة)
  - V3: Session Management (إدارة الجلسات)
  - V4: Access Control (التحكم في الوصول)
  - V5: Input Validation (التحقق من المدخلات)
  - V6: Cryptography (التشفير)
  - V7: Logging (التسجيل)
  - V8: Data Protection (حماية البيانات)
  - V9: Communications (الاتصالات)
  - V10: Malicious Code (الكود الخبيث)
  - V11: Business Logic (منطق الأعمال)
  - V12: Files & Resources (الملفات)
  - V13: API & Web Service (واجهات API)
  - V14: Configuration (الإعدادات)

مستويات الضمان

المستوىالوصفلمن؟
L1أساسي (Automated)كل التطبيقات - ثغرات يمكن اكتشافها تلقائياً
L2قياسي (Manual)تطبيقات تتعامل مع بيانات حساسة - يحتاج مراجعة يدوية
L3متقدم (In-Depth)تطبيقات عالية الخطورة (بنوك، صحة، أمن وطني)

المستوى 1 (L1) - أساسي

// متطلبات أساسية - L1
{
  "V2_Authentication": {
    "2.1.1": "تأكد أن forms المصادقة تستخدم HTTPS فقط",
    "2.1.2": "تأكد من وجود قوة كلمة مرور (8 أحرف + حرف + رقم)",
    "2.2.1": "تأكد من عدم وجود كلمات مرور افتراضية",
    "2.5.1": "تأكد من وجود Rate Limiting على تسجيل الدخول"
  },
  "V5_Input_Validation": {
    "5.1.1": "تأكد من validation لكل المدخلات",
    "5.3.1": "تأكد من استخدام parameterized queries",
    "5.5.1": "تأكد من ترميز المخرجات (output encoding)"
  }
}

المستوى 2 (L2) - قياسي

// متطلبات إضافية - L2 (كل L1 + L2)
{
  "V2_Authentication": {
    "2.3.1": "تأكد من تفعيل MFA للحسابات الحساسة",
    "2.4.1": "تأكد من تخزين كلمات المرور بشكل آمن (bcrypt, argon2)",
    "2.7.1": "تأكد من وجود session timeout"
  },
  "V3_Session_Management": {
    "3.1.1": "تأكد من توليد session IDs عشوائياً",
    "3.3.1": "تأكد من إبطال الجلسة بعد logout",
    "3.4.1": "تأكد من استخدام HttpOnly و Secure cookies"
  },
  "V13_API_Web": {
    "13.1.1": "تأكد من مصادقة كل API endpoints",
    "13.2.1": "تأكد من التحقق من الصلاحية لكل كائن (BOLA)",
    "13.3.1": "تأكد من تطبيق Rate Limiting على API"
  }
}

المستوى 3 (L3) - متقدم

// متطلبات متقدمة - L3 (كل L1 + L2 + L3)
{
  "V2_Authentication": {
    "2.2.2": "تأكد من عدم وجود حسابات مشتركة",
    "2.7.2": "تأكد من إبطال session عند تغيير كلمة المرور",
    "2.8.1": "تأكد من تسجيل كل محاولات المصادقة"
  },
  "V1_Architecture": {
    "1.1.1": "تأكد من وجود threat model للتطبيق",
    "1.4.1": "تأكد من استخدام trusted execution environment",
    "1.8.1": "تأكد من وجود incident response plan"
  },
  "V10_Malicious_Code": {
    "10.1.1": "تأكد من عدم وجود backdoors أو dead code",
    "10.2.1": "تأكد من فحص التبعيات عن ثغرات",
    "10.3.1": "تأكد من توقيع الكود"
  }
}

تطبيق ASVS في التطوير

مرحلة التخطيط

// اختيار المستوى المناسب
function determineAsvsLevel(application) {
  const { dataType, users, impact } = application;

  if (impact === 'critical') return 'L3'; // بنوك، صحة
  if (dataType.includes('personal') || users > 100000) return 'L2';
  return 'L1'; // مواقع بسيطة
}

// متطلبات ASVS في ملف Requirements
const asvsRequirements = {
  L1: ['V2-1', 'V5-1', 'V6-1', 'V8-1', 'V14-1'],
  L2: ['L1', 'V2-2', 'V3-1', 'V4-1', 'V7-1', 'V9-1', 'V13-1'],
  L3: ['L2', 'V1-1', 'V10-1', 'V11-1', 'V12-1'],
};

مرحلة التطوير

// استخدام ASVS في PR Review
module.exports = {
  rules: {
    'require-auth': {
      meta: { severity: 'error' },
      create(context) {
        return {
          MethodDefinition(node) {
            // ASVS 13.1.1: تأكد من وجود middleware auth على API
            if (isAPIRoute(node)) {
              const hasAuth = node.value.body.body.some(
                stmt => isAuthMiddleware(stmt)
              );
              if (!hasAuth) {
                context.report({
                  node,
                  message: 'ASVS 13.1.1: API endpoint بدون مصادقة',
                });
              }
            }
          },
        };
      },
    },
  },
};

مرحلة الاختبار

// اختبار ASVS تلقائي
const asvsTests = {
  'V2.1.1': {
    name: 'HTTPS فقط للمصادقة',
    test: async (url) => {
      const res = await fetch(url.replace('http://', 'https://'));
      return res.ok;
    },
    severity: 'critical',
  },
  'V5.3.1': {
    name: 'Parameterized Queries',
    test: async (url) => {
      // SQLi test
      const res = await fetch(`${url}?id=1' OR '1'='1`);
      return res.status === 400 || res.status === 500;
    },
    severity: 'critical',
  },
  'V13.2.1': {
    name: 'BOLA Protection',
    test: async (baseUrl, token) => {
      // اختبار IDOR
      const res1 = await fetch(`${baseUrl}/api/users/1`, {
        headers: { Authorization: `Bearer ${token}` },
      });
      const res2 = await fetch(`${baseUrl}/api/users/999`, {
        headers: { Authorization: `Bearer ${token}` },
      });
      return res1.status !== res2.status;
    },
    severity: 'high',
  },
};

ASVS و OWASP Top 10

OWASP Top 10 2021ASVS Sections ذات الصلة
A01: Broken Access ControlV4 (Access Control), V13.2
A02: Cryptographic FailuresV6 (Cryptography), V8 (Data Protection)
A03: InjectionV5 (Input Validation)
A04: Insecure DesignV1 (Architecture)
A05: Security MisconfigurationV14 (Configuration)
A06: Vulnerable ComponentsV10 (Malicious Code)
A07: Auth FailuresV2 (Authentication), V3 (Session)
A08: Data IntegrityV8 (Data Protection)
A09: Logging FailuresV7 (Logging)
A10: SSRFV5 (Validation), V11 (Business Logic)

أدوات ASVS

# ASVS تلقائي باستخدام OWASP ASVS Gateway
git clone https://github.com/OWASP/ASVS
cd ASVS/tools/asvs-gateway
npm install
node asvs-check.js --level L2 --config config.json

# تحويل ASVS لمتطلبات Jira
node tools/export-to-jira.js --level L2 --format csv
// أداة ASVS بسيطة
const asvs = require('./asvs-4.0.json');

function generateChecklist(level = 'L1') {
  const requirements = [];

  for (const [section, items] of Object.entries(asvs)) {
    for (const [id, req] of Object.entries(items)) {
      if (req.levels.includes(level)) {
        requirements.push({
          id,
          title: req.title,
          description: req.description,
          section: req.section,
          level,
        });
      }
    }
  }

  return requirements;
}

شهادة ASVS

للحصول على شهادة ASVS:
  1. حدد مستوى الضمان (L1, L2, L3)
  2. قيم تطبيقك حسب المتطلبات
  3. وثق النتائج والأدلة
  4. راجع مع خبراء (اختياري)
  5. انشر التقرير (اختياري)

مستويات الشهادة:
  ✅ ASVS Level 1 Verified
  ✅✅ ASVS Level 2 Verified
  ✅✅✅ ASVS Level 3 Verified

⚠️ ASVS ليس مشروعاً لمرة واحدة - إنه عملية مستمرة. كل تحديث أو ميزة جديدة في تطبيقك قد تؤثر على مستوى الامتثال لـ ASVS.

🎯 التالي: الخصوصية والتوافقية (GDPR)

شرح معيار OWASP ASVS — أمن API وقواعد البيانات بالعربي
معيار OWASP ASVSأمن API وقواعد البيانات بالعربي · The Code Fix

هل كان هذا الدرس مفيدًا؟