-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1.36 KB
/
Copy pathserver.js
File metadata and controls
41 lines (32 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const { scanPrompt } = require('./guardrails');
const { logSecurityIncidentOnChain } = require('./mantleLogger');
const app = express();
app.use(express.json());
const PORT = process.env.PORT || 3000;
// Security Guardrail Proxy Endpoint
app.post('/api/v1/chat', async (req, res) => {
const { message } = req.body;
// Execute real-time core guardrail inspection
const securityCheck = scanPrompt(message);
if (!securityCheck.isSafe) {
console.warn(`[SECURITY ALERT]: Intervention triggered due to: ${securityCheck.reason}`);
// Push threat telemetry to Mantle Network for unalterable compliance audit
const txHash = await logSecurityIncidentOnChain("Prompt Injection", securityCheck.reason);
return res.status(403).json({
status: "blocked",
error: "Security Policy Violation",
reason: securityCheck.reason,
blockchainAudit: txHash ? { network: "Mantle Testnet", txHash: txHash } : "Failed to establish audit log"
});
}
// Input is verified safe; forward to target AI Agent execution loop
res.json({
status: "success",
message: "Input verified as secure.",
forwardedMessage: message
});
});
app.listen(PORT, () => {
console.log(`🛡️ AgentWatchdog Security Proxy active on port ${PORT}`);
});