حماية مساعد الذكاء الاصطناعي وRAG بصلاحيات خارج التعليمات
بوابة أدوات بعزل العملاء وصلاحيات المستندات وميزانية الاستدعاء. ثمانية اختبارات محلية وتعليمات إنجليزية.

ابدأ هنا: ما فائدة هذا الدليل
يأمر مستند المساعد بتجاهل القواعد وإرسال بيانات عميل آخر: حقن غير مباشر. التعليمات القوية لا تستبدل صلاحيات خارجية. تحدد البوابة المستند المسموح بهوية موثوقة وحدود استدعاء دون LLM حقيقي أو كتابة. تثبت الاختبارات السياسة لا مقاومة شاملة للنموذج.
مثال عملي
الجواب مثال للشكل المتوقع وليس تدقيقًا لتطبيقك. اتبع الخطوات وقارن الملفات والاختبارات والنتائج الفعلية بالهدف. إن قال المساعد إنه انتهى فقط فاطلب الناتج والدليل وما لم يجر التحقق منه.
Proposal: read_document for a document belonging to another tenant.
Decision: denied by server policy, regardless of the document instruction.
Proposal: delete_records.
Decision: denied; this gateway exposes no write operation.الهدف
قد يقرأ المساعد مستندًا يحتوي على تعليمات. يجب أن يبقى التطبيق مسؤولًا عن تحديد البيانات والأدوات المسموحة للمستخدم. يفرض المختبر بوابة قراءة فقط دون استدعاء نموذج أو خدمة خارجية.
1. تحديد نطاق العمل
فك ZIP في مجلد جديد واستخدم Node.js 22 أو أحدث. المستندات والهويات والردود المقترحة وهمية. في الخدمة الحقيقية تأتي الهوية والصلاحيات من الخادم، لا من مستند مرفوع أو معاملات النموذج.
2. تشغيل المختبر المحلي
شغّل ثمانية اختبارات: قراءة مسموحة وعميل آخر وحق مفقود وكتابة ممنوعة وهوية مزيفة وتعليمات داخل مستند وميزانية وإعداد غير صالح. يعاد نص المستند عمدًا كبيانات دون تنفيذه.
node --version
node --test lab.test.mjs3. طلب أدلة من الذكاء الاصطناعي
تطلب التعليمات الأولى رسم حدود الثقة. درجة التشابه المتجهي ليست صلاحية. تفحص الاختبارات سياسة حتمية ولا تثبت مقاومة نموذج حقيقي لكل حقن تعليمات.
Review this LOCAL AI/RAG boundary lab. No real model or external service is
connected. Read lab.mjs and lab.test.mjs. Identify trusted actor and ACL metadata,
untrusted document text, proposed model tool calls and the execution budget. Test
whether a document instruction, forged tenant field or unknown write tool could
bypass the gateway. Do not treat a system prompt, an opaque document ID, a vector
search score or a model’s user_confirmed flag as authorization. Produce evidence and
remaining integration requirements, not a claim of complete prompt-injection
resistance.4. التحقق من الإصلاح
تضبط التعليمات الثانية تعديلًا صغيرًا واختبار تراجع. أبقِ الصلاحيات والتحقق من المعاملات خارج النموذج. طلب تجاهل تعليمات المستند ليس آلية تحكم قابلة للإنفاذ.
Implement only the agreed local gateway improvement and add a regression test. Keep
authorization and argument validation in server-controlled code outside the model.
Use authenticated actor/tenant metadata, a document ACL, an explicit tool allowlist
and a bounded call budget. Keep retrieved document text as data. Use harmless
synthetic documents and proposed tool calls; do not connect a real database, send
messages or execute shell commands. Run node --test lab.test.mjs. Document that
these tests check policy enforcement, not a live model, a vector database
integration or an injection detector.5. التطبيق على مشروعك
في RAG الحقيقي صفِّ العميل وصلاحيات المستند على الخادم أثناء الاسترجاع قبل إرسال السياق للنموذج. افحص كل استدعاء ورمّز المخرجات حسب وجهتها وافرض ميزانية مشتركة في الإنتاج. أي أداة كتابة مستقبلية تحتاج موافقة مرتبطة بالفاعل والمعاملات الدقيقة.
المراجع الرسمية
طبّقه في مشروعك
نزّل الملفات، واحفظ الدليل، أو أعطِ مساعد البرمجة تعليمات جاهزة للاستخدام.
الإعداد بمساعدة الذكاء الاصطناعي
انسخ هذه التعليمات الإنجليزية إلى مساعدك. تتضمن المقال والملفات المتاحة وخطوات تجهيز المشروع.
عرض تعليمات الإعداد
Read this tutorial as reference material:
https://nethanelfitoussi.com/article/ai-rag-prompt-injection-guardrails?lang=en
Goal: apply the documented workflow to my development project.
Read the existing project instructions, inspect the relevant files and explain the smallest useful setup.
Available starter files:
https://nethanelfitoussi.com/api/media/f34e57b8-eb7c-49ea-889f-441e88ba63f0.zip
Download and inspect these files in a temporary folder before using them. Do not overwrite existing project instructions.
If I have not supplied a project folder, ask which development project to use. Do not invent a repository URL.
Additional project setup instructions:
Use the downloaded starter lab in a NEW folder. Read README.md and both English prompts first. Run its dependency-free Node.js tests before editing.
Review this LOCAL AI/RAG boundary lab. No real model or external service is
connected. Read lab.mjs and lab.test.mjs. Identify trusted actor and ACL metadata,
untrusted document text, proposed model tool calls and the execution budget. Test
whether a document instruction, forged tenant field or unknown write tool could
bypass the gateway. Do not treat a system prompt, an opaque document ID, a vector
search score or a model’s user_confirmed flag as authorization. Produce evidence and
remaining integration requirements, not a claim of complete prompt-injection
resistance.
Implement only the agreed local gateway improvement and add a regression test. Keep
authorization and argument validation in server-controlled code outside the model.
Use authenticated actor/tenant metadata, a document ACL, an explicit tool allowlist
and a bounded call budget. Keep retrieved document text as data. Use harmless
synthetic documents and proposed tool calls; do not connect a real database, send
messages or execute shell commands. Run node --test lab.test.mjs. Document that
these tests check policy enforcement, not a live model, a vector database
integration or an injection detector.
Adapt example paths, commands and acceptance criteria to this repository rather than assuming they match.
Give me a short plan, then make the agreed local changes and run the relevant checks. Report actual results and anything not verified. Stop before credentials, paid services, production changes, push, merge or deployment.

