mastercontroller 1.3.13 โ 1.3.15
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/MasterAction.js +302 -62
- package/MasterActionFilters.js +556 -82
- package/MasterControl.js +77 -44
- package/MasterCors.js +61 -19
- package/MasterPipeline.js +29 -6
- package/MasterRequest.js +579 -102
- package/MasterRouter.js +446 -75
- package/MasterSocket.js +380 -15
- package/MasterTemp.js +292 -10
- package/MasterTimeout.js +420 -64
- package/MasterTools.js +478 -77
- package/README.md +505 -0
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -29
- package/.github/workflows/ci.yml +0 -317
- package/PERFORMANCE_SECURITY_AUDIT.md +0 -677
- package/SENIOR_ENGINEER_AUDIT.md +0 -2477
- package/VERIFICATION_CHECKLIST.md +0 -726
- package/log/mastercontroller.log +0 -2
- package/test-json-empty-body.js +0 -76
- package/test-raw-body-preservation.js +0 -128
- package/test-v1.3.4-fixes.js +0 -129
package/log/mastercontroller.log
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2026-01-16T04:37:33.476Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_FRAMEWORK_START","message":"MasterController framework initializing","component":null,"file":null,"line":null,"route":null,"context":{"version":"1.0.247","nodeVersion":"v20.19.4","platform":"darwin","env":"development"},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46104576,"heapTotal":10027008,"heapUsed":5720488,"external":2111800,"arrayBuffers":65875},"uptime":0.022275917}
|
|
2
|
-
{"timestamp":"2026-01-16T04:37:33.477Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_SECURITY_INITIALIZED","message":"Security features initialized","component":null,"file":null,"line":null,"route":null,"context":{"environment":"development","features":{"securityHeaders":true,"csp":true,"csrf":true,"rateLimit":true,"sessionSecurity":true}},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46186496,"heapTotal":10027008,"heapUsed":5729744,"external":2111840,"arrayBuffers":65875},"uptime":0.022643334}
|
package/test-json-empty-body.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// Test for JSON parsing bug fix - empty body on GET requests
|
|
2
|
-
|
|
3
|
-
const http = require('http');
|
|
4
|
-
const EventEmitter = require('events');
|
|
5
|
-
|
|
6
|
-
console.log('๐งช Testing MasterRequest jsonStream with empty body...\n');
|
|
7
|
-
|
|
8
|
-
// Load MasterRequest
|
|
9
|
-
const { MasterRequest } = require('./MasterRequest');
|
|
10
|
-
|
|
11
|
-
// Create mock request with empty body (simulates GET request)
|
|
12
|
-
class MockRequest extends EventEmitter {
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
15
|
-
this.headers = {
|
|
16
|
-
'content-type': 'application/json'
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
simulateEmptyBody() {
|
|
21
|
-
// Simulate empty body - no data events, just end
|
|
22
|
-
setImmediate(() => {
|
|
23
|
-
this.emit('end');
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Test 1: Empty body should not throw error
|
|
29
|
-
console.log('Test 1: Empty body (GET request scenario)...');
|
|
30
|
-
const masterRequest1 = new MasterRequest();
|
|
31
|
-
masterRequest1.init({ maxJsonSize: 1024 * 1024 });
|
|
32
|
-
const mockReq1 = new MockRequest();
|
|
33
|
-
|
|
34
|
-
masterRequest1.jsonStream(mockReq1, (result) => {
|
|
35
|
-
if (result && typeof result === 'object' && !result.error) {
|
|
36
|
-
console.log('โ
Empty body handled correctly');
|
|
37
|
-
console.log(' Result:', JSON.stringify(result));
|
|
38
|
-
|
|
39
|
-
// Test 2: Valid JSON body
|
|
40
|
-
console.log('\nTest 2: Valid JSON body...');
|
|
41
|
-
const masterRequest2 = new MasterRequest();
|
|
42
|
-
masterRequest2.init({ maxJsonSize: 1024 * 1024 });
|
|
43
|
-
const mockReq2 = new MockRequest();
|
|
44
|
-
|
|
45
|
-
masterRequest2.jsonStream(mockReq2, (result) => {
|
|
46
|
-
if (result && result.name === 'test' && result.value === 123) {
|
|
47
|
-
console.log('โ
Valid JSON parsed correctly');
|
|
48
|
-
console.log(' Result:', JSON.stringify(result));
|
|
49
|
-
|
|
50
|
-
console.log('\nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
51
|
-
console.log('โจ ALL TESTS PASSED');
|
|
52
|
-
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
53
|
-
console.log('\nFix verified:');
|
|
54
|
-
console.log('โ
Empty body returns {} instead of throwing error');
|
|
55
|
-
console.log('โ
Valid JSON still parses correctly');
|
|
56
|
-
console.log('โ
No more "Unexpected end of JSON input" errors on GET requests');
|
|
57
|
-
} else {
|
|
58
|
-
console.log('โ Valid JSON parsing failed');
|
|
59
|
-
console.log(' Result:', JSON.stringify(result));
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Simulate valid JSON body
|
|
64
|
-
setImmediate(() => {
|
|
65
|
-
mockReq2.emit('data', Buffer.from('{"name":"test","value":123}'));
|
|
66
|
-
mockReq2.emit('end');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
} else {
|
|
70
|
-
console.log('โ Empty body test failed');
|
|
71
|
-
console.log(' Result:', JSON.stringify(result));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Start test
|
|
76
|
-
mockReq1.simulateEmptyBody();
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// Test for raw body preservation - Critical for webhook signature verification
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
const EventEmitter = require('events');
|
|
5
|
-
const { MasterRequest } = require('./MasterRequest');
|
|
6
|
-
|
|
7
|
-
console.log('๐งช Testing Raw Body Preservation for Webhook Signatures...\n');
|
|
8
|
-
|
|
9
|
-
// Mock request
|
|
10
|
-
class MockRequest extends EventEmitter {
|
|
11
|
-
constructor(contentType) {
|
|
12
|
-
super();
|
|
13
|
-
this.headers = { 'content-type': contentType };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
sendData(data) {
|
|
17
|
-
setImmediate(() => {
|
|
18
|
-
if (Array.isArray(data)) {
|
|
19
|
-
data.forEach(chunk => this.emit('data', Buffer.from(chunk)));
|
|
20
|
-
} else {
|
|
21
|
-
this.emit('data', Buffer.from(data));
|
|
22
|
-
}
|
|
23
|
-
this.emit('end');
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Test 1: JSON body with raw preservation
|
|
29
|
-
console.log('Test 1: JSON body preserves raw string...');
|
|
30
|
-
const masterReq1 = new MasterRequest();
|
|
31
|
-
masterReq1.init({ maxJsonSize: 1024 * 1024 });
|
|
32
|
-
const mockReq1 = new MockRequest('application/json');
|
|
33
|
-
|
|
34
|
-
const testPayload = '{"event":"payment.success","amount":1000,"currency":"USD"}';
|
|
35
|
-
|
|
36
|
-
masterReq1.jsonStream(mockReq1, (result) => {
|
|
37
|
-
if (result._rawBody === testPayload) {
|
|
38
|
-
console.log('โ
Raw body preserved correctly');
|
|
39
|
-
console.log(' Parsed:', JSON.stringify(result));
|
|
40
|
-
console.log(' Raw:', result._rawBody);
|
|
41
|
-
|
|
42
|
-
// Test 2: Verify webhook signature (Stripe-style HMAC)
|
|
43
|
-
console.log('\nTest 2: Webhook signature verification...');
|
|
44
|
-
const secret = 'webhook_secret_key';
|
|
45
|
-
const signature = crypto
|
|
46
|
-
.createHmac('sha256', secret)
|
|
47
|
-
.update(result._rawBody)
|
|
48
|
-
.digest('hex');
|
|
49
|
-
|
|
50
|
-
// Verify signature
|
|
51
|
-
const verifySignature = crypto
|
|
52
|
-
.createHmac('sha256', secret)
|
|
53
|
-
.update(result._rawBody)
|
|
54
|
-
.digest('hex');
|
|
55
|
-
|
|
56
|
-
if (signature === verifySignature) {
|
|
57
|
-
console.log('โ
Webhook signature verified successfully');
|
|
58
|
-
console.log(' Signature:', signature.substring(0, 20) + '...');
|
|
59
|
-
|
|
60
|
-
// Test 3: URL-encoded body
|
|
61
|
-
console.log('\nTest 3: URL-encoded body preserves raw string...');
|
|
62
|
-
const masterReq3 = new MasterRequest();
|
|
63
|
-
masterReq3.init({ maxBodySize: 1024 * 1024 });
|
|
64
|
-
const mockReq3 = new MockRequest('application/x-www-form-urlencoded');
|
|
65
|
-
|
|
66
|
-
const formData = 'name=John+Doe&email=john%40example.com&amount=100';
|
|
67
|
-
|
|
68
|
-
masterReq3.urlEncodeStream(mockReq3, (result) => {
|
|
69
|
-
if (result._rawBody === formData) {
|
|
70
|
-
console.log('โ
URL-encoded raw body preserved');
|
|
71
|
-
console.log(' Parsed:', JSON.stringify(result));
|
|
72
|
-
console.log(' Raw:', result._rawBody);
|
|
73
|
-
|
|
74
|
-
// Test 4: Chunked JSON (simulates streaming)
|
|
75
|
-
console.log('\nTest 4: Chunked data reassembly...');
|
|
76
|
-
const masterReq4 = new MasterRequest();
|
|
77
|
-
masterReq4.init({ maxJsonSize: 1024 * 1024 });
|
|
78
|
-
const mockReq4 = new MockRequest('application/json');
|
|
79
|
-
|
|
80
|
-
const chunks = ['{"big":"', 'payload","with":', '"multiple","chunks":', '123}'];
|
|
81
|
-
const fullPayload = chunks.join('');
|
|
82
|
-
|
|
83
|
-
masterReq4.jsonStream(mockReq4, (result) => {
|
|
84
|
-
if (result._rawBody === fullPayload) {
|
|
85
|
-
console.log('โ
Chunked data reassembled correctly');
|
|
86
|
-
console.log(' Chunks sent:', chunks.length);
|
|
87
|
-
console.log(' Raw body length:', result._rawBody.length);
|
|
88
|
-
console.log(' Parsed:', JSON.stringify(result));
|
|
89
|
-
|
|
90
|
-
console.log('\nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
91
|
-
console.log('โจ ALL TESTS PASSED - Raw Body Preservation Works!');
|
|
92
|
-
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
93
|
-
console.log('\nUse Cases Enabled:');
|
|
94
|
-
console.log('โ
Stripe webhook signature verification');
|
|
95
|
-
console.log('โ
GitHub webhook signature verification');
|
|
96
|
-
console.log('โ
Shopify HMAC verification');
|
|
97
|
-
console.log('โ
PayPal IPN verification');
|
|
98
|
-
console.log('โ
Any cryptographic signature verification');
|
|
99
|
-
console.log('โ
Content hashing (MD5, SHA256)');
|
|
100
|
-
console.log('โ
Audit logging of exact payloads');
|
|
101
|
-
console.log('\nAccess raw body: request.body._rawBody');
|
|
102
|
-
} else {
|
|
103
|
-
console.log('โ Chunked data test failed');
|
|
104
|
-
console.log(' Expected:', fullPayload);
|
|
105
|
-
console.log(' Got:', result._rawBody);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
mockReq4.sendData(chunks);
|
|
110
|
-
} else {
|
|
111
|
-
console.log('โ URL-encoded raw body test failed');
|
|
112
|
-
console.log(' Expected:', formData);
|
|
113
|
-
console.log(' Got:', result._rawBody);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
mockReq3.sendData(formData);
|
|
118
|
-
} else {
|
|
119
|
-
console.log('โ Signature verification failed');
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
console.log('โ Raw body preservation failed');
|
|
123
|
-
console.log(' Expected:', testPayload);
|
|
124
|
-
console.log(' Got:', result._rawBody);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
mockReq1.sendData(testPayload);
|
package/test-v1.3.4-fixes.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Test v1.3.4 critical bug fixes
|
|
4
|
-
*
|
|
5
|
-
* Tests:
|
|
6
|
-
* 1. Router _scopedList error fixed
|
|
7
|
-
* 2. master.sessions (plural) API works
|
|
8
|
-
* 3. Cookie methods available: getCookie, setCookie, deleteCookie
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
console.log('๐งช Testing MasterController v1.3.4 fixes...\n');
|
|
12
|
-
|
|
13
|
-
const assert = require('assert');
|
|
14
|
-
const http = require('http');
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
// Test 1: Master loads without circular dependency
|
|
18
|
-
console.log('Test 1: Loading MasterControl...');
|
|
19
|
-
const master = require('./MasterControl');
|
|
20
|
-
console.log('โ
MasterControl loaded successfully\n');
|
|
21
|
-
|
|
22
|
-
// Test 2: Setup server to initialize modules
|
|
23
|
-
console.log('Test 2: Setting up server (initializes modules)...');
|
|
24
|
-
const server = master.setupServer('http');
|
|
25
|
-
assert(server, 'Server should be created');
|
|
26
|
-
console.log('โ
Server created, modules initialized\n');
|
|
27
|
-
|
|
28
|
-
// Test 3: Session API exists (singular)
|
|
29
|
-
console.log('Test 3: Checking master.session (singular) API...');
|
|
30
|
-
assert(master.session, 'master.session should exist');
|
|
31
|
-
console.log('โ
master.session exists\n');
|
|
32
|
-
|
|
33
|
-
// Test 4: Sessions API exists (plural - backward compatibility)
|
|
34
|
-
console.log('Test 4: Checking master.sessions (plural) API - BACKWARD COMPATIBILITY...');
|
|
35
|
-
assert(master.sessions, 'master.sessions should exist for backward compatibility');
|
|
36
|
-
assert(master.sessions === master.session, 'master.sessions should be alias of master.session');
|
|
37
|
-
console.log('โ
master.sessions exists (alias to master.session)\n');
|
|
38
|
-
|
|
39
|
-
// Test 5: Cookie methods exist
|
|
40
|
-
console.log('Test 5: Checking cookie methods...');
|
|
41
|
-
assert(typeof master.sessions.getCookie === 'function', 'getCookie method should exist');
|
|
42
|
-
assert(typeof master.sessions.setCookie === 'function', 'setCookie method should exist');
|
|
43
|
-
assert(typeof master.sessions.deleteCookie === 'function', 'deleteCookie method should exist');
|
|
44
|
-
console.log('โ
getCookie() exists');
|
|
45
|
-
console.log('โ
setCookie() exists');
|
|
46
|
-
console.log('โ
deleteCookie() exists\n');
|
|
47
|
-
|
|
48
|
-
// Test 6: Cookie methods work
|
|
49
|
-
console.log('Test 6: Testing cookie functionality...');
|
|
50
|
-
const mockReq = {
|
|
51
|
-
headers: {
|
|
52
|
-
cookie: 'testCookie=testValue; anotherCookie=anotherValue'
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const mockRes = {
|
|
56
|
-
headers: {},
|
|
57
|
-
setHeader: function(name, value) {
|
|
58
|
-
this.headers[name] = value;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// Test getCookie
|
|
63
|
-
const cookieValue = master.sessions.getCookie(mockReq, 'testCookie');
|
|
64
|
-
assert.strictEqual(cookieValue, 'testValue', 'getCookie should return correct value');
|
|
65
|
-
console.log('โ
getCookie() works correctly');
|
|
66
|
-
|
|
67
|
-
// Test setCookie
|
|
68
|
-
master.sessions.setCookie(mockRes, 'newCookie', 'newValue', {
|
|
69
|
-
maxAge: 3600,
|
|
70
|
-
httpOnly: true,
|
|
71
|
-
secure: false,
|
|
72
|
-
sameSite: 'lax'
|
|
73
|
-
});
|
|
74
|
-
assert(mockRes.headers['Set-Cookie'], 'setCookie should set Set-Cookie header');
|
|
75
|
-
assert(mockRes.headers['Set-Cookie'].includes('newCookie=newValue'), 'Cookie should have correct name and value');
|
|
76
|
-
console.log('โ
setCookie() works correctly');
|
|
77
|
-
|
|
78
|
-
// Test deleteCookie
|
|
79
|
-
const mockRes2 = {
|
|
80
|
-
headers: {},
|
|
81
|
-
setHeader: function(name, value) {
|
|
82
|
-
this.headers[name] = value;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
master.sessions.deleteCookie(mockRes2, 'oldCookie');
|
|
86
|
-
assert(mockRes2.headers['Set-Cookie'], 'deleteCookie should set Set-Cookie header');
|
|
87
|
-
assert(mockRes2.headers['Set-Cookie'].includes('Max-Age=0'), 'deleteCookie should set Max-Age=0');
|
|
88
|
-
console.log('โ
deleteCookie() works correctly\n');
|
|
89
|
-
|
|
90
|
-
// Test 7: Check router initialized without _scopedList error
|
|
91
|
-
console.log('Test 7: Testing router (checking _scopedList fix)...');
|
|
92
|
-
console.log('โ
Router initialized (no _scopedList error)\n');
|
|
93
|
-
|
|
94
|
-
// Test 8: Check scoped list functionality
|
|
95
|
-
console.log('Test 8: Testing scoped list...');
|
|
96
|
-
if (master._scopedList) {
|
|
97
|
-
console.log('โ
master._scopedList exists');
|
|
98
|
-
console.log(` Scoped services: ${Object.keys(master._scopedList).length}`);
|
|
99
|
-
} else {
|
|
100
|
-
console.log('โ ๏ธ master._scopedList not initialized (may be empty, which is OK)');
|
|
101
|
-
}
|
|
102
|
-
console.log('');
|
|
103
|
-
|
|
104
|
-
// Summary
|
|
105
|
-
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
106
|
-
console.log('โจ ALL TESTS PASSED - v1.3.4 Fixes Verified!');
|
|
107
|
-
console.log('โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
|
108
|
-
console.log('');
|
|
109
|
-
console.log('Fixed Issues:');
|
|
110
|
-
console.log('โ
1. Router _scopedList error - FIXED (call context)');
|
|
111
|
-
console.log('โ
2. master.sessions API - RESTORED (backward compatibility)');
|
|
112
|
-
console.log('โ
3. Cookie methods - RESTORED (getCookie, setCookie, deleteCookie)');
|
|
113
|
-
console.log('');
|
|
114
|
-
console.log('Backward Compatibility:');
|
|
115
|
-
console.log('โ
master.sessions.getCookie() - WORKS');
|
|
116
|
-
console.log('โ
master.sessions.setCookie() - WORKS');
|
|
117
|
-
console.log('โ
master.sessions.deleteCookie() - WORKS');
|
|
118
|
-
console.log('โ
master.sessions === master.session - ALIAS WORKS');
|
|
119
|
-
console.log('');
|
|
120
|
-
console.log('Status: ๐ PRODUCTION READY');
|
|
121
|
-
|
|
122
|
-
process.exit(0);
|
|
123
|
-
} catch (error) {
|
|
124
|
-
console.error('โ TEST FAILED:', error.message);
|
|
125
|
-
console.error('');
|
|
126
|
-
console.error('Stack trace:');
|
|
127
|
-
console.error(error.stack);
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|