Protocol statem auth guard

From XuShuwenn/RedAct · View interactive version

Protocol statem auth guard is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Audit and fix protocol state machines so pre-auth messages cannot trigger privileged actions; add centralized authentication guards around message dispatch.

How to use this skill

Skill file

Secure Authentication Guarding in Protocol State Machines

Harden stateful protocol servers (e.g., SSH-like, RPC, or any gen_statem-style FSM) by ensuring connection-level messages that can open channels, execute commands, or alter session state are only processed after successful authentication.

When to Use

Activate this skill when:

Core Workflow

  1. Map the Ingress Path
  1. Identify the Gate
  1. Choose the Policy for Pre-Auth Messages
  1. Implement the Fix at the Choke Point

Example Erlang gen_statem pattern (abstracted):

```erlang

%% Positive guard: only process when authenticated/connected

handle_event(internal, {conn_msg, Msg}, StateName, Data) when CONNECTED(StateName) ->

%% proceed with existing logic

process_conn_msg(Msg, StateName, Data);

%% Negative guard: reject or postpone before authentication

handle_event(internal, {conn_msg, _Msg}, StateName, Data) when not CONNECTED(StateName) ->

%% Choose one policy:

%% (A) Disconnect with protocol error:

{Shutdown, Data1} = send_disconnect(protocol_error_reason(), "Conn msg before auth", StateName, Data),

{stop, Shutdown, Data1};

%% (B) Or postpone (if pipelining supported):

%% {keep_state_and_data, [postpone]};

```

Notes:

  1. Preserve Legitimate Flows
  1. Validate the Fix

Verification Checklist

Common Pitfalls and How to Avoid Them

Optional Script Usage

Use the included audit script to flag potentially unguarded handlers in Erlang sources.

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.