Key takeaway
- Secure coding practices for 2027: a checklist mapped to OWASP Top 10:2025 and ASVS 5.0, NIST SSDF, safe use of AI coding assistants and secure code review.
Secure coding practices are the habits, rules and checks that stop developers writing exploitable flaws into software: validating input, encoding output, enforcing access control on the server, handling secrets and errors safely, and controlling third-party code. In 2026 the reference points are the OWASP Top 10:2025 for the risks, OWASP ASVS 5.0 for testable requirements, and the NIST Secure Software Development Framework (SSDF, SP 800-218) for the organisation-wide process.
This guide gives enterprise engineering and security leaders a checklist mapped to those standards, what changed with AI coding assistants, and how to run secure code review without slowing delivery. Secure coding is one layer of a wider programme: pair it with the testing methods in our guide to types of security testing and the pipeline gates described in DevSecOps pipeline, tools and governance.
What are secure coding practices and why do they still matter?
Secure coding means writing software so that known classes of vulnerability cannot appear in it, rather than finding them later. Most serious weaknesses are still simple coding errors. The 2025 CWE Top 25 Most Dangerous Software Weaknesses from MITRE is led by cross-site scripting (CWE-79), SQL injection (CWE-89), cross-site request forgery (CWE-352), missing authorisation (CWE-862) and out-of-bounds write (CWE-787). Each of these is prevented at the point where code is written, by a consistent pattern rather than a heroic test.
No programming language is secure by default. Memory-safe languages remove whole classes of flaw such as out-of-bounds writes, but injection, broken access control and weak secret handling appear in every language. That is why secure coding is a team standard, backed by tools and review, and not a matter of individual skill.
What has changed in secure coding since 2023?
Several of the standards teams rely on were revised in 2025, and AI coding assistants changed how much code reaches review. If your secure coding guideline still cites the 2021 OWASP Top 10 or ASVS 4.0, it needs updating.
| Reference | What changed | Current status (read 11 Nov 2026) |
| OWASP Top 10:2025 | New categories A03 Software Supply Chain Failures and A10 Mishandling of Exceptional Conditions; Broken Access Control remains A01 | Current edition |
| OWASP ASVS 5.0.0 | Restructured verification requirements for web applications and APIs | Stable release, published 30 May 2025 |
| NIST SSDF 1.1 (SP 800-218) | Draft SSDF 1.2 (SP 800-218 Rev. 1) published 17 Dec 2025 | 1.1 is final (Feb 2022); 1.2 is an initial public draft, comments closed 30 Jan 2026 |
| NIST SP 800-218A | Community profile adding secure development practices for generative AI and dual-use foundation models | Final |
| OWASP Secure Coding Practices Quick Reference Guide | Project archived; its checklists migrated to the OWASP Developer Guide | Use the OWASP Developer Guide (version 4.x) |
| OWASP Top 10 for LLM Applications 2025 | Covers prompt injection, improper output handling, excessive agency and other LLM-specific risks | Current edition |
Which secure coding best practices matter most?
The practices below map directly to the OWASP Top 10:2025 categories, so a team that follows them is addressing the risks auditors and customers ask about.
| Practice | OWASP Top 10:2025 risk | What it looks like in code |
| Enforce access control on the server | A01 Broken Access Control | Check authorisation on every request and object, deny by default, never trust IDs or roles sent by the client |
| Secure configuration as code | A02 Security Misconfiguration | Hardened defaults, no debug endpoints in production, configuration reviewed like code |
| Control dependencies and build inputs | A03 Software Supply Chain Failures | Pin versions, verify packages exist and come from trusted registries, keep an SBOM, scan with SCA |
| Use current cryptography and protect secrets | A04 Cryptographic Failures | Use vetted libraries, TLS for all traffic, secrets in a vault, never in source or logs |
| Validate input and encode output | A05 Injection | Parameterised queries, allow-list validation, context-aware output encoding |
| Threat model before you build | A06 Insecure Design | Map data flows and trust boundaries, decide controls at design time |
| Use proven authentication and sessions | A07 Authentication Failures | Use the platform identity provider, MFA, secure session tokens, rate limiting |
| Verify integrity of code and data | A08 Software or Data Integrity Failures | Signed artefacts, safe deserialisation, protected CI/CD pipelines |
| Log security events safely | A09 Security Logging and Alerting Failures | Log authentication and authorisation decisions, never log secrets or personal data, alert on anomalies |
| Handle errors and exceptions safely | A10 Mishandling of Exceptional Conditions | Fail closed, return generic errors to users, keep detail in protected logs |
Never trust input, from users or from systems
Every value that crosses a trust boundary, whether from a form, an API call, a file, a message queue or an LLM response, should be validated against what is expected and encoded for the context where it is used. Injection and cross-site scripting, the top two entries in the 2025 CWE Top 25, both come from skipping this step. Parameterised queries and framework-provided encoding remove most of the risk with very little effort.
Threat model early
Threat modelling finds the weak spots before code exists. Document how data flows through the application, mark each trust boundary, list what could go wrong at each one, and decide the control. Repeat it when the design changes, for example when a new integration, AI agent or external API is added.
Automate the checks that humans miss
Static analysis (SAST), software composition analysis (SCA) and secret scanning should run on every pull request, so developers fix issues while the code is fresh. Examples include Bandit, "a tool designed to find common security issues in Python code", GitHub code scanning with the CodeQL engine, and SonarQube Server or SonarQube Cloud. Our post on Kubernetes security automation shows the same principle applied to the platform layer.
What should a secure coding checklist include?
Use OWASP ASVS 5.0 as the source of testable requirements and keep a short checklist for daily work. A practical checklist for each change:
- Input and output: all external input validated with allow-lists; queries parameterised; output encoded for HTML, JavaScript, SQL or shell context.
- Authentication: platform identity provider used; MFA for privileged users; passwords hashed with an approved algorithm if stored at all.
- Sessions: secure, HttpOnly and SameSite cookies; sessions expire and are invalidated on logout.
- Access control: authorisation checked server-side on every request and every object; deny by default.
- Data protection: TLS for all traffic; sensitive data encrypted at rest; secrets held in a vault.
- File uploads: type and size checked, files stored outside the web root, names generated by the server.
- Errors and logging: generic error messages to users; security events logged without secrets or personal data.
- Dependencies: versions pinned; SCA clean or exceptions approved; new packages checked for existence and reputation.
- Configuration: debug off in production; security headers set; infrastructure as code reviewed.
- AI-generated code: labelled in the pull request and held to the same review and scanning gates.
How does NIST SSDF fit with secure coding?
Secure coding is what developers do; the SSDF is how the organisation proves it happens consistently. The SSDF groups its practices into four areas: Prepare the Organization (PO), Protect the Software (PS), Produce Well-Secured Software (PW) and Respond to Vulnerabilities (RV). Secure coding standards, code review and automated testing sit mainly in PW; protecting source and build integrity sits in PS; and a working vulnerability intake and fix process sits in RV.
For teams that build or fine-tune AI models, NIST SP 800-218A adds practices for generative AI and dual-use foundation models on top of SP 800-218. Track the SSDF 1.2 draft, but build against the final 1.1 until 1.2 is published.
How should teams use AI coding assistants securely?
AI assistants write code quickly, but the evidence is that they do not write secure code by default. In the study "Asleep at the Keyboard?" (IEEE Symposium on Security and Privacy 2022), researchers generated 1,689 programs across 89 scenarios with GitHub Copilot and found approximately 40% to be vulnerable. Veracode's 2025 GenAI Code Security Report (October 2025 update) reports that AI-generated code introduced risky security flaws in 45% of tests across more than 100 large language models.
Assistants also invent dependencies. A study of package hallucinations, to appear at USENIX Security 2025, found that on average at least 5.2% of packages suggested by commercial models and 21.7% by open-source models did not exist, with 205,474 unique hallucinated package names. An attacker who registers one of those names can get malicious code installed, which is a direct route into OWASP A03 Software Supply Chain Failures.
| AI coding risk | Control |
| Generated code contains classic flaws (injection, missing authorisation) | Treat AI output as untrusted code: same SAST, SCA and human review gates as any other change |
| Hallucinated or typo-squatted packages | Allow-list registries, check that new packages exist and are maintained, pin versions |
| Coding agents with broad permissions (OWASP LLM06 Excessive Agency) | Least-privilege tokens, no direct push to protected branches, sandboxed execution |
| Prompt injection through repository content or issues (OWASP LLM01) | Do not let agents act on untrusted text without review; log agent actions |
| Unvalidated model output reaching interpreters or queries (OWASP LLM05 Improper Output Handling) | Validate and encode model output like user input |
AI can also help fix flaws. GitHub describes Copilot Autofix as generating fix suggestions for CodeQL alerts, and states that it "may suggest fixes that fail to remediate the underlying vulnerability" and that you "must always review suggestions". SonarQube says it checks AI-generated code with the same rules and quality gates as developer-written code. The lesson is consistent: AI speeds up both writing and fixing, and review remains the control. When agents start to write and merge code, ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control.
How do you run an effective secure code review?
Code review is where a second person checks that the change does what it should and nothing it should not. For security, reviewers should focus on trust boundaries, authorisation checks, query and command construction, secret handling, error paths and any new dependency.
Keep reviews small and time-boxed
As reported by SmartBear from its research with a Cisco development team, developers should review no more than 200 to 400 lines of code at a time, and a review of 200 to 400 lines over 60 to 90 minutes should yield 70 to 90% defect discovery. Beyond 400 lines, the ability to find defects diminishes. Large AI-generated changes should be split before review for the same reason.
Let tools do the first pass
Run SAST, SCA and secret scanning before a human looks at the change, so reviewers spend time on logic, design and authorisation, which tools find hardest. The tool categories and when each fits are compared in our security testing guide.
Use a short security review checklist
- Does every new endpoint or function check who is calling and what they may access?
- Is any external input used in a query, command, file path or template without validation and encoding?
- Are secrets, tokens or personal data written to code, logs or error messages?
- What happens when this code fails: does it fail closed?
- Are new dependencies needed, real, pinned and approved?
- Was any part generated by AI, and has it been read line by line?
Build a blameless review culture
Reviews work when findings are treated as learning, not blame. Track recurring findings and turn them into linter rules, secure defaults in shared libraries or short training, so the same flaw is not found twice.
How should leaders govern secure coding?
Secure coding becomes reliable when it is owned, measured and auditable. Leaders should set one secure coding standard based on ASVS 5.0 and the OWASP Developer Guide, make security gates part of the definition of done, and measure outcomes such as time to fix critical findings, the share of repositories with SAST and SCA gates, and recurring finding types. Regulation is raising the bar: the EU Cyber Resilience Act entered into force on 10 December 2024, with reporting obligations from 11 September 2026 and main obligations from 11 December 2027 for products with digital elements. More of the guidance is covered in our application security best practices guide.
As AI agents start to change code and infrastructure, the same governance has to cover their actions. Elixir Govern (formerly AgentGRC) keeps autonomous agent actions inside policy, with the audit trail risk teams need, and MetaSecure offers an agentic SOC with AI agents, including a red teaming agent to simulate adversaries and harden systems.
What is a practical adoption sequence?
- Set the standard: adopt OWASP Top 10:2025 as the risk list and ASVS 5.0 as the requirement source; retire older internal guidelines.
- Automate the basics: secret scanning, SCA and SAST on every pull request, starting with blocking only critical findings.
- Secure the defaults: shared libraries for authentication, authorisation, encoding and logging so the secure path is the easy path.
- Add threat modelling for new services and major design changes.
- Write rules for AI assistants and agents: labelling, package checks, least-privilege tokens and mandatory review.
- Map to the SSDF and keep evidence for customers and regulators.
- Measure and improve: track time to fix and recurring findings, and tighten gates as the backlog falls.
What are the trade-offs, and when should you not add more controls?
Every gate adds friction. Blocking builds on low-severity findings trains developers to ignore tools, so start strict only on critical issues and tune rules to cut false positives. Full threat models are not needed for every small change; reserve them for new services, new trust boundaries and sensitive data. Manual review of every line is not practical at AI-assisted speed, so concentrate human attention on authorisation, data handling and dependency changes, and let automation cover the rest. The aim is fewer exploitable flaws in production, not the largest number of controls.
To map one secure coding or code review decision your agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
What should you plan for in 2027?
Regulation is the main dated item for secure coding teams. The European Commission's page on the EU Cyber Resilience Act gives these dates, read on 15 November 2026.
- 11 December 2027: the main obligations of the Act apply, so products with digital elements sold in the EU need their secure development evidence ready before then.
- 11 September 2026: reporting obligations already apply, so vulnerability intake and reporting processes should be running now.
Use the SSDF mapping and ASVS checklist above as the evidence trail, and ask legal counsel how the Act applies to your products.
Frequently asked questions about secure coding practices
What are secure coding practices?
They are the rules and checks that prevent developers writing exploitable flaws: validating input, encoding output, enforcing server-side access control, protecting secrets, handling errors safely and controlling dependencies.
Which standard should a secure coding checklist follow in 2026?
Use the OWASP Top 10:2025 for risk awareness, OWASP ASVS 5.0.0 (published 30 May 2025) for testable requirements, and the NIST SSDF (SP 800-218) for the organisation-wide process.
Is the OWASP Secure Coding Practices Quick Reference Guide still current?
No. OWASP has archived the project, and its checklists have been migrated to the OWASP Developer Guide.
Is AI-generated code secure?
Not by default. Research on GitHub Copilot found about 40% of generated programs vulnerable, and Veracode's 2025 report found risky flaws in 45% of tests. Treat AI output as untrusted code and apply the same scanning and review.
How many lines of code should a secure code review cover?
SmartBear's research with a Cisco team recommends no more than 200 to 400 lines at a time, over 60 to 90 minutes.
What is new in the OWASP Top 10:2025?
It adds A03 Software Supply Chain Failures and A10 Mishandling of Exceptional Conditions, while Broken Access Control stays at A01.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE