What are the best practices for securing web applications against common threats such as cross-site scripting (XSS) and SQL injection attacks?