Join our Newsletter — 33% off our NHI Course
Home› Guides› Secure Coding Standard Template: Language-Neutral Rules for Auth,…
Template Application Security

Secure Coding Standard Template: Language-Neutral Rules for Auth, Secrets and Input

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 11 November 2026 11 min read
On this page

A secure SDLC policy says that code must be written securely; a secure coding standard says exactly what that means, in rules a developer can follow and a reviewer or scanner can check. This template gives [Organisation] a language-neutral standard with numbered rules for authentication, authorisation, secrets, input and output handling, errors and logging, and dependencies, each with a conformance level and a verification method. Language-specific annexes then add the idioms for each stack. It is for application security leads, engineering managers and security champions who need a standard that auditors can trace and developers will actually use. The background on why each rule matters is in the Secure Coding Guide; the policy that requires a standard is in the Secure SDLC Policy Template.

How to use this template

  • Keep the rule IDs stable: scanners, review checklists, training and exceptions will reference them, so retire IDs rather than renumbering.
  • Set the conformance levels: "Must" rules block a merge when broken; "Should" rules are expected unless a reason is recorded in the pull request. Adjust the split to your risk appetite, but keep every Must rule checkable.
  • Fill the placeholders: [square brackets] mark choices [Organisation] makes, such as the approved secrets manager, password hashing function or logging library.
  • Add language annexes, do not fork the core: section 11 is where Java, Go, Python or TypeScript specifics go, so the core rules stay the same across teams.
  • Map rules to tools: fill the "Verified by" column with the actual static analysis rule, test or review item, so every Must rule has an automated or recorded check.

1. Purpose

This standard defines the minimum secure coding rules for software developed by or for [Organisation]. It implements the secure development requirements of the [Secure SDLC Policy] and supports [NIST SP 800-218 (SSDF) practice PW.5, other frameworks [Organisation] follows, and customer contractual requirements].

2. Scope

  • All application, service, infrastructure-as-code and script code in repositories owned by [Organisation], including code produced by AI coding assistants and agents.
  • Code delivered by contractors and suppliers under [Organisation] contracts.
  • Out of scope: [prototypes in isolated sandboxes with no real data or credentials, as defined in the Vibe Coding Policy]. See the Vibe Coding Policy Template.

3. Roles and responsibilities

RoleResponsibility
[Head of Application Security]Owns this standard, approves changes and deviations for Must rules
Engineering managersEnsure teams are trained and that pipelines enforce the checks
Developers (and anyone merging AI-generated code)Follow the rules; the person who merges code is accountable for it, whoever or whatever wrote it
Reviewers and security championsCheck Should rules and judgement-based Must rules in review
Platform teamMaintains scanner configuration mapped to rule IDs

4. Rule format and conformance

Each rule has an ID (area prefix and number), a statement, a level (Must or Should) and a verification method: SAST (static analysis rule), SCAN (secret or dependency scanning), TEST (automated test), or REVIEW (manual review item). Rules reference OWASP ASVS 5.0 requirements so the standard can be traced to a verification level.

5. Authentication and sessions (AUTH)

IDRuleLevelVerified byASVS 5.0
AUTH-01Use [Organisation's identity provider] for user login; do not build custom password authentication without [Head of AppSec] approvalMustREVIEWNot mapped
AUTH-02Every endpoint that changes data or returns non-public data requires authentication, declared through the framework's central mechanism, not per handlerMustSAST, TESTV6.3.4
AUTH-03Where passwords are stored locally, hash them only with [approved password hashing function and parameters]MustSASTV11.4.2
AUTH-04Validate token signature, algorithm allowlist, issuer, audience and expiry before using any claimMustTESTV9.1.1, V9.1.2, V9.2.1, V9.2.3
AUTH-05Issue a new session identifier at login and invalidate it server-side at logoutMustTESTV7.2.4, V7.4.1
AUTH-06Login and reset responses do not reveal whether an account existsShouldTESTV6.3.8
AUTH-07No default, test or backdoor accounts or bypass flags in production buildsMustSAST, REVIEWV6.3.2

6. Authorisation (AUTHZ)

IDRuleLevelVerified byASVS 5.0
AUTHZ-01Deny by default: every route or function declares the permission it requiresMustSAST, TESTV8.2.1
AUTHZ-02Check object ownership or entitlement for every identifier taken from a requestMustTEST, REVIEWV8.2.2
AUTHZ-03Enforce authorisation on the server; client-side checks are for usability onlyMustREVIEWV8.3.1
AUTHZ-04Bind request data to explicit allowlists of fields per action (no mass assignment)MustSASTV15.3.3
AUTHZ-05Decisions for delegated calls use the originating user's permissionsShouldREVIEWV8.3.3
AUTHZ-06Use the shared authorisation library [name]; do not hand-write role checksShouldSASTNot mapped

See the Broken Access Control Prevention Guide and the Authorisation Models Guide.

7. Secrets and cryptography (SEC)

IDRuleLevelVerified byASVS 5.0
SEC-01No secrets in source code, tests, configuration files, container images, build arguments or commentsMustSCAN (pre-commit and CI)V13.3.1
SEC-02Read secrets at runtime from [approved secrets manager]; prefer mounted files or in-memory retrieval over environment variablesMustREVIEWV13.3.1
SEC-03Each workload identity can read only the secrets it needs; production and non-production secrets are separateMustREVIEWV13.3.2
SEC-04Prefer short-lived, dynamically issued credentials (workload identity, OAuth client credentials with short tokens) over static keysShouldREVIEWV13.2.1
SEC-05Never log, print or return secrets or tokens; mask them in error outputMustSAST, REVIEWV16.5.1
SEC-06Use [approved crypto library] and approved algorithms only; no custom cryptographyMustSASTV11.4.1
SEC-07Generate tokens, identifiers and codes with a cryptographically secure random generatorMustSASTV11.5.1
SEC-08Never disable TLS certificate validation, including in test code that can reach productionMustSASTV12.3.2

A secret committed to a repository is treated as exposed and rotated, even if the commit is reverted. See the Secrets Management Guide and the Git Secret Scanning Guide.

8. Input and output handling (IO)

IDRuleLevelVerified byASVS 5.0
IO-01Validate all input server-side against an allowlist of type, length, range and formatMustREVIEW, TESTV2.2.1, V2.2.2
IO-02Use parameterised queries or the ORM's safe API; never build queries by string concatenationMustSASTV1.2.4
IO-03Do not invoke a shell with input; use APIs that take arguments as a listMustSASTV1.2.5
IO-04Encode output for its context using the framework's auto-escaping; document any place it is switched offMustSAST, REVIEWV1.2.1
IO-05Do not deserialise untrusted data into arbitrary types; disable external entities in XML parsersMustSASTV1.5.1, V1.5.2
IO-06Server-side requests to URLs influenced by input use a destination allowlist and do not follow redirects by defaultMustREVIEW, TESTV13.2.4, V15.3.2
IO-07Uploaded files are checked for type, size and archive limits and stored outside the web rootMustTESTV5.2.1, V5.2.2, V5.2.3
IO-08Return only the fields the caller needs, not whole data objectsShouldREVIEWV15.3.1

See the Input Validation and Output Encoding Guide and the SSRF Prevention Guide.

9. Errors and logging (LOG)

IDRuleLevelVerified byASVS 5.0
LOG-01Return generic error messages to callers; keep detail in server logsMustTESTV16.5.1
LOG-02Fail closed: an exception in an authorisation, payment or approval step stops the actionMustREVIEW, TESTV16.5.3
LOG-03Log authentication outcomes and authorisation failures through [logging library] with user, time and sourceMustTESTV16.3.1, V16.3.2
LOG-04Do not log secrets, session tokens or full payment or health dataMustSAST, REVIEWV16.2.5
LOG-05Debug modes and verbose errors are off in production configurationMustTESTV13.4.2

See the Secure Error Handling and Logging Guide.

10. Dependencies, configuration and non-human identities (DEP)

IDRuleLevelVerified byASVS 5.0
DEP-01Install packages only from [approved registry or proxy]; verify that AI-suggested packages exist and are the intended onesMustSCANV15.2.4
DEP-02Keep a software bill of materials for every deployable artefactMustSCANV15.1.2
DEP-03Fix vulnerable components within the remediation windows in [Vulnerability Management Standard]MustSCANV15.1.1, V15.2.1
DEP-04Production builds exclude test code, sample data and source control metadataMustTESTV13.4.1, V15.2.3
DEP-05Every service account, API key or workload identity the code introduces has a named owner, a purpose and least privilege scopes, recorded in [inventory]MustREVIEWV13.3.2

See the Service Account Security Guide.

11. Language annexes

Each annex lists, for one language or framework: the approved libraries for the placeholders above, the safe and banned APIs, and the scanner rules mapped to each core rule ID. Start from the relevant NHI Mgmt Group language guide:

12. Deviations

  • A Must rule may be broken only with a recorded deviation: rule ID, location, reason, compensating control, approver ([Head of AppSec]) and expiry date no later than [12 months].
  • A Should rule may be departed from with a reason recorded in the pull request.
  • Deviations are reviewed [quarterly]; expired deviations block the next release of the affected component. See the Security Exceptions and Risk Acceptance Guide.

13. Review and approval

This standard is reviewed at least [annually], after any vulnerability class reaches production, and when OWASP ASVS or the CWE Top 25 is revised. Owner: [Head of Application Security]. Approved by: [CISO], [date]. Version: [1.0].

Implementation guidance

  1. Map before you mandate: for each Must rule, confirm a scanner rule, test or review item exists in every language you use. Rules with no check become Should until one does.
  2. Run in report mode first: enable the scanner rules in non-blocking mode for [four weeks], measure findings per rule and fix false positives.
  3. Block on a small core: start with SEC-01, IO-02, IO-03 and AUTHZ-01 as blocking gates, then add rules as the false positive rate falls.
  4. Train on the standard, not on generic content: use the rule IDs in onboarding and in review comments. See the Developer Security Training Programme Guide.
  5. Roll back safely: if a blocking rule stalls delivery, return it to report mode with an owner and date, rather than deleting it.

Choosing the level of prescription

SituationApproach
Small team, one or two languagesCore rules plus one annex; reviewers check REVIEW items with the pull request template
Many teams and stacksCore rules owned centrally, annexes owned by language guilds, scanner configuration shared as code
Regulated or high-assurance softwareMap every rule to ASVS Level 2 or 3, keep evidence of each check per release
Heavy use of AI coding toolsAdd DEP-01 and SEC-01 as blocking gates first; generated code follows the same rules

Metrics

  • Share of Must rules with an automated check in each language.
  • Findings per rule ID per thousand lines changed, by team.
  • Open deviations, and deviations past expiry.
  • Production vulnerabilities traced to a rule that existed but was not enforced.

Framework mapping

FrameworkReference
NIST SP 800-218 (SSDF 1.1)PW.5 Create source code by adhering to secure coding practices
NIST SP 800-53 Rev 5SA-15 Development Process, Standards, and Tools; SA-11 Developer Testing and Evaluation; SI-10 Information Input Validation
NIST CSF 2.0PR.PS-06
OWASP Top 10 Proactive Controls 2024C1 access control, C2 cryptography, C3 input and exceptions, C6 components, C7 digital identities, C9 logging, C10 SSRF

Common failure patterns

  • A standard nobody can check: rules phrased as advice ("be careful with input") that no scanner or reviewer can test.
  • Copying a language standard wholesale: hundreds of rules, most irrelevant, so developers ignore the lot.
  • No owner for annexes: the core is approved but the language-specific mapping never gets written.
  • Permanent deviations: exceptions with no expiry become the real standard.

Standards and references

Related NHI Mgmt Group resources: Secure Coding Guide · Secure SDLC Policy Template · Secure Code Review Guide · OWASP ASVS Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 11 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org