Secure Coding
Apply language-level and framework-level practices that eliminate whole vulnerability classes.
BeginnerSecure CodingApplication
Where it fits in the lifecycle
- Plan
- Code
- Build
- Test
- Release
- Deploy
- Operate
- Monitor
- Plan Threat modeling, requirements and security design decisions.
- Code Static analysis, secret detection and secure coding practices.
Overview
Secure coding is mostly about defaults: parameterised queries, output encoding by the template engine, validated input at boundaries, and safe-by-construction APIs rather than developer vigilance.
Why it matters
A framework that makes the safe path the default removes an entire class of findings from every future scan.
How it works
- 01Identify the vulnerability classes relevant to the stack.
- 02Choose APIs and framework settings that make the unsafe form hard to write.
- 03Encode the rule as a linter or SAST check so it stays enforced.
Common tools
SemgrepSonarQubeESLintPythonGitHubLinux
Implementation examples
pythonParameterised query
# Unsafe: string interpolationcur.execute(f"SELECT * FROM users WHERE email = '{email}'") # Safe: parameter bindingcur.execute("SELECT * FROM users WHERE email = %s", (email,))Best practices
- Validate at the boundary and use typed models.
- Prefer allow-lists over deny-lists.
- Turn each incident into a lint rule.
Common mistakes
- Relying on code review alone to catch known unsafe patterns.