mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-01 02:46:20 +01:00
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
This commit is contained in:
@@ -192,9 +192,13 @@ class secMiddleware:
|
||||
pathActual.find('/api/') > -1 or pathActual.find('aiscanner/scheduled-scans') > -1)
|
||||
|
||||
if isAPIEndpoint:
|
||||
# Skip validation for fields that contain legitimate code/scripts
|
||||
if key == 'content' or key == 'fileContent' or key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'contentNow' or key == 'emailMessage':
|
||||
continue
|
||||
|
||||
# For API endpoints, still check for the most dangerous command injection characters
|
||||
if isinstance(value, (str, bytes)) and (value.find('- -') > -1 or value.find('\n') > -1 or value.find(';') > -1 or
|
||||
value.find('&&') > -1 or value.find('||') > -1 or value.find('|') > -1 or
|
||||
if isinstance(value, (str, bytes)) and (value.find('- -') > -1 or value.find('\n') > -1 or value.find(';') > -1 or
|
||||
value.find('&&') > -1 or value.find('||') > -1 or value.find('|') > -1 or
|
||||
value.find('...') > -1 or value.find("`") > -1 or value.find("$") > -1 or
|
||||
value.find('../') > -1 or value.find('../../') > -1):
|
||||
logging.writeToFile(request.body)
|
||||
@@ -212,7 +216,7 @@ class secMiddleware:
|
||||
or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' \
|
||||
or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' \
|
||||
or key == 'fileContent' or key == 'commands' or key == 'gitHost' or key == 'ipv6' or key == 'contentNow' \
|
||||
or key == 'time_of_day' or key == 'notification_emails' or key == 'domains':
|
||||
or key == 'time_of_day' or key == 'notification_emails' or key == 'domains' or key == 'content':
|
||||
continue
|
||||
|
||||
# Skip validation for API endpoints that need JSON structure characters
|
||||
|
||||
Reference in New Issue
Block a user