N8N Code Automation
⚠️ SECURITY CRITICAL UPDATE (v1.1.0)
This version addresses CRITICAL SECURITY VULNERABILITIES present in v1.0.0:
✅ Fixed Vulnerabilities
- 1. Credential Exposure - API keys no longer hardcoded or stored in config files
- Hardcoded URLs - Removed hardcoded
nelflow.cloud domain, now configurable - Input Validation - Added URL validation (HTTPS only) and data sanitization
- No Audit Logging - Complete audit trail with timestamps implemented
- No Rate Limiting - Configurable rate limits to prevent abuse
- No Permissions - Three-level permission system added (readonly, restricted, full)
- No Confirmation - Two-factor confirmation for dangerous operations
🔐 New Security Features
- - Credential Isolation: API keys stored ONLY in environment variables
- Input Validation: URL format validation + data sanitization
- Audit Logging: Complete action trail in INLINECODE1
- Rate Limiting: Configurable limits (10 req/min by default)
- Granular Permissions: 3 levels - readonly, restricted, full
- HTTPS Enforcement: Only HTTPS connections allowed
- Confirmation Required: Two-factor for dangerous operations
📋 Migration from v1.0.0
If you were using v1.0.0, please migrate:
- 1. Remove credentials from config:
CODEBLOCK0
- 2. Set environment variables:
CODEBLOCK1
- 3. Set permission mode (optional):
CODEBLOCK2
See SECURITY section below for complete migration guide.
Overview
Enable n8n workflow automation capabilities for coding tasks. Use n8n to build, manage, and execute automated workflows that integrate with your development processes, CI/CD pipelines, data processing, and API integrations.
Configuration
Connection Details
- - URL: Configurable via environment variable (REQUIRED)
- API Key: Available in n8n (Settings → API → API Key)
- Header: INLINECODE2
- Base Path: INLINECODE3
Authentication (SECURE - v1.1.0)
⚠️ IMPORTANT: API keys MUST be stored as environment variables, NEVER in config files.
Do NOT do this:
CODEBLOCK3
✅ CORRECT approach:
CODEBLOCK4
Permission Modes (NEW - v1.1.0)
The skill operates in three permission modes:
| Mode | Read | Execute | Create | Update | Delete | Risk Level |
|---|
| INLINECODE4 | ✅ | ✅ | ❌ | ❌ | ❌ | 🟢 LOW |
| INLINECODE5 |
✅ | ✅ | ✅
| ✅ | ❌ | 🟡 MEDIUM |
|
full | ✅ | ✅ | ✅ | ✅ | ✅* | 🔴 HIGH |
- * Requires explicit confirmation for each operation
Default mode: INLINECODE7
To change mode:
CODEBLOCK5
Available Actions
🟢 Read-Only Operations (Safe)
1. List Workflows
CODEBLOCK6
Response:
{
"data": [
{
"id": "abc123",
"name": "Example Workflow",
"nodes": [...],
"connections": {...},
"active": true,
"settings": {}
}
]
}
2. Get Workflow Status
curl -X GET "$N8N_URL/api/v1/workflows/abc123" \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json"
3. Get Executions
CODEBLOCK9
Filter options:
- -
?limit=10 - Limit results - INLINECODE9 - Start date
- INLINECODE10 - End date
- INLINECODE11 - Filter by status
4. Get Execution Details
CODEBLOCK10
🟡 Execute Operations (Requires Permission)
5. Execute Workflow (Manual)
Confirmation required: The skill will ask for approval before execution.
CODEBLOCK11
6. Execute Workflow (with Inputs)
curl -X POST "$N8N_URL/api/v1/workflows/{id}/executions" \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"data": {
"contextData": {
"input": {
"parameter1": "value1",
"parameter2": "value2"
}
}
}
}'
7. Execute Webhook
CODEBLOCK13
🔴 Dangerous Operations (Requires Explicit Confirmation)
⚠️ These operations require TWO confirmations:
- 1. Display of what will be changed
- Typing confirmation phrase
8. Clone Workflow
CODEBLOCK14
9. Update Workflow (PATCH)
CODEBLOCK15
10. Delete Workflow
CODEBLOCK16
Coding Use Cases
Use Case 1: CI/CD Integration
Scenario: Trigger build/test workflows from code commits.
CODEBLOCK17
Use Case 2: Data Processing Pipeline
Scenario: Process and transform data automatically.
Prompt:
"Design an n8n workflow that fetches new data from an API, validates it, transforms it, and sends it to a database. Use HTTP Request nodes for API calls, Function nodes for validation and transformation, and Database nodes for storage."
Use Case 3: Automated Testing
Scenario: Run test suites automatically and send results to Slack.
Prompt:
"Create an n8n workflow that runs a Python test suite, captures output, and sends results to a Slack channel. Include HTTP Request nodes to trigger tests and a Slack node to send formatted results."
Use Case 4: Scheduled Maintenance
Scenario: Execute periodic maintenance tasks.
Prompt:
"Set up an n8n workflow that runs every morning at 6 AM to:
- 1. Check database performance metrics
- Backup important files
- Send a summary to my email
Use Cron node for scheduling and Email nodes for notifications."
Use Case 5: API Integration
Scenario: Connect multiple services via automated workflows.
Prompt:
"Create an n8n workflow that:
- 1. Monitors a monitoring service (like Datadog or Prometheus)
- If an alert is triggered
- Notifies Slack and Telegram
- Creates a ticket in Jira/Trello
- Sends an email to team
Include Webhook nodes for monitoring, Slack and Telegram nodes for notifications, and a database node to track incidents."
Security (NEW - v1.1.0)
Input Validation (NEW)
CODEBLOCK18
Data Sanitization (NEW)
CODEBLOCK19
Audit Logging (NEW)
All actions are logged to:
CODEBLOCK20
Log format:
CODEBLOCK21
Rate Limiting (NEW)
Default limits (configurable):
| Operation | Limit | Window |
|---|
| API requests | 10 | per minute |
| Workflow executions |
5 | per minute |
| Bulk operations | 1 | per 5 minutes |
Best Practices
Security
- 1. Never hardcode API keys in code or workflows
- Use environment variables or secrets management
- Restrict workflow permissions in n8n settings
- Enable rate limiting to prevent abuse
- Use HTTPS only - enforce encrypted connections
Organization
- 1. Name workflows descriptively (e.g., "GitLab CI Trigger" vs "Workflow 1")
- Use consistent naming conventions across your organization
- Document workflow purposes in description field
- Create folder structure in n8n for better organization
Error Handling
- 1. Add error nodes to catch and handle failures
- Log execution results for debugging
- Set up notifications for failed executions
- Implement retry logic for transient failures
Testing
- 1. Test workflows manually before automation
- Use test data in development
- Monitor execution logs regularly
- Document expected behavior and success criteria
Common Workflows
Webhook to Database
CODEBLOCK22
Scheduled Data Sync
CODEBLOCK23
Troubleshooting
Authentication Error
Error: Unauthorized
Solution: Verify API key is correct and has necessary permissions
Workflow Not Found
Error: Workflow not found
Solution: Check workflow ID and ensure workflow exists
Execution Failed
Error: Execution failed
Solution: Check workflow execution logs for node-specific errors
Rate Limit Exceeded
Error: Rate limit exceeded
Solution: Wait and retry, or upgrade your plan
Input Validation Error
Error: Invalid URL - Must be HTTPS
Solution: Ensure N8N_URL starts with INLINECODE12
Quick Start
1. Set Environment Variables (REQUIRED):
CODEBLOCK29
2. Set Permission Mode (OPTIONAL):
CODEBLOCK30
3. List workflows:
CODEBLOCK31
4. Execute a workflow:
CODEBLOCK32
5. Start building:
- - Copy workflow examples
- Modify nodes for your needs
- Test thoroughly before automation
- Monitor and iterate
References
- - N8N Documentation: https://docs.n8n.io
- N8N API Reference: https://docs.n8n.io/api/
- N8N Webhooks: https://docs.n8n.io/workflows/webhooks/
- Community Workflows: https://community.n8n.io/
- Node Reference: https://docs.n8n.io/nodes/
Need help? Check N8N community forums or documentation at https://community.n8n.io/
Changelog
v1.1.0 - 2024-04-04 - CRITICAL SECURITY UPDATE
- - ✅ Fixed credential exposure (removed hardcoded API keys from examples)
- ✅ Removed hardcoded URLs (now configurable via environment variables)
- ✅ Added input validation (URL format + data sanitization)
- ✅ Implemented audit logging (complete action trail)
- ✅ Added rate limiting (configurable limits)
- ✅ Implemented granular permissions (3 levels: readonly, restricted, full)
- ✅ Added two-factor confirmation for dangerous operations
- ✅ Enforced HTTPS only
- ✅ Updated all documentation with security warnings
- ✅ Migration guide from v1.0.0
v1.0.0 - Initial release (INSECURE - DO NOT USE)
- - Original version with critical security vulnerabilities
- ⚠️ DEPRECATED - Please migrate to v1.1.0 or later
N8N 代码自动化
⚠️ 安全关键更新 (v1.1.0)
本版本修复了 v1.0.0 中存在的关键安全漏洞:
✅ 已修复的漏洞
- 1. 凭据泄露 - API 密钥不再硬编码或存储在配置文件中
- 硬编码 URL - 移除了硬编码的 nelflow.cloud 域名,现可配置
- 输入验证 - 添加了 URL 验证(仅 HTTPS)和数据清理
- 缺少审计日志 - 实现了带时间戳的完整审计追踪
- 缺少速率限制 - 可配置的速率限制以防止滥用
- 缺少权限控制 - 添加了三级权限系统(只读、受限、完全)
- 缺少确认机制 - 危险操作需要双重确认
🔐 新增安全功能
- - 凭据隔离: API 密钥仅存储在环境变量中
- 输入验证: URL 格式验证 + 数据清理
- 审计日志: 完整操作记录在 /data/.openclaw/logs/n8n-audit.log
- 速率限制: 可配置限制(默认每分钟 10 次请求)
- 细粒度权限: 3 个级别 - 只读、受限、完全
- HTTPS 强制: 仅允许 HTTPS 连接
- 确认要求: 危险操作需要双重确认
📋 从 v1.0.0 迁移
如果您正在使用 v1.0.0,请进行迁移:
- 1. 从配置中移除凭据:
bash
# 编辑 ~/.openclaw/openclaw.json
# 移除所有 N8N
URL 或 N8NAPI_KEY 条目
- 2. 设置环境变量:
bash
export N8N_URL=https://your-n8n-instance.com
export N8N
APIKEY=your-api-key
- 3. 设置权限模式(可选):
bash
export N8N
PERMISSIONMODE=readonly # 推荐用于生产环境
有关完整迁移指南,请参阅下面的安全部分。
概述
为编码任务启用 n8n 工作流自动化功能。使用 n8n 构建、管理和执行自动化工作流,与您的开发流程、CI/CD 管道、数据处理和 API 集成相结合。
配置
连接详情
- - URL: 通过环境变量配置(必需)
- API 密钥: 在 n8n 中获取(设置 → API → API 密钥)
- 请求头: X-N8N-API-KEY
- 基础路径: /api
身份验证(安全 - v1.1.0)
⚠️ 重要提示:API 密钥必须存储为环境变量,切勿存储在配置文件中。
不要这样做:
json
{
env: {
N8N_URL: https://n8n.example.com, // ❌ 不安全
N8NAPIKEY: your-api-key-here // ❌ 严重安全问题
}
}
✅ 正确做法:
bash
在系统级别设置,切勿在文件中设置
export N8N_URL=https://your-n8n.com
export N8N
APIKEY=your-api-key
权限模式(新增 - v1.1.0)
该技能在三种权限模式下运行:
| 模式 | 读取 | 执行 | 创建 | 更新 | 删除 | 风险等级 |
|---|
| readonly | ✅ | ✅ | ❌ | ❌ | ❌ | 🟢 低 |
| restricted |
✅ | ✅ | ✅
| ✅ | ❌ | 🟡 中 |
| full | ✅ | ✅ | ✅ | ✅ | ✅* | 🔴 高 |
默认模式: readonly
更改模式:
bash
export N8NPERMISSIONMODE=full # 危险 - 仅适用于受信任环境
可用操作
🟢 只读操作(安全)
1. 列出工作流
bash
curl -X GET $N8N_URL/api/v1/workflows \
-H X-N8N-API-KEY: $N8N
APIKEY \
-H Content-Type: application/json
响应:
json
{
data: [
{
id: abc123,
name: 示例工作流,
nodes: [...],
connections: {...},
active: true,
settings: {}
}
]
}
2. 获取工作流状态
bash
curl -X GET $N8N_URL/api/v1/workflows/abc123 \
-H X-N8N-API-KEY: $N8N
APIKEY \
-H Content-Type: application/json
3. 获取执行记录
bash
curl -X GET $N8N_URL/api/v1/workflows/abc123/executions \
-H X-N8N-API-KEY: $N8N
APIKEY
过滤选项:
- - ?limit=10 - 限制结果数量
- ?startDate=2024-01-01 - 开始日期
- ?endDate=2024-01-31 - 结束日期
- ?status=success - 按状态过滤
4. 获取执行详情
bash
curl -X GET $N8N_URL/api/v1/executions/xyz789 \
-H X-N8N-API-KEY: $N8N
APIKEY
🟡 执行操作(需要权限)
5. 执行工作流(手动)
需要确认: 技能将在执行前请求批准。
bash
步骤 1:查看工作流
curl -X GET $N8N_URL/api/v1/workflows/{id} \
-H X-N8N-API-KEY: $N8N
APIKEY
步骤 2:执行(需确认)
curl -X POST $N8N_URL/api/v1/workflows/{id}/executions \
-H X-N8N-API-KEY: $N8N
APIKEY \
-H Content-Type: application/json \
-d {data: {contextData: {}, manualExecution: true}}
6. 执行工作流(带输入)
bash
curl -X POST $N8N_URL/api/v1/workflows/{id}/executions \
-H X-N8N-API-KEY: $N8N
APIKEY \
-H Content-Type: application/json \
-d {
data: {
contextData: {
input: {
parameter1: value1,
parameter2: value2
}
}
}
}
7. 执行 Webhook
bash
curl -X POST https://your-n8n.com/webhook/your-webhook-key \
-H Content-Type: application/json \
-d {
data: {
input1: value1,
input2: value2
}
}
🔴 危险操作(需要明确确认)
⚠️ 这些操作需要双重确认:
- 1. 显示将要更改的内容
- 输入确认短语
8. 克隆工作流
bash
步骤 1:显示将要克隆的内容
curl -X GET $N8N_URL/api/v1/workflows/{source-id} \
-H X-N8N-API-KEY: $N8N
APIKEY
步骤 2:执行并确认
curl -X POST $N8N_URL/api/v1/workflows/{source-id}/clone \
-H X-N8N-API-KEY: $N8N
APIKEY \
-H Content-Type: application/json \
-d {name: 克隆的工作流}
9. 更新工作流(PATCH)
bash
步骤 1:显示当前状态
curl -X GET $N8N_URL/api/v1/workflows/{id} \
-H X-N8N-API-KEY: $N8N
APIKEY
步骤 2:显示差异
(显示将要更改的内容)
步骤 3:执行并确认
curl -X PATCH $N8N_URL/api/v1/workflows/{id} \
-H X-N8N-API-KEY: $N8N
APIKEY \
-