| 
									
										
										
										
											2018-07-05 15:22:48 +05:00
										 |  |  | from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging | 
					
						
							| 
									
										
										
										
											2018-09-24 18:56:48 +05:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2018-09-28 14:23:02 +05:00
										 |  |  | from django.shortcuts import HttpResponse | 
					
						
							| 
									
										
										
										
											2018-06-30 15:29:56 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class secMiddleware: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, get_response): | 
					
						
							|  |  |  |         self.get_response = get_response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __call__(self, request): | 
					
						
							|  |  |  |         if request.method == 'POST': | 
					
						
							| 
									
										
										
										
											2018-09-28 14:23:02 +05:00
										 |  |  |             try: | 
					
						
							|  |  |  |                 data = json.loads(request.body) | 
					
						
							|  |  |  |                 for key, value in data.iteritems(): | 
					
						
							|  |  |  |                     if type(value) == int or type(value) == bool or key == 'configData': | 
					
						
							|  |  |  |                         continue | 
					
						
							|  |  |  |                     if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1: | 
					
						
							|  |  |  |                         logging.writeToFile(request.body) | 
					
						
							|  |  |  |                         return HttpResponse('Error') | 
					
						
							|  |  |  |                     if key.find(';') > -1 or key.find('&&') > -1 or key.find('|') > -1 or key.find('...') > -1: | 
					
						
							|  |  |  |                         logging.writeToFile(request.body) | 
					
						
							|  |  |  |                         return HttpResponse('Error') | 
					
						
							|  |  |  |             except BaseException, msg: | 
					
						
							|  |  |  |                 logging.writeToFile(str(msg)) | 
					
						
							|  |  |  |                 response = self.get_response(request) | 
					
						
							|  |  |  |                 return response | 
					
						
							| 
									
										
										
										
											2018-06-30 15:29:56 +05:00
										 |  |  |         response = self.get_response(request) | 
					
						
							| 
									
										
										
										
											2018-09-24 18:56:48 +05:00
										 |  |  |         return response |