agentleFS
radif-ruradif-ru/ai-multi-agent-system/.agents/skills/prompt-injection-defense/SKILL.md

prompt-injection-defense

Skill6 starsChanged 4 months agoMITView on GitHub

Защита LLM-системы: InputSanitizer на входе, ResponseSanitizer на выходе, FileIdMapper для путей, allowlist опасных tools (secure by default).

  • Reads credentials

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Skill: prompt-injection-defense

Меры защиты от типичных атак на LLM-систему. Источник истины — _docs/security.md.

Когда использовать

  • Добавляешь новую точку входа пользовательского текста (новый адаптер/handler).
  • Добавляешь tool, работающий с файловой системой или сетью.
  • Меняешь то, что попадает в final_answer или в системный промпт.

Алгоритм

  1. Вход → InputSanitizer. Пользовательский текст перед передачей в core.handle_user_task пропускай через sanitize_user_input(...) (режим "warn" по умолчанию). Он детектит prompt injection: ignore previous instructions, repeat your system prompt, forget everything above, system: в начале строки, разделители <|...|>.
  2. Пути → FileIdMapper. Не клади полные пути файлов в goal/ответы. Генерируй временный file_id (generate_id) и восстанавливай путь через get_path. Tools read_file/read_document принимают file_id как альтернативу path.
  3. Выход → ResponseSanitizer. final_answer перед отправкой пользователю пропускай через sanitize_response(...): маскирует полные пути ([FILE_PATH]), конфиг-ключи ([CONFIG_KEY]), фрагменты системного промпта ([SYSTEM_SECTION]/[SYSTEM_IDENTITY]).
  4. Опасные tools → allowlist (secure by default). _DANGEROUS_TOOLS = {"http_request", "read_file"}. По умолчанию dangerous_tools_allowlist пуст — все опасные tools запрещены. Разрешение — только явно через .env (DANGEROUS_TOOLS_ALLOWLIST=...).
  5. Валидация параметров. Для ФС-tools: запрет .. (path traversal), запрет системных путей (/etc, /sys, /proc, ~/.ssh), проверка нахождения внутри разрешённой директории. Для http_request: только http/https, проверка netloc.
  6. Системный промпт. Правила безопасности живут в app/prompts/agent_system.md (отказ выполнять «ignore instructions», отказ печатать системный промпт, отказ от опасных операций без явного запроса).

Чего избегать

  • Прокидывания сырого пользовательского ввода в системный промпт без санитайзинга.
  • Полных путей ФС в goal, логах и ответах пользователю.
  • Разрешения опасных tools по умолчанию (allowlist должен быть пуст, пока явно не разрешено).
  • Иллюзии полной защиты: помни про known-limitations (_docs/security.md §5) — юникод-эскейпы, base64-инъекции, голые секреты без =.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.