Fixing error_message": "Session reuse detected, IPAddress logged

@arworld said:
For cloudflare users please replace REMOTE_ADDR with True-Client-IP and for nginx please replace REMOTE_ADDR with X_REAL_IP
your issue will be resolved no need to remove a single line and also no 500 error cheers
regards
Aditya Rathore World

ipAddr = request.META.get(‘True-Client-IP’).split(‘:’)[:3]

you can comment above line if using cloudflare as it have single header ip only
def call(self, request):
try:
uID = request.session[‘userID’]
admin = Administrator.objects.get(pk=uID)
ipAddr = request.META.get(‘True-Client-IP’)

        if ipAddr.find('.') > -1:
            if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
                pass
            else:
                del request.session['userID']
                del request.session['ipAddr']
                logging.writeToFile(request.META.get('True-Client-IP'))
                final_dic = {'error_message': "Session reuse detected, IPAddress logged.",
                             "errorMessage": "Session reuse detected, IPAddress logged."}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)
        else:

ipAddr = request.META.get(‘True-Client-IP’).split(‘:’)[:3]

            if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
                pass
            else:
                del request.session['userID']
                del request.session['ipAddr']
                logging.writeToFile(request.META.get('True-Client-IP'))
                final_dic = {'error_message': "Session reuse detected, IPAddress logged.",
                             "errorMessage": "Session reuse detected, IPAddress logged."}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)
    except:
        pass
1 Like