Cybersecurity & Information Security

Detection as Code: Managing Detection Rules in Git

6 min readPublished: August 5, 2026
Professional visual illustration of Detection as Code in Threat Hunting and Detection
Quick answer

Detection as Code starts with a question or behavior to identify, continues to telemetry and logic definition, and concludes with testing, tuning, documentation, and controlled deployment. Quality is measured by coverage and investigative capability.

Threat Hunting and Detection Engineering translate knowledge about adversary behavior into measurable questions, data sources, and detection rules. The goal is not to generate more alerts, but to improve coverage and decision quality. This article focuses on Detection as Code and is intended for advanced Detection and SOC teams. The aim is to provide a working methodology that can be applied in practice, during professional interviews, and in a work environment, without settling for a dictionary definition.

The main challenge is that data is almost always incomplete. A repository, pull request, and lint can indicate a direction, but their meaning depends on time, asset, user, and expected activity. Therefore, we will build the test around an investigative question, required evidence, and clear completion criteria.

The practical scenario in the article is: a sample Repository structure without malicious code. All examples are laboratory data or descriptions of processes. When dealing with Penetration Testing, Web, or Cloud, work only with explicit authorization, defined Scope, and the ability to stop the test.

Why Manage Detections as Code

The topic 'Why manage Detections as Code' is a central part of working on Detection as Code. It is recommended to break it down into three questions: what is the input, what decision do you want to make, and what evidence is sufficient to justify it. These questions prevent automatic tool use without understanding the objective.

In practice, write down the repository, pull request, lint, tests, release, compare to expected behavior, and define at least one pivot. The result should be verifiable by another analyst, including limitations and next steps.

Repository structure

The topic 'Repository structure' is a central part of working on Detection as Code. It is recommended to break it down into three questions: what is the input, what decision do you want to make, and what evidence is sufficient to justify it. These questions prevent automatic tool use without understanding the objective.

In practice, write down the repository, pull request, lint, tests, release, compare to expected behavior, and define at least one pivot. The result should be verifiable by another analyst, including limitations and next steps.

Review and Approval

The topic 'Review and Approval' is a central part of working on Detection as Code. It is recommended to break it down into three questions: what is the input, what decision do you want to make, and what evidence is sufficient to justify it. These questions prevent automatic tool use without understanding the objective.

In practice, write down the repository, pull request, lint, tests, release, compare to expected behavior, and define at least one pivot. The result should be verifiable by another analyst, including limitations and next steps.

Testing and CI

Professional testing for Detection as Code begins with success and failure conditions. Define a positive case, a negative case, a boundary case, and similar legitimate activity. This allows identification of both False Negatives and False Positives.

In an authorized environment, a minimal action that proves the claim without causing damage is used. Input, Output, time, and version are saved, and after correction, a Retest is performed in the same scenario, and Regression on nearby functions is also checked.

Deployment and Rollback

The topic 'Deployment and Rollback' is a central part of working on Detection as Code. It is recommended to break it down into three questions: what is the input, what decision do you want to make, and what evidence is sufficient to justify it. These questions prevent automatic tool use without understanding the objective.

In practice, write down the repository, pull request, lint, tests, release, compare to expected behavior, and define at least one pivot. The result should be verifiable by another analyst, including limitations and next steps.

Unique Testing Focus Areas

In this topic, it is recommended to build a focused evidence map in advance. The main testing areas are: repository, pull request, lint, tests, release, rollback. The list is not an automatic Checklist; each item is chosen because it can link an entity, action, and time or explain legitimate behavior.

  • repository: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.
  • pull request: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.
  • lint: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.
  • tests: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.
  • release: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.
  • rollback: Define the expected value, what would be considered anomalous, and what additional source would corroborate the finding.

When one of the focus areas is unavailable, the gap should be documented, and an alternative selected. For example, if a Process identifier is unstable, time, Host, User, and Parent can be used; if Payload is encrypted, Metadata, volume, frequency, and TLS/DNS context are used.

Practical Scenario

The selected scenario is a sample Repository structure without malicious code. The purpose of the exercise is not to prove attack capability, but to practice collecting, comparing, and documenting in a safe manner. Before starting, define mock data, a time window, and an expected outcome.

At the end of the exercise, a deliverable that another analyst or tester can review should be submitted: a screenshot or Export of the evidence, a short Timeline, an initial hypothesis, corroborating evidence, a limitation, and a recommendation. When there is insufficient evidence, the correct conclusion is that the scenario was not proven.

StepWhat is performedDeliverable
PreparationDefine Scope, time, and objective. List which fields or evidence from repository, pull request, lint are expected to appear.Short test plan
Data CreationPerform a safe and simulated action related to Detection as Code, without real information or impact on a production system.Controlled event/Request/Flow
CollectionCollect the raw evidence and context from an additional source. Ensure Time zone, identifiers, and integrity.Two linked pieces of evidence
AnalysisWrite what each piece of evidence proves, what it does not prove, and what is the possible legitimate explanation.Interim conclusion
CompletionChoose closure, escalation, Finding, or Tuning; add recommendation and Retest.Documented deliverable

Practical Checklist

  • Check and document: Hypothesis.
  • Check and document: ATT&CK technique.
  • Check and document: Data sources.
  • Check and document: Detection logic.
  • Check and document: Expected benign behavior.
  • Check and document: Test cases and coverage.
  • Specify Time zone, tool version, and collection time.
  • Save raw data before filtering or modification.
  • Write what the finding proves and what is still unknown.
  • Define owner and next action with a due date.

Common Mistakes

  • Starting from a random IOC without a Hypothesis.
  • Mapping ATT&CK by name only.
  • Writing a Rule without Test cases.
  • Ignoring legitimate behavior.
  • Measuring Rules instead of Coverage.
  • Not managing versions.

Summary and CTA

Detection as Code: Managing Detection Rules in Git is a topic that connects technical knowledge with work discipline. Start with a question, collect only relevant evidence, maintain context and time, and choose an action that can be justified and re-tested.

In HPI's Cybersecurity & AI track, these principles are practiced using systems, logs, and labs. A natural progression is to move on to the linked articles, complete the lab exercise, and save the output as part of a professional portfolio.

FAQ

Does Detection as Code alone prove an attack or vulnerability?

No. It provides a signal or finding that requires context, validation, and an additional source. A professional conclusion relies on a sequence of evidence and alignment with expected behavior.

What do you do when some data is missing?

Document the missing data, check for an alternative source, and reduce the level of confidence. Do not fill in fields by assumption or present Unknown as normal.

How long should evidence be retained?

The time depends on policy, regulation, cost, and the type of event. It is important to pre-define Retention, Legal hold, and the ability to export evidence in a verifiable format.

How do you practice without risking a real system?

Use virtual machines, simulated data, CTF, or a dedicated lab. In authorized tests, define Scope, Stop conditions, and backup before starting work.

Want to check if this track is right for you?

Leave your details and an HPI advisor will get back to you for a short, no-obligation fit call.

Your details are stored securely.

For SOC and cyber studies within the Cybersecurity & AI program

Want to hear the details? Leave your info and we'll get back to you.

Related articles