graph TB
subgraph "外部系统"
A[GitHub]
B[GitLab]
C[CI/CD]
end
subgraph "dsh Webhook"
D[HTTP 端点]
E[签名验证]
F[规则匹配]
G[Session 创建]
end
subgraph "Agent"
H[Agent Loop]
I[工具执行]
end
A --> D
B --> D
C --> D
D --> E
E --> F
F --> G
G --> H
H --> I
# cordis.patch.yml-id: webhook
config:# 可信规则rules:-name:'github-push'match:source:'github'eventType:'push'action:agentPreset:'code-reviewer'systemPrompt:'Review the pushed changes'allowedTools:-'file_read'-'bash'-name:'github-issue'match:source:'github'eventType:'issues'action:agentPreset:'issue-handler'systemPrompt:'Handle the new issue'# 端点配置endpoint:port:3001path:'/webhook'# 签名密钥secrets:github:'${GITHUB_WEBHOOK_SECRET}'gitlab:'${GITLAB_WEBHOOK_SECRET}'
// 确保使用 timing-safe 比较functiontimingSafeEqual(a: Buffer, b: Buffer):boolean{if(a.length !== b.length)returnfalselet result =0for(let i =0; i < a.length; i++){
result |= a[i]^ b[i]}return result ===0}
16.6.2 速率限制
// 概念性描述classRateLimiter{private requests =newMap<string,number[]>()/** 检查速率限制 */check(source:string, limit:number, window:number):boolean{const now = Date.now()const timestamps =this.requests.get(source)??[]// 清理过期的请求const validTimestamps = timestamps.filter(t => now - t < window)if(validTimestamps.length >= limit){returnfalse// 超过速率限制}
validTimestamps.push(now)this.requests.set(source, validTimestamps)returntrue}}