MCP Server Framework - v1.0.0
    Preparing search index...

    Class InjectionGuard

    Injection Guard class for preventing log injection attacks.

    Provides:

    • Newline escaping (CWE-117 mitigation)
    • Control character escaping
    • ANSI escape sequence stripping
    const guard = new InjectionGuard();
    const safe = guard.sanitize('User: admin\nLevel: root'); // "User: admin\\nLevel: root"
    Index

    Constructors

    Methods

    • Check if text contains ANSI escape sequences.

      Parameters

      • text: string

        The text to check

      Returns boolean

      true if the text contains ANSI sequences

    • Check if text contains potential injection characters.

      Parameters

      • text: string

        The text to check

      Returns boolean

      true if the text contains injection characters

    • Sanitize text to prevent log injection. Replaces newlines and control characters with escaped versions.

      Parameters

      • text: string

        The text to sanitize

      Returns string

      Sanitized text safe for logging