Target Audience: Automation Engineers, Ops Managers, No-Code Builders. Goal: Secure your AI workflows against injection and cost overruns without writing complex code.
Never connect a User Input directly to an LLM Node. You must “sandwich” the AI between security layers.
[ Trigger ] -> [ 🛡️ Security Filter ] -> [ 🤖 AI Agent ] -> [ 🔍 Output Validator ] -> [ Response ]
Make.com does not allow custom Python scripts easily, so we use native modules to enforce security.
Goal: Stop “Ignore Previous Instructions” attacks before they cost you money.
Text Parser or Router module immediately after your Trigger.Security CheckLength(User_Message) < 2000 (Prevents Token Overload)User_Message Does not contain (Case Insensitive) system:User_Message Does not contain (Case Insensitive) ignore previous{"error": "Security Policy Violation"}.Goal: Stop the scenario if the AI hangs or errors out.
Break directive.
35 secondsn8n is more powerful because it allows JavaScript execution. We will use a Code Node to act as a firewall.
Insert a Code Node before your AI Model node. Paste this script to sanitize inputs.
// AI SAFE2 - Input Security Validator
// ----------------------------------
const input = items[0].json.body.message || ""; // Adjust based on your webhook structure
// 1. DOS Protection (Length Check)
const MAX_LENGTH = 2000;
if (input.length > MAX_LENGTH) {
throw new Error(`Security Violation: Input exceeds ${MAX_LENGTH} characters.`);
}
// 2. Prompt Injection Blocklist
const blockedPatterns = [
'system:',
'ignore previous',
'<script',
'drop table'
];
if (blockedPatterns.some(word => input.toLowerCase().includes(word))) {
// Fail Closed: Stop execution immediately
throw new Error('Security Violation: Malicious pattern detected.');
}
// 3. PII Redaction (Basic Example)
// Replace email addresses with [REDACTED]
const cleanInput = input.replace(/[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/g, "[REDACTED_EMAIL]");
return [{json: { safe_message: cleanInput }}];
Don’t rely on n8n execution history (it gets deleted). Create a permanent audit trail.
Google Sheets or Postgres node after every AI interaction.Timestamp (ISO format)User_ID (if available)Input_Snippet (First 50 chars)Token_Usage (From AI Node Output)Status (Success/Fail)