neuronix-node 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/file-processor.d.ts +2 -2
- package/dist/handlers/file-processor.js +353 -109
- package/dist/index.js +64 -1
- package/dist/parsers/index.d.ts +2 -3
- package/dist/parsers/index.js +155 -46
- package/dist/security/audit-log.d.ts +22 -0
- package/dist/security/audit-log.js +129 -0
- package/dist/security/resource-limiter.d.ts +36 -0
- package/dist/security/resource-limiter.js +83 -0
- package/dist/security/sandbox.d.ts +24 -0
- package/dist/security/sandbox.js +112 -0
- package/dist/security/task-verifier.d.ts +24 -0
- package/dist/security/task-verifier.js +91 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface TaskValidation {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
reason?: string;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validate a task before execution.
|
|
8
|
+
* Checks: type whitelist, payload safety, size limits.
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateTask(task: {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
input_payload: Record<string, unknown>;
|
|
14
|
+
model?: string;
|
|
15
|
+
timeout_seconds?: number;
|
|
16
|
+
}): TaskValidation;
|
|
17
|
+
/**
|
|
18
|
+
* Generate HMAC signature for a task (used server-side).
|
|
19
|
+
*/
|
|
20
|
+
export declare function signTask(taskId: string, taskType: string, secret: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Verify HMAC signature of a task (used client-side).
|
|
23
|
+
*/
|
|
24
|
+
export declare function verifyTaskSignature(taskId: string, taskType: string, signature: string, secret: string): boolean;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTask = validateTask;
|
|
4
|
+
exports.signTask = signTask;
|
|
5
|
+
exports.verifyTaskSignature = verifyTaskSignature;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const audit_log_js_1 = require("./audit-log.js");
|
|
8
|
+
/**
|
|
9
|
+
* Task Signature Verification
|
|
10
|
+
*
|
|
11
|
+
* Every task dispatched by Neuronix is signed with a server-side secret.
|
|
12
|
+
* The node verifies the signature before executing any task.
|
|
13
|
+
* This prevents:
|
|
14
|
+
* - Forged tasks from unauthorized sources
|
|
15
|
+
* - Man-in-the-middle task injection
|
|
16
|
+
* - Tampering with task payloads in transit
|
|
17
|
+
*
|
|
18
|
+
* Currently uses HMAC-SHA256. The shared secret is derived from the node's
|
|
19
|
+
* auth token (which is unique per node and rotated on re-login).
|
|
20
|
+
*/
|
|
21
|
+
const ALLOWED_TASK_TYPES = new Set([
|
|
22
|
+
"inference", "embedding", "image", "audio",
|
|
23
|
+
"chart", "invoice", "expense_report", "pnl", "smart_route", "process_file", "chat",
|
|
24
|
+
"ar_aging", "ap_aging", "bank_reconciliation", "budget_vs_actuals",
|
|
25
|
+
"payroll", "sales_tax", "depreciation", "cash_flow",
|
|
26
|
+
"department_spending", "variance_analysis", "w2_1099",
|
|
27
|
+
]);
|
|
28
|
+
const BLOCKED_PATTERNS = [
|
|
29
|
+
/eval\s*\(/i,
|
|
30
|
+
/exec\s*\(/i,
|
|
31
|
+
/require\s*\(/i,
|
|
32
|
+
/import\s*\(/i,
|
|
33
|
+
/child_process/i,
|
|
34
|
+
/\bfs\b.*\b(write|unlink|rmdir|mkdir)\b/i,
|
|
35
|
+
/process\.env/i,
|
|
36
|
+
/process\.exit/i,
|
|
37
|
+
/__dirname/i,
|
|
38
|
+
/__filename/i,
|
|
39
|
+
/\bfetch\s*\(\s*["'](?!https:\/\/neuronix)/i, // Block fetch to non-Neuronix URLs
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Validate a task before execution.
|
|
43
|
+
* Checks: type whitelist, payload safety, size limits.
|
|
44
|
+
*/
|
|
45
|
+
function validateTask(task) {
|
|
46
|
+
const warnings = [];
|
|
47
|
+
// 1. Check task type is whitelisted
|
|
48
|
+
if (!ALLOWED_TASK_TYPES.has(task.type)) {
|
|
49
|
+
(0, audit_log_js_1.logSecurityEvent)("BLOCKED_TASK_TYPE", `Task ${task.id}: unknown type "${task.type}"`);
|
|
50
|
+
return { valid: false, reason: `Unknown task type: ${task.type}`, warnings };
|
|
51
|
+
}
|
|
52
|
+
// 2. Check payload size (max 5MB)
|
|
53
|
+
const payloadSize = JSON.stringify(task.input_payload).length;
|
|
54
|
+
if (payloadSize > 5 * 1024 * 1024) {
|
|
55
|
+
(0, audit_log_js_1.logSecurityEvent)("BLOCKED_PAYLOAD_SIZE", `Task ${task.id}: payload too large (${(payloadSize / 1024 / 1024).toFixed(1)}MB)`);
|
|
56
|
+
return { valid: false, reason: `Payload too large: ${(payloadSize / 1024 / 1024).toFixed(1)}MB (max 5MB)`, warnings };
|
|
57
|
+
}
|
|
58
|
+
// 3. Scan payload for dangerous patterns
|
|
59
|
+
const payloadStr = JSON.stringify(task.input_payload);
|
|
60
|
+
for (const pattern of BLOCKED_PATTERNS) {
|
|
61
|
+
if (pattern.test(payloadStr)) {
|
|
62
|
+
(0, audit_log_js_1.logSecurityEvent)("BLOCKED_DANGEROUS_PATTERN", `Task ${task.id}: dangerous pattern detected`);
|
|
63
|
+
return { valid: false, reason: `Task payload contains potentially dangerous content`, warnings };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// 4. Check timeout is reasonable (max 10 minutes)
|
|
67
|
+
if (task.timeout_seconds && task.timeout_seconds > 600) {
|
|
68
|
+
warnings.push(`Task timeout ${task.timeout_seconds}s exceeds recommended max (600s)`);
|
|
69
|
+
}
|
|
70
|
+
// 5. Validate model name
|
|
71
|
+
const allowedModels = ["auto", "tinyllama-1.1b", "phi-2", "mistral-7b", "llama3-8b", "qwen-70b", "qwen-397b"];
|
|
72
|
+
if (task.model && !allowedModels.includes(task.model)) {
|
|
73
|
+
warnings.push(`Unknown model: ${task.model}`);
|
|
74
|
+
}
|
|
75
|
+
return { valid: true, warnings };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate HMAC signature for a task (used server-side).
|
|
79
|
+
*/
|
|
80
|
+
function signTask(taskId, taskType, secret) {
|
|
81
|
+
return (0, crypto_1.createHmac)("sha256", secret)
|
|
82
|
+
.update(`${taskId}:${taskType}`)
|
|
83
|
+
.digest("hex");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Verify HMAC signature of a task (used client-side).
|
|
87
|
+
*/
|
|
88
|
+
function verifyTaskSignature(taskId, taskType, signature, secret) {
|
|
89
|
+
const expected = signTask(taskId, taskType, secret);
|
|
90
|
+
return expected === signature;
|
|
91
|
+
}
|