3. Secure Python
This volume teaches you how to write Python programs that are not only functional but also safe, resilient, and trustworthy. You will revisit your earlier projects through a security lens, build new defensive habits, and complete two major capstones: Securing PyDo CLI and Secure Password Vault CLI. By the end, you will understand how to identify risks, apply secure patterns, and design Python applications that defend themselves.
Part I: The Security Mindset
- 1. Why Security Matters in Every Python Project
- 2. Thinking Like an Attacker
- 3. Common Misconceptions About Security
- 4. The Build Improve Secure Cycle
- 5. Security by Design Prevention Over Reaction
- 6. From Bugs to Breaches
Part II: Secure Coding Fundamentals
- 7. What Is Secure Coding
- 8. Principles of Defensive Programming
- 9. Understanding Common Vulnerabilities
- 10. Input Validation Fundamentals
- 11. Sanitizing and Normalizing Input Data
- 12. Output Encoding and Escaping
- 13. Secure Use of Exceptions
- 14. Handling Errors Without Leaking Data
- 15. Managing Dependencies Responsibly
- 16. Safe Use of Third-Party Libraries
Part III: Securing Python Foundations
- 17. Secure File Handling Basics
- 18. Avoiding Path Traversal Attacks
- 19. Safe Directory Operations
- 20. Handling Configuration Files Safely
- 21. Secrets and Environment Variables
- 22. Secure Logging Practices
- 23. Logging Dos and Donts
- 24. Safe Use of Temporary Files
- 25. Dependency Management with Hashes
- 26. Version Pinning and Reproducible Environments
Part IV: Cryptography and Data Protection
- 27. The Dangers of Eval and Exec
- 28. Pickle and Serialization Risks
- 29. Safer Alternatives to Pickle
- 30. Introduction to Cryptographic Hashing
- 31. Hashing Passwords and Sensitive Data
- 32. Randomness and Secure Token Generation
- 33. Secure Storage and Key Management
- 34. Secure JSON and YAML Handling
Part V: System and Network Security
- 35. Safe Subprocess and OS Interactions
- 36. Secure Use of External Tools and Shells
- 37. Safe Network Requests and APIs
- 38. Validating and Sanitizing Network Data
- 39. Dependency Vulnerabilities and CVEs
- 40. Awareness: Supply Chain Security
Part VI: Injection Families
- 41. SQL Injection Intro
- 42. Command Injection Intro
- 43. Code Injection in Python Intro
- 44. Path Injection and File Exploits
Part VII: Web and Application Security Awareness
- 45. Cross Site Scripting (XSS Intro)
- 46. Cross Site Request Forgery (CSRF Intro)
- 47. Authentication and Password Handling Basics
- 48. Session Management and Token Safety
- 49. Secure Input and Output Design in Web Contexts
Part VIII: Capstone 1 - Securing PyDo CLI
- 50. Project Overview
- 51. Identifying Security Gaps
- 52. Designing for Secure Input and Output
- 53. Implementing Safe File Storage
- 54. Logging and Error Management
- 55. Secrets and Environment Integration
- 56. Testing for Security and Resilience
- 57. Hardening and Packaging the Project
- 58. Review and Reflection
- 59. The Secure Python Mindset Applied
Part IX: Capstone 2 - Secure Password Vault CLI
- 60. Project Overview
- 61. Designing a Secure CLI App
- 62. Implementing Encryption and Secrets Management
- 63. Secure Input Handling and Validation
- 64. Logging and Error Handling Without Leaks
- 65. Testing and Verifying Security Features
- 66. Final Wrap Up Security Checklist
By completing this volume, you will be able to identify vulnerabilities, design safe workflows, and write code that defends itself across all Python environments.