Custom Validations in Django Rest Framework
Introduction One of the key components of HTTP request-response is request data validation. Modern HTTP requests typically send a JSON payload that needs to be sanitized and validated before proceeding with business logic and database operations. While client-side applications may implement basic form validations using libraries like Formik, backend validation remains essential as a security precaution. This article on hacking McDonald’s India Service APIs showcases interesting vulnerabilities that can be exploited when backend validations and authorizations are improperly implemented. ...
Hacky usage of mutable default arguments in Python
One of the most commonly known gotchas in Python is the use of mutable default arguments. Consider this simple Python function snippet: def foo(item: int, bar: list = []) -> None: bar.append(item) print( f"{bar=}" ) # Neat f-string trick btw to print both variable name and value foo(6) foo(6) foo(12) A Python newcomer might expect the output to be: bar = [6] bar = [6] bar = [12] Instead you would get: ...