Skip to content

Commit e65109f

Browse files
committed
Fix security middleware to allow file content in API endpoints
- Add bypass check for 'content' field INSIDE isAPIEndpoint block - Prevents blocking of legitimate JavaScript/PHP code in replace-file API - Bypass list includes: content, fileContent, configData, rewriteRules, modSecRules - Security check still applies to other fields in API requests - Fixes: Replace-file API being blocked by security middleware
1 parent 7ba2058 commit e65109f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

CyberCP/secMiddleware.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ def __call__(self, request):
192192
pathActual.find('/api/') > -1 or pathActual.find('aiscanner/scheduled-scans') > -1)
193193

194194
if isAPIEndpoint:
195+
# Skip validation for fields that contain legitimate code/scripts
196+
if key == 'content' or key == 'fileContent' or key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'contentNow' or key == 'emailMessage':
197+
continue
198+
195199
# For API endpoints, still check for the most dangerous command injection characters
196-
if isinstance(value, (str, bytes)) and (value.find('- -') > -1 or value.find('\n') > -1 or value.find(';') > -1 or
197-
value.find('&&') > -1 or value.find('||') > -1 or value.find('|') > -1 or
200+
if isinstance(value, (str, bytes)) and (value.find('- -') > -1 or value.find('\n') > -1 or value.find(';') > -1 or
201+
value.find('&&') > -1 or value.find('||') > -1 or value.find('|') > -1 or
198202
value.find('...') > -1 or value.find("`") > -1 or value.find("$") > -1 or
199203
value.find('../') > -1 or value.find('../../') > -1):
200204
logging.writeToFile(request.body)
@@ -212,7 +216,7 @@ def __call__(self, request):
212216
or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' \
213217
or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' \
214218
or key == 'fileContent' or key == 'commands' or key == 'gitHost' or key == 'ipv6' or key == 'contentNow' \
215-
or key == 'time_of_day' or key == 'notification_emails' or key == 'domains':
219+
or key == 'time_of_day' or key == 'notification_emails' or key == 'domains' or key == 'content':
216220
continue
217221

218222
# Skip validation for API endpoints that need JSON structure characters

0 commit comments

Comments
 (0)