Skip to content

Add beginner examples safe t1106#121

Open
geekysatbir wants to merge 4 commits intosafe-agentic-framework:mainfrom
geekysatbir:add-beginner-examples-safe-t1106
Open

Add beginner examples safe t1106#121
geekysatbir wants to merge 4 commits intosafe-agentic-framework:mainfrom
geekysatbir:add-beginner-examples-safe-t1106

Conversation

@geekysatbir
Copy link
Contributor

@geekysatbir geekysatbir commented Nov 15, 2025

Summary

This PR adds a comprehensive Beginner-Friendly Examples section to SAFE-T1106 (Autonomous Loop Exploit), providing practical, runnable Python code examples that help developers and security practitioners understand how autonomous loops work and how to detect and prevent them in MCP environments.

What's Added

Key Features:

  • Example 1: Simple Loop Detection - Python LoopDetector class that tracks repeated identical tool calls within a time window

    • Demonstrates call history tracking using hash-based identification
    • Configurable repeat thresholds and time windows
    • Returns loop detection alerts with session and tool information
  • Example 2: Basic Loop Prevention - SafeAgentExecutor class with iteration limits and convergence checks

    • Implements maximum iteration caps to prevent infinite loops
    • Convergence detection to identify when progress stalls
    • Automatic termination when limits are exceeded
  • Example 3: Log Pattern Analysis - Function to analyze logs for loop indicators

    • Regex-based pattern matching for identifying loop patterns
    • Extracts loop metrics (iteration count, duration, tool names)
    • Provides actionable insights for security teams

Technical Highlights:

  • Production-Ready Code: All examples are complete, runnable Python code that can be adapted for real-world use
  • Educational Value: Helps beginners understand the mechanics of autonomous loop exploits through hands-on examples
  • Practical Implementation: Demonstrates actual detection and prevention strategies that can be integrated into MCP agent frameworks
  • Clear Documentation: Each example includes detailed comments explaining the logic and purpose

Value Proposition:

This enhancement makes SAFE-T1106 more accessible to developers new to MCP security, providing concrete examples that bridge the gap between theoretical attack descriptions and practical implementation. The code examples serve as both educational tools and starting points for implementing loop detection and prevention in production MCP environments.

Type of Contribution

  • Documentation improvement
  • Update to existing content

Testing

  • All Python code examples validated for syntax correctness
  • Examples tested for logical correctness and clarity
  • Code follows Python best practices with proper type hints and documentation
  • MD5 usage documented with security note (non-cryptographic purpose)

Related Techniques

This enhancement complements the existing SAFE-T1106 documentation and helps practitioners understand:

  • How autonomous loops are triggered (SAFE-T1102: Prompt Injection)
  • How loops can be detected and prevented in practice
  • The relationship between loop exploits and resource exhaustion (SAFE-T2102: Service Disruption)

Impact

  • Accessibility: Makes complex security concepts more approachable for beginners
  • Practicality: Provides actionable code that can be immediately used or adapted
  • Education: Enhances understanding of autonomous loop attack vectors and defenses
  • Implementation: Serves as a reference for developers building MCP agent security controls

Satbir Singh and others added 4 commits November 15, 2025 11:27
Added practical Python code examples demonstrating:
- Simple loop detection using call history tracking
- Basic loop prevention with iteration limits and convergence checks
- Log pattern analysis for identifying loop indicators

This addition helps beginners understand autonomous loop exploits
through hands-on, runnable code examples.

Signed-off-by: Satbir Singh <satbisin@cisco.com>
Signed-off-by: Satbir Singh <satbisin@cisco.com>
Signed-off-by: Satbir Singh <satbisin@cisco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant