Usually they are in line 11-40. Final code shoud look like
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
import json
from django.shortcuts import HttpResponse
class secMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
try:
uID = request.session['userID']
ipAddr = request.META.get('REMOTE_ADDR')
if request.method == 'POST':
try:
#logging.writeToFile(request.body)
data = json.loads(request.body)
for key, value in data.iteritems():
if request.path.find('gitNotify') > -1:
break
# if request.path.find('users') > -1 or request.path.find('firewall') > -1 or request.path.find('servicesAction') > -1 or request.path.find('sslForHostName') > -1:
# logging.writeToFile(request.body)
# final_dic = {'error_message': "Data supplied is not accepted.",
# "errorMessage": "Data supplied is not accepted."}
# final_json = json.dumps(final_dic)
# return HttpResponse(final_json)
if type(value) == str or type(value) == unicode:
pass
else:
continue
if request.build_absolute_uri().find('saveSpamAssassinConfigurations') > -1 or request.build_absolute_uri().find('docker') > -1 or request.build_absolute_uri().find('cloudAPI') > -1 or request.build_absolute_uri().find('filemanager') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1:
continue
if key == 'ports' or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' or key == 'fileContent':
continue
if 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 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)
final_dic = {'error_message': "Data supplied is not accepted.",
"errorMessage": "Data supplied is not accepted."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
if key.find(';') > -1 or key.find('&&') > -1 or key.find('|') > -1 or key.find('...') > -1 \\
or key.find("`") > -1 or key.find("$") > -1 or key.find("(") > -1 or key.find(")") > -1 \\
or key.find("'") > -1 or key.find("[") > -1 or key.find("]") > -1 or key.find("{") > -1 or key.find("}") > -1\\
or key.find(":") > -1 or key.find("<") > -1 or key.find(">") > -1:
logging.writeToFile(request.body)
final_dic = {'error_message': "Data supplied is not accepted.", "errorMessage": "Data supplied is not accepted."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except BaseException, msg:
logging.writeToFile(str(msg))
response = self.get_response(request)
return response
response = self.get_response(request)
return response
and this file is available at /usr/local/CyberCP/CyberCP
Actually, I coded an option you can enable or disable this within that file.
I do not have a dynamic session that changes to verify it that works, but the file works on my test server and has an if condition to only run if ‘true’ so in theory should work for you to toggle it off by setting value to ‘false’ without having to comment or delete lines in the core file which bound to be error-prone.
To set to On ‘true’
sed -i “s/^sessionIPValidation =.*/sessionIPValidation = ‘true’/g” /usr/local/CyberCP/CyberCP/secMiddleware.py
To set to Off: ‘false’
sed -i “s/^sessionIPValidation =.*/sessionIPValidation = ‘false’/g” /usr/local/CyberCP/CyberCP/secMiddleware.py
To check status:
grep -E ‘^sessionIPValidation’ /usr/local/CyberCP/CyberCP/secMiddleware.py
Example of this toggled to On(true): Default
root@ubuntu:~# grep -E ‘^sessionIPValidation’ /usr/local/CyberCP/CyberCP/secMiddleware.py
sessionIPValidation = ‘true’
root@ubuntu:~#
Example of this toggled to Off(false):
root@ubuntu:~# grep -E ‘^sessionIPValidation’ /usr/local/CyberCP/CyberCP/secMiddleware.py
sessionIPValidation = ‘false’
root@ubuntu:~#
After toggling:
systemctl restart lscpd||service lscpd restart
Test
If it works ill submit a pull request to have it merged to the stable branch.