A local rule is a custom Semgrep rule created and managed by the team running the scan. It can be defined ephemerally for one-off use or stored in YAML for reuse. Local rules are useful when standard rule sets do not capture an organisation’s specific coding patterns or security concerns.
What a local rule does in Semgrep
A local rule is a team-owned Semgrep rule that extends the scan to patterns your standard rule packs do not cover. Because it is authored and managed locally, it can reflect an organisation’s own frameworks, code conventions, and risk priorities without waiting for an upstream rule release.
That makes local rules especially useful for catching proprietary idioms, internal helper functions, wrapper libraries, and security-sensitive patterns that only exist in one codebase or product family. They are also a practical way to translate policy intent into code checks when a generic rule would be too broad or too noisy.
How local rules are defined and reused
Local rules can be created for a one-off review or stored in YAML for repeated use. In practice, the difference is less about the syntax and more about operational ownership: ephemeral rules are often used to answer a narrow question during investigation, while reusable rules become part of a team’s ongoing scan library.
That reuse matters because teams can version-control the rule, review it like code, and refine it as the application evolves. A local rule is therefore both a detection artifact and a living decision about what the organisation considers important enough to check continuously.
Why local rules matter for coverage and signal quality
Standard rule sets are necessarily general, so they will miss some organisation-specific behaviors. Local rules close that gap by allowing teams to encode context the scanner cannot infer on its own, such as internal authentication helpers, custom deserialisation paths, or unsafe wrapper functions that appear benign in isolation.
They also help reduce false negatives and improve alert quality when used carefully. A well-designed local rule can focus on the exact code shape the team cares about, rather than forcing analysts to sift through generic findings that are technically valid but operationally unhelpful.
Where local rules fit in a security programme
Local rules work best as part of a wider secure development and code review practice, not as a substitute for upstream rule coverage. They are most valuable when teams treat them as maintained controls: tested against real code, reviewed when patterns change, and retired when the underlying risk disappears.
They can also surface governance issues. If a team needs many local rules for the same class of weakness, that often indicates a recurring design or library choice that should be addressed upstream in architecture, shared components, or training rather than patched repeatedly at scan time.
Risk and Threat Considerations
Local rules can become a blind spot if they are poorly maintained, because they only protect the patterns the team has explicitly encoded. Over time, stale rules may miss new code paths, while overly broad rules can bury real findings in noise and train reviewers to ignore alerts.
Failure mechanism: Attackers or bugs exploit code constructs that are unique to the organisation, but the scanner does not flag them because no local rule captures the pattern, or because the rule is too imprecise to be actionable.
Impact: Security reviews lose coverage exactly where custom application logic is most likely to differ from public examples, which can allow unsafe input handling, privilege checks, or secret handling issues to persist into production.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, CIS Controls v8 and OWASP SAMM set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V15 — Secure Coding and Architecture | Local rules encode organisation-specific secure coding checks for custom application patterns. |
| Recommendation — Map recurring findings into V15-style review criteria and test local rules against the code paths they protect. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Local rules support application security testing and validation of custom code patterns. |
| Recommendation — Use CIS-16 to govern custom scan rules as part of application security testing and validation. | ||
| OWASP SAMM | Architecture Risk Assessment — Architecture Risk Assessment | Local rules reflect project-specific risks that secure design and assessment practices should capture. |
| Recommendation — Feed repeated local-rule themes back into architecture risk assessment and secure design review. | ||
Practitioner Guidance
Governance implication: Treat local rules as owned security content, not ad hoc analyst notes. Give them a clear maintainer, review cadence, and naming convention so teams can tell which rules are authoritative and which are temporary investigation aids.
What to watch for: Repeated creation of similar local rules is often a sign that the same weakness is reappearing across services or repositories. When that happens, promote the pattern into a shared rule or address the underlying coding practice instead of letting each team reinvent its own detection.
Related resources from NHI Mgmt Group
- Why are local .env files and config notes risky in Microsoft 365?
- How should teams respond to a local Linux privilege escalation flaw in shared environments?
- What is the difference between global identity strategy and local governance?
- How should security teams handle local accounts in cloud and SaaS apps?
Deepen Your Knowledge
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.
Reviewed and updated by the NHIMG editorial team on November 4, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org