Created
November 30, 2021 12:46
-
-
Save codephillip/ec95145981a63c21a6bf78f6dd31addd to your computer and use it in GitHub Desktop.
Custom CORS and CSRF middleware bypasser(used in microservices)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.deprecation import MiddlewareMixin | |
# NOTE: This is not best practise, however, api requests from some browser would fail continuous so explains the use | |
# of this. Enhance this CSRF solution if necessary | |
class DisableCsrfCheck(MiddlewareMixin): | |
def process_request(self, req): | |
attr = '_dont_enforce_csrf_checks' | |
if not getattr(req, attr, False): | |
setattr(req, attr, True) | |
class CorsMiddleware(object): | |
def process_response(self, req, resp): | |
resp["Access-Control-Allow-Origin"] = "*" | |
return resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment