Human-in-the-Loop Security
aixa.js classifies every tool as either SAFE or HIGH_RISK.
For HIGH_RISK tools, agents cannot proceed without human approval.
This is not a suggestion — it is enforced at the framework level. No tool call tagged
HIGH_RISK will ever execute until a human explicitly clicks Approve.
How Risk Is Classified
The inference engine automatically detects risk by analyzing DOM elements. Here's how:
| Detection Method | Risk Level |
|---|---|
Auto-inference from form[action*="cart"] |
HIGH_RISK |
Auto-inference from button[type="submit"] |
HIGH_RISK |
data-aixa-confirm attribute present |
HIGH_RISK |
| Everything else | SAFE |
You can explicitly mark any element as high-risk by adding a data-aixa-confirm
attribute. The inference engine will respect it regardless of the element type.
The HITL Modal
When a HIGH_RISK tool is invoked, a modal intercepts execution with this lifecycle:
- Agent invokes HIGH_RISK tool — the tool call is intercepted before execution.
- Page freezes — all background interaction is blocked. No other actions can run.
-
Modal appears at
z-index: 2147483647— showing the tool name, parameters, and risk level. Nothing can render above it. - Human clicks Approve or Deny — the decision is final and immediate.
- If approved, the action proceeds normally. If denied, the agent receives an error and the action is discarded.
- Everything is logged — full audit trail: tool name, parameters, timestamp, and the human's decision.
What Agents See
When a human denies a HIGH_RISK tool call, the agent receives a JSON-RPC error
response. This is the standard error shape:
{
"jsonrpc": "2.0",
"id": "request-id-here",
"error": {
"code": -32000,
"message": "Human approval required"
}
}
The agent can handle this gracefully — retrying with different parameters, asking the human for clarification, or proceeding with an alternative SAFE tool.
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
hitlEnabled |
boolean |
true |
Enable Human-in-the-Loop for HIGH_RISK tools |
hitlTimeout |
number |
30000 |
HITL modal timeout in milliseconds |
hitlRiskLevels |
RiskLevel[] |
[HIGH_RISK] |
Which risk levels trigger the HITL modal |
Prompt Injection Protection
The sanitizePayload() function provides defense-in-depth against prompt injection
attacks. It detects and neutralizes:
- Patterns like
"IGNORE PREVIOUS INSTRUCTIONS"and similar override attempts - Token smuggling — hidden control characters and escape sequences
- HTML tags embedded in payloads (
<script>,<img>, etc.) - Recursive sanitization of nested objects and arrays — every level is checked
Sanitization runs before any payload reaches the agent, ensuring that malicious inputs are neutralized at the boundary.
Risk Policies
aixa.js supports three risk policy modes to match your security posture:
| Policy | Behavior |
|---|---|
| Permissive | Allow all SAFE tools. HITL only for explicit HIGH_RISK. |
| Strict | Unknown capabilities are blocked. Even LOW_RISK tools trigger HITL. |
| Lockdown | Block everything. No tool executes without manual approval. |