Safeguard
Security Guides•

How do you write a secure coding standard that SAST can enforce?

Write each rule as a checkable statement, tie it to a weakness type, and mark what a tool can enforce versus what needs review. A five step method.

Safeguard Security Team
7 min read

Write each rule as a short, checkable statement tied to a weakness type, then mark whether a tool can enforce it or a human must review it. A standard that says "validate all input" cannot be enforced. One that says "never build SQL by string concatenation" can be.

Why the standard comes first

NIST's Secure Software Development Framework says code review or analysis should be performed against the organization's secure coding standards, and that discovered issues be recorded and triaged in the team's workflow. That sentence assumes a standard exists. Without one, a scanner's default rule set becomes your standard by accident.

A five step method

  1. List the weakness types that matter to you. Start from your own incidents and from a public list such as the CWE Top 25, then trim to what applies to your stack.
  2. Write one rule per weakness, in plain words. Use verbs a developer can act on: use, never, always.
  3. Add a positive example and a negative example. Short code snippets from your own codebase help most.
  4. Classify enforcement. Mark each rule as tool enforced, review enforced or test enforced.
  5. Assign an owner and a review date. Standards rot when nobody owns them.

Example rules and how to classify them

RuleEnforcement
Never build SQL statements by joining strings with user inputTool, a data flow rule can check this
Never pass user input to a shell commandTool
Resolve file paths against an allowed base directoryTool plus review
Every route that returns account data must check ownershipReview and tests, static tools struggle here
Do not disable certificate checksTool, a simple pattern rule
Log security events with a request identifierReview

The pattern is useful. Rules about how untrusted data reaches a risky operation suit static analysis. Rules about what the application should allow suit review and tests. OWASP lists access control and authentication among the flaws that are very difficult to find automatically.

Map rules to tool rules

Once the standard exists, map each tool enforced rule to a rule or query in your scanner. Two outcomes are useful. A rule with no matching tool check is a gap you now know about. A tool check with no matching standard rule is noise you may be able to turn off.

Keep the mapping in a simple table: standard rule, scanner rule name, severity, action on a finding. Reviewing that table once a quarter is lightweight and keeps both sides honest.

Keep it short

A standard with sixty rules will not be read. Aim for a page that a new developer can finish in one sitting, with links to deeper guidance. Add rules when a real incident or repeated finding earns them a place.

A worked example: from vague rule to enforceable rule

Start with a common line in an old standard: "Developers must validate all input." It sounds good and cannot be checked. Here is how to rewrite it in steps.

  1. Identify the weakness: untrusted data reaching a database call.
  2. State the behavior: "Database queries must use parameterized statements. String concatenation with request data is not allowed."
  3. Add examples. Show a short unsafe snippet and a safe one from your own code.
  4. Classify enforcement: tool enforced, because a data flow rule can detect string built queries.
  5. Name the exception route: "Dynamic table names must come from an allow list defined in code and reviewed by the security champion."

The result is a rule a developer can follow, a tool can check, and a reviewer can audit. The original line gave none of those.

A sample page, structured

SectionContent
PurposeTwo sentences on why the standard exists
ScopeWhich repositories and languages it covers
RulesA numbered list, each with a rule, example and enforcement type
ExceptionsWho can approve and how it is recorded
OwnershipA named owner and a review date
Change logDated list of rule changes

Keep each rule to three or four lines. Link to a longer guide for background.

Choosing the first ten rules

Most teams get more value from ten good rules than from sixty. A simple way to pick:

  1. List weakness types behind your last year of security findings and incidents.
  2. Add the types from a public list such as the CWE Top 25 that apply to your stack.
  3. Remove anything the framework already prevents by design.
  4. Keep the ones where a developer needs a clear instruction.

Review the result with two or three developers before you publish it. They will tell you which rules are unclear or impractical.

Making the standard visible in the pipeline

A standard is more likely to be followed if the tool messages echo it. When a rule fires, the finding should reference the rule number, for example "Standard 4: use parameterized queries." Many tools let you attach custom messages or tags to rules. Even without that feature, a mapping table in the wiki works. The goal is that a developer who sees a finding can find the matching rule and a fix example within a minute.

Reviewing the standard against tool results

Every quarter, check three things:

CheckQuestionAction
Rules with no tool coverageIs there a gap?Add review steps or tests
Tool rules with no standardAre they noise?Disable or document
Rules often overriddenIs the rule unclear or the tool wrong?Rewrite or tune

This keeps the standard and the tooling in step, and it shows auditors that the document is alive.

Training and onboarding

Add the standard to onboarding. A thirty minute walkthrough with the ten rules and live examples from your codebase is enough. Refresh it when rules change. People follow rules they understand, and they understand rules they have seen applied in code they work on.

Standards and the SSDF

NIST's Secure Software Development Framework ties code analysis to your organization's secure coding standards, so having a documented standard is part of showing that your practice is coherent. Keep the version history, because it shows how the standard changed in response to real findings.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how a failed check names the rule and what the author does next, which is how a standard becomes visible in daily work.

Quick check

Do I need a standard before I buy a SAST tool?

A draft helps. It tells you what to test during a pilot and what you expect the tool to enforce.

Can the tool's default rules be my standard?

They can be a starting point, but a standard should reflect your stack and risks, and you should be able to explain every rule.

Who should own the secure coding standard?

A named person, usually in security or an engineering lead role, with input from developers. The owner keeps the review date and the change log.

Safeguard offers policies, gates and guardrails you can use to enforce decisions in your pipeline, and a free scan is at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.