mastercontroller 1.3.22 → 1.3.24

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.
Files changed (2) hide show
  1. package/MasterRouter.js +26 -8
  2. package/package.json +1 -1
package/MasterRouter.js CHANGED
@@ -124,14 +124,18 @@ const ROUTER_CONFIG = {
124
124
  return paramValue;
125
125
  }
126
126
 
127
+ // Fast path: skip expensive regex checks for simple alphanumeric values
128
+ if (/^[a-zA-Z0-9_-]+$/.test(paramValue)) {
129
+ return paramValue;
130
+ }
131
+
127
132
  // Check for path traversal attempts
128
133
  const pathCheck = detectPathTraversal(paramValue);
129
134
  if (!pathCheck.safe) {
130
135
  logger.warn({
131
136
  code: 'MC_SECURITY_PATH_TRAVERSAL',
132
137
  message: 'Path traversal attempt detected in route parameter',
133
- param: paramName,
134
- value: paramValue
138
+ context: { param: paramName, value: paramValue }
135
139
  });
136
140
 
137
141
  // Remove dangerous content
@@ -144,8 +148,7 @@ const ROUTER_CONFIG = {
144
148
  logger.warn({
145
149
  code: 'MC_SECURITY_SQL_INJECTION',
146
150
  message: 'SQL injection attempt detected in route parameter',
147
- param: paramName,
148
- value: paramValue
151
+ context: { param: paramName, value: paramValue }
149
152
  });
150
153
 
151
154
  // Escape to prevent injection
@@ -158,8 +161,7 @@ const ROUTER_CONFIG = {
158
161
  logger.warn({
159
162
  code: 'MC_SECURITY_COMMAND_INJECTION',
160
163
  message: 'Command injection attempt detected in route parameter',
161
- param: paramName,
162
- value: paramValue
164
+ context: { param: paramName, value: paramValue }
163
165
  });
164
166
 
165
167
  // Remove dangerous characters
@@ -810,7 +812,7 @@ class MasterRouter {
810
812
  const control = new Control(requestObject);
811
813
  const _callEmit = new EventEmitter();
812
814
 
813
- _callEmit.on(EVENT_NAMES.CONTROLLER, function(){
815
+ _callEmit.once(EVENT_NAMES.CONTROLLER, function(){
814
816
  try {
815
817
  control.next = function(){
816
818
  control.__callAfterAction(control, requestObject);
@@ -830,7 +832,18 @@ class MasterRouter {
830
832
 
831
833
  // Execute action
832
834
  Promise.resolve(wrappedAction.call(control, requestObject))
833
- .then(() => {
835
+ .then((returnValue) => {
836
+ // Auto-send return value as JSON if controller returned data
837
+ // and no response was sent yet (e.g., overridden returnJson pattern)
838
+ if (returnValue !== undefined && returnValue !== null
839
+ && !requestObject.response.headersSent && !requestObject.response._headerSent) {
840
+ const json = JSON.stringify(returnValue);
841
+ requestObject.response.writeHead(200, {
842
+ 'Content-Type': 'application/json',
843
+ 'Content-Length': Buffer.byteLength(json, 'utf8')
844
+ });
845
+ requestObject.response.end(json);
846
+ }
834
847
  performanceTracker.end(requestId);
835
848
  // MEMORY LEAK FIX: Clean up event listeners
836
849
  _callEmit.removeAllListeners();
@@ -961,6 +974,11 @@ class MasterRouter {
961
974
  throw new TypeError('Request object must have a valid type (HTTP method)');
962
975
  }
963
976
 
977
+ // Skip route processing for OPTIONS requests already handled by CORS middleware
978
+ if (rr.type.toLowerCase() === 'options' && (rr.response.headersSent || rr.response._headerSent)) {
979
+ return;
980
+ }
981
+
964
982
  const $that = this;
965
983
  // FIX: Use direct reference instead of Object.create() to preserve request/response objects
966
984
  // Object.create() puts properties on prototype, causing undefined access issues
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastercontroller",
3
- "version": "1.3.22",
3
+ "version": "1.3.24",
4
4
  "description": "Fortune 500 ready Node.js MVC framework with enterprise security, monitoring, and horizontal scaling",
5
5
  "main": "MasterControl.js",
6
6
  "license": "MIT",