Skip to content

Instantly share code, notes, and snippets.

@Cediddi
Last active May 1, 2020 04:42
Show Gist options
  • Save Cediddi/454701eb94c64c43be6c to your computer and use it in GitHub Desktop.
Save Cediddi/454701eb94c64c43be6c to your computer and use it in GitHub Desktop.
Django Middleware for fingerprinting browsers server-side. Useful for expiring auth tokens.
"""
#Disclaimer
- Use with caution
- Don't be evil
- Respect your users
"""
class FingerPrintMiddleware(object):
def process_request(self, request):
import hashlib
fingerprint_raw = "".join(
(request.META.get("HTTP_USER_AGENT", ""),
request.META.get("HTTP_ACCEPT_ENCODING", ""))
)
request.fingerprint = hashlib.md5(
fingerprint_raw.encode('utf-8')).hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment