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
Intro
Secure Coding
Secure coding is the practice of preventing weaknesses in software before those weaknesses become exploitable vulnerabilities. It connects security requirements to concrete implementation decisions: what data the program trusts, which operations it permits, how it represents secrets, and what happens when a check fails.
The work begins before a developer types a function. A team identifies assets, actors, trust boundaries, and misuse cases. Those findings become testable security requirements. Code then enforces the requirements with small, reviewable controls. Tests, code review, and analysis tools supply evidence that the controls work. Production findings return to the backlog so the same weakness class can be prevented in related code.
This cycle fits inside any software development lifecycle. NIST's Secure Software Development Framework groups the broader work into preparing the organization, protecting software, producing well-secured software, and responding to vulnerabilities. Secure coding sits mainly in production, but it depends on requirements, protected build systems, review, testing, release integrity, and feedback after deployment.
The control path
An application receives data from users, files, APIs, message queues, databases, and operating-system services. Each boundary can introduce data that does not match the program's assumptions. Treat external data as untrusted until a control establishes the property required for the next operation.
A useful control path is:
- Classify the boundary. Identify the caller, data origin, expected format, and authority.
- Validate the value. Enforce type, length, range, structure, and business rules as early as practical.
- Authorize the action. Check the authenticated subject against the requested object and operation on every protected request.
- Use a safe interface. Keep data separate from commands with parameterized queries, structured APIs, and context-aware output encoding.
- Limit the effect. Run with the least privilege and constrain file, network, process, memory, and resource access.
- Handle failure safely. Reject incomplete or ambiguous operations without exposing secrets or leaving partial state.
- Record useful evidence. Log security-relevant events without placing credentials, tokens, or sensitive payloads in logs.
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
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
