Created
October 19, 2016 06:58
-
-
Save jimmyislive/a00869b596b19482811a1f78568104f9 to your computer and use it in GitHub Desktop.
csrf origin check
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
def csrf_check(web_request): | |
def real_decorator(view_func): | |
@wraps(view_func) | |
def wrapper(*args, **kwargs): | |
if (request.method == 'GET'): | |
return view_func(*args, **kwargs) | |
u = urlparse(request.headers['Origin']) | |
if u.netloc in ['www.my_awesome_domain.com', 'my_awesome_domain.com']: | |
return view_func(*args, **kwargs) | |
raise Unauthorized('Not Authorized') | |
return wrapper | |
return real_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment