Secure Coding
Secure coding is the practice of preventing software weaknesses while you design, implement, review, and maintain code. It treats every trust boundary, privileged operation, and sensitive value as an explicit security decision.
itOffensive security and application security | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Secure Coding
Secure coding is the habit of making a program state exactly what it trusts, what it permits, and what it does when reality arrives wearing a false moustache. The point is not to sprinkle security dust over finished code. It is to turn assumptions into controls and tests before they become vulnerabilities.
Start with a sensitive operation. Changing an account, reading a record, spending a balance, running a query, or rendering a comment all have a moment when data or authority can cause an effect. That moment is the trust boundary: data or control moves between components with different assumptions. Treating every incoming value as friendly because it came from a form is how an application develops an exciting private life.
Three distinctions do much of the work. Validation asks whether a value has the required type, size, structure, and business meaning. Authorization asks whether the authenticated subject may perform this action on this object. And a safe interface keeps data separate from instructions: parameterized queries for SQL, structured process arguments instead of shell strings, and output encoding for the browser context actually in use. One control cannot impersonate the others convincingly.
The surprise is that security bugs often live between individually sensible steps. A token can be checked and then reused. An account can be authorized and then swapped before the write. A retry can arrive while the first request is still deciding what happened. Those are security invariants, conditions that must remain true across every allowed state change. Put the check and the change together when a race could open a gap.
Tools help, but none receives a cape. Linters catch local rules. Static analysis follows repeated patterns and some data flows. Fuzzing worries parsers and state machines. Manual review notices business intent and authority. A scanner finding is a hypothesis; follow its source, path, sink, and consequence before deciding what to repair. Then add a regression test and look for siblings, because bugs enjoy company.
Read the intro when you need the full control path and its limits. Use the slides when the distinctions need to stay in your head. Keep the cheatsheet nearby when a boundary reaches SQL, a process, a browser, a secret, or a state transition. The practice reference turns one sensitive operation into a review sequence, and the exercise lets an isolated training application supply the deliberately bad example. That is considerably kinder than discovering one in a service that mattered.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://csrc.nist.gov/pubs/sp/800/218/final
Supports
- Secure coding within a complete software development lifecycle
- SSDF practice groups and shared vocabulary
- Root-cause remediation, verification, and vulnerability response
- Publication of SSDF version 1.1 in February 2022
- https://csrc.nist.gov/projects/ssdf
Supports
- Publication of SSDF version 1.0 in April 2020
- Integration of high-level secure practices into existing lifecycle models
- https://owasp.org/www-project-secure-coding-practices-quick-reference-guide/
Supports
- Technology-agnostic secure coding practice categories
- Secure coding as lifecycle-integrated requirements and implementation guidance
- https://owasp.org/www-project-application-security-verification-standard/
Supports
- Verifiable application-security requirements
- Uses for implementation guidance, testing, metrics, and procurement
- https://cheatsheetseries.owasp.org/
Supports
- Control-specific implementation guidance across secure coding topics
- Reference path rationale for implementation study
- https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
Supports
- Early validation of all untrusted sources
- Syntactic and semantic validation
- Validation does not replace injection prevention or output encoding
- https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
Supports
- Parameterized queries separate SQL structure from bound data
- Avoidance of query construction through string concatenation
- https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
Supports
- Context-aware output encoding
- Different encoding rules for HTML, attributes, URLs, CSS, and JavaScript
- https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html
Supports
- Default-deny authorization and permission checks on every request
- Server-side enforcement of object and function access
- https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html
Supports
- Separation of authentication from authorization
- Reauthentication for defined sensitive operations
- https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html
Supports
- Random session identifiers, lifecycle limits, rotation, and invalidation
- Protection of authenticated session state
- https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
Supports
- Password hashing rather than reversible password storage
- Salts and adjustable work factors
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
Supports
- Keeping secrets outside source code and logs
- Least-privilege access and rotation practices
- https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html
Supports
- Maintained cryptographic libraries and approved constructions
- Key separation and definition of protection requirements
- https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html
Supports
- Security-relevant logging without credentials, tokens, or key material
- Separation of external error detail from protected diagnostics
- https://cheatsheetseries.owasp.org/cheatsheets/Secure_Code_Review_Cheat_Sheet.html
Supports
- Security-focused manual review of boundaries and controls
- Review coverage for authentication, authorization, validation, encoding, and sensitive operations
- https://owasp.org/www-project-developer-guide/
Supports
- Developer guidance spanning foundations, design, implementation, verification, and operations
- Migration of secure coding practice material into current guidance
- https://devguide.owasp.org/en/07-training-education/05-top-ten/
Supports
- OWASP Top 10 as an awareness document
- Original publication in 2003 and later revision history
- https://cwe.mitre.org/
Supports
- Shared names, relationships, and guidance for weakness classes
- https://cwe.mitre.org/top25/index.html
Supports
- Recurring impactful weakness classes and root-cause prioritization
- https://cwe.mitre.org/data/definitions/367.html
Supports
- Time-of-check to time-of-use race conditions
- Need to limit change between a security check and resource use
- https://cwe.mitre.org/data/definitions/636.html
Supports
- Security consequences of failing open when a decision cannot complete
- https://cwe.mitre.org/about/history.html
Supports
- PLOVER work in 2005 and first CWE release in 2006
- Mobile content added in 2014 and hardware weakness support added in 2020
- https://wiki.sei.cmu.edu/confluence/display/seccode/SEI+CERT+Coding+Standards
Supports
- Language-specific actionable secure coding rules and examples
- https://wiki.sei.cmu.edu/confluence/display/c/History
Supports
- Origin of the CERT C standard project in 2006
- Community development of actionable guidance for C programmers
- https://www.sei.cmu.edu/library/cert-c-secure-coding-standard/
Supports
- First official CERT C Secure Coding Standard in October 2008
- Rules, insecure examples, and secure alternatives for C weaknesses
- https://www.cisa.gov/securebydesign
Supports
- Producer responsibility for secure defaults and customer security outcomes
- Product-level placement of secure development practices
- https://owasp.org/blog/2024/04/21/owasp-foundation-20th-anniversary.html
Supports
- OWASP community origin in September 2001
- OWASP Foundation incorporation in April 2004
- https://www.microsoft.com/en-us/securityengineering/sdl/about
Supports
- Microsoft SDL mandatory adoption in 2004
- Public release of SDL guidance during 2006 to 2008
- https://www.whitehouse.gov/presidential-actions/2021/05/executive-order-on-improving-the-nations-cybersecurity/
Supports
- May 2021 direction for secure software development and supply-chain guidance
- https://github.com/sindresorhus/awesome
Supports
- Discovery of the curated Awesome AppSec list
- https://github.com/paragonie/awesome-appsec
Supports
- Discovery of Juice Shop, WebGoat, NodeGoat, and Cryptopals
- https://owasp-juice.shop/
Supports
- Intentionally insecure JavaScript application with security challenges
- Training and authorized security-tool evaluation
- https://owasp.org/www-project-webgoat/
Supports
- Deliberately insecure Java application with interactive lessons
- Authorized environment for learning and tool testing
- https://owasp.org/www-project-node.js-goat/
Supports
- Node.js environment for learning, fixing, and testing OWASP risks
- https://cryptopals.com/
Supports
- Programming exercises that demonstrate attacks on cryptographic constructions
- https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql
Supports
- CodeQL analysis, repository integration, and pull-request findings
- GitHub Code Security landscape entry
- https://semgrep.dev/solutions/static-application-security-testing/
Supports
- Pattern and data-flow analysis near developer workflows
- Semgrep landscape entry
- https://docs.sonarsource.com/sonarqube-server/user-guide/security-related-rules/
Supports
- Distinction between vulnerabilities and security hotspots requiring review
- SonarQube landscape entry
- https://docs.snyk.io/scan-with-snyk/snyk-code
Supports
- Developer-facing static analysis and source findings
- Snyk Code landscape entry
- https://checkmarx.com/product/application-security-platform/
Supports
- Centralized application-security analysis, policy, and remediation workflows
- Checkmarx One landscape entry
- https://docs.veracode.com/r/c_static_overview
Supports
- Static application analysis in developer and release workflows
- Veracode Static Analysis landscape entry
- https://www.opentext.com/products/fortify-static-code-analyzer
Supports
- Static analysis, centralized policy, and language coverage
- OpenText Fortify landscape entry
- https://www.securecodewarrior.com/products/training
Supports
- Language- and framework-specific secure coding exercises
- Secure Code Warrior landscape entry
- https://googleprojectzero.blogspot.com/2021/12/this-shouldnt-have-happened.html
Supports
- NSS vulnerability postmortem showing how component fuzzing can miss a reachable end-to-end security path
- Need to exercise generated test objects through the security-sensitive operation
- https://engineering.fb.com/2020/08/07/security/pysa/
Supports
- Source-to-sink analysis, its false-positive and false-negative trade-offs, and its limits for authorization logic
- Security analysis feedback on proposed code changes and the need for manual context review
- https://help.owasp-juice.shop/appendix/code-snippets.html
Supports
- Juice Shop coding challenges that ask learners to identify vulnerable code and select an appropriate fix
- Local code-snippet and fix-option workflow for authorized secure-coding practice
