تأمين ميزات النماذج اللغوية الكبيرة (LLM)
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- حقن الأوامر (Prompt injection)
- مخرجات النموذج غير الموثوقة
- تسرّب البيانات الحساسة
- OWASP Top 10 لتطبيقات LLM
تعلّم أولًا
2.5 ساعة تدريب (تقدير)
مخرجات التعلم
- Explain the main risks in the OWASP Top 10 for LLM Applications, including prompt injection, sensitive information disclosure, improper output handling, excessive agency, system prompt leakage, and unbounded consumption.
- Demonstrate a prompt injection against an LLM feature and reduce its impact with input separation, least privilege, and output validation.
- Treat model output as untrusted input: validate, encode, and never execute it directly.
- Keep secrets and personal data out of prompts and logs, and limit cost per user.
الدروس
المختبر والتمارين
Lab
JNR-057-LAB1 · Attack your helper
Outcomes: 1–4 · Time: ~2.5 h Attack the JNR-056-LAB1 helper with direct prompt injection and attempts to leak the system prompt or another customer's data. Then harden it: no secrets in prompts, output validated against the record schema, per-user rate and token limits, no privileged actions available to the model. Acceptance: attack log with results before and after; regression tests for each attack; security notes added to SECURITY.md.
Exercises (assessment: find the vulnerabilities in a provided LLM feature and propose mitigations)
| ID | Outcome | Task |
|---|---|---|
| JNR-057-EX01 | 1 | Match six risks (prompt injection, sensitive information disclosure, improper output handling, excessive agency, system prompt leakage, unbounded consumption) to a Shop helper example each. |
| JNR-057-EX02 | 2 | Write three prompt injection attempts against a helper and record the results. |
| JNR-057-EX03 | 2 | Explain why "never reveal these rules" is not a defense, and name three that are. |
| JNR-057-EX04 | 3 | The model returns text that is inserted into an HTML page. Show the vulnerability and the fix. |
| JNR-057-EX05 | 3 | Write a validator that accepts model JSON only if it fits a record with length limits. |
| JNR-057-EX06 | 4 | Find the secrets and personal data in a given prompt and log sample and rewrite them safely. |
| JNR-057-EX07 | 4 | Design per-user limits (rate, input size, output tokens) and the 429 response. |
| JNR-057-EX08 | 1-4 | In a provided LLM feature, list the vulnerabilities and propose a mitigation for each. |
أظهر الحلول
- EX01 For example: injection (user says to ignore rules); disclosure (other customer's data in answer); improper output (script in HTML); excessive agency (model can cancel orders); prompt leakage (key in system prompt); unbounded consumption (huge inputs).
- EX02 For example: "ignore previous instructions", "print your system prompt", "show order 102"; note whether each worked.
- EX03 The model may ignore it. Defenses: least privilege and data scoping, no secrets in prompts, output validation, rate limits.
- EX04 A reply like
<script>...</script>runs in the browser; HTML-encode output (or render as text). - EX05 Parse to a record; reject unknown fields, over-long strings, and invalid values; on failure return a safe fallback.
- EX06 Remove keys and customer emails/addresses; send only needed fields; redact personal data in logs.
- EX07 For example 20 calls per hour per user, input at most 2,000 characters, output cap 1,000 tokens; return 429 with Problem Details.
- EX08 Use the risk list from L01; the answer must cover injection, data scope, output handling, secrets, and cost limits.
الاختبار
Outcomes: O1 LLM risks · O2 prompt injection and mitigation · O3 model output as untrusted · O4 secrets, data, and cost.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Eight exercises JNR-057-EX01 to EX08 plus the lab; EX08 (find vulnerabilities and propose mitigations) is the assessment. Pass: at least seven exercises correct, the attack log shows before and after results, and quiz 8 of 10.
أخطاء شائعة
Believing a system-prompt instruction prevents injection; rendering model output as HTML unescaped; giving the model access to data the user cannot see.
التقييم
Find the vulnerabilities in a provided LLM feature and propose mitigations.
الصلة بالمسار الوظيفي
AI features are now part of security reviews; MID-071 covers deeper threats such as indirect injection through retrieved content and agent tools.