# Data models: vaults, targets, scans and findings

The models of the research context: the vault and its scope, the targets inside it, scans with their lifecycle, findings and signatures. Part of the [data model reference](./index.md).

## Vault

**File:** `vault.py` · **Table:** `vaults` · **Exposure:** API

A research program (bug bounty program or engagement). It is the context of
the workstation: targets, scans, findings, proxy traffic and notes belong to
one vault.

| Field | Type | Notes |
|---|---|---|
| `name` | String(255) | Not null, indexed |
| `platform` | Enum `PlatformType` | Not null, default `CUSTOM` |
| `target_domain` | String(255) | Not null |
| `program_url` | String(255) | Nullable |
| `scope_rules` | JSON | Not null, default `{"in": [], "out": []}`: lists of exact hosts, `*.` suffixes, IP literals or CIDR ranges, stored canonical |
| `engagement` | JSON | Nullable: engagement rules (`app/core/engagement`); null allows everything |
| `policy_version` | Integer | Not null, default 1; grows with every scope or rules change |

AuthorizationDecision (`authorization_decisions`, `engagement.py`): one
decision of the engagement gate: `vault_id` (CASCADE), `created_at`,
`actor`, `agent_id` (SET NULL), `operation` (`scan`, `attack`,
`repeater`, `replay`), `host`, `policy_version`, `outcome` (`allowed`,
`refused`), `reason`, `message`. EngagementUsage (`engagement_usage`):
requests originated per vault and engagement day, unique per pair.
Attacks and scans carry the `agent_id` that started them (SET NULL).

**Relationships (backrefs defined on the child models):** `targets` (1→N,
`cascade='all, delete-orphan'`), `proxy_flows` (1→N, `cascade='all,
delete-orphan'`), `workflows` (1→N). Notes and note folders reference the
vault by foreign key only (no ORM relationship).

**Methods:** `scope` (property) builds an immutable `ScopePolicy`
(`app/core/scope.py`) from `scope_rules`. `is_in_scope(domain)` is
`scope.allows(domain)`, so it is true when an in-pattern matches and no
out-pattern does. `is_out_scope(domain)` is its negation.

Scope patterns (`app/core/scope_patterns.py`) are validated when a vault is
saved: `example.com` matches only that host, `*.example.com` every name
below it (not the apex), `10.0.0.0/24` every address in the range.
Anything wider, such as `*example.com` (which would also match
`evilexample.com`), is refused with 422 and the index of the pattern.
Patterns stored by older versions stay conservative: an invalid in-pattern
matches nothing, an invalid out-pattern keeps its old wildcard match.

### `PlatformType`
`HACKERONE`, `BUGCROWD`, `INTIGRITI`, `YESWEHACK`, `CUSTOM` (stored as
lowercase values, for example `hackerone`).

---

## Target

**File:** `target.py` · **Table:** `targets` · **Exposure:** API

A specific asset inside a Vault. It is self-referential, so it supports
hierarchies such as Domain → Subdomain → Endpoint.

| Field | Type | Notes |
|---|---|---|
| `identifier` | String(512) | Not null, indexed |
| `target_type` | Enum `TargetType` | Not null, default `WEB` |
| `vault_id` | FK → `vaults.id` | Nullable, indexed, `ON DELETE CASCADE` |
| `parent_id` | FK → `targets.id` | Nullable, `ON DELETE SET NULL` |
| `status` | Enum `TargetStatus` | Not null, default `ACTIVE` |
| `is_wildcard` | Boolean | Default `False` |
| `ip_address` | String(45) | Nullable, IPv4 or IPv6 |
| `tech_stack` | JSON | Nullable |
| `risk_score` | Integer | Default `0` |
| `description` | Text | Nullable |
| `last_scanned_at` | DateTime | Nullable, naive UTC |

**Relationships:** `vault` (backref `Vault.targets`), `children` / `parent`
(self, `children` has `cascade='all, delete-orphan'`), and the backrefs
`assets`, `scans`, `findings` (1→N, each `cascade='all, delete-orphan'`).

**Methods:** `mark_scanned()` sets `last_scanned_at` to `datetime.utcnow()`.

### `TargetType`
`WEB`, `API`, `MOBILE`, `NETWORK`, `CLOUD`, `OTHER`

### `TargetStatus`
`ACTIVE`, `ARCHIVED`, `BLACKLISTED`, `VULNERABLE`

---

## Scan

**File:** `scan.py` · **Table:** `scans` · **Exposure:** API

One execution of an engine pipeline against a target. The lifecycle is an
explicit state machine. A transition it does not allow raises
`InvalidStateError`.

| Field | Type | Notes |
|---|---|---|
| `target_id` | FK → `targets.id` | Not null, indexed, `ON DELETE CASCADE` |
| `module_id` | FK → `modules.id` | Nullable, `ON DELETE SET NULL` |
| `scan_type` | Enum `ScanType` | Not null |
| `status` | Enum `ScanStatus` | Not null, default `QUEUED` |
| `config` | JSON | Default `{}` |
| `result_summary` | JSON | Default `{}` |
| `error_message` | Text | Nullable |
| `assets_discovered` | Integer | Default `0` |
| `findings_count` | Integer | Default `0` |
| `started_at` | DateTime (tz) | Nullable; set by `start()` |
| `completed_at` | DateTime (tz) | Nullable |
| `duration_seconds` | Integer | Nullable |
| `triggered_by` | String(50) | Default `'manual'` |

**Indexes:** `ix_scan_target_status (target_id, status)`,
`ix_scan_module_type (module_id, scan_type)`.

**Relationships:** `target` (backref `Target.scans`), `module` (backref
`Module.scans`), `findings` (backref from `Finding.scan`,
`passive_deletes=True`).

**State machine (`TRANSITIONS`):**

| From | Allowed to |
|---|---|
| `QUEUED` | `RUNNING`, `CANCELLED`, `FAILED` |
| `RUNNING` | `COMPLETED`, `CANCELLED`, `FAILED` |
| `PAUSED` | `CANCELLED`, `FAILED` |

`PAUSED` is reserved and unreachable: the runner cannot pause a scan
(pausing needs checkpointing in the signature engine, see the roadmap), so
no transition leads into it and it cannot resume to `RUNNING`. It stays in
the enum for the stored column type and counts as active; a legacy row in
that state can only be failed or cancelled, which the runner's startup
recovery does. Terminal statuses have no outgoing transitions
(`tests/test_model_fixes.py`).

**Methods:** `is_active` (property: status in `ACTIVE_STATUSES`),
`start()` (to `RUNNING`, sets `started_at`), `complete()`, `cancel()`,
`fail(error)`. The last three set `completed_at` and `duration_seconds`, and
`fail` also records `error_message`.

**Module constants:** `ACTIVE_STATUSES = {QUEUED, RUNNING, PAUSED}`,
`TERMINAL_STATUSES = {COMPLETED, CANCELLED, FAILED}` (both exported from
`app.models`).

### `ScanType`
`SUBDOMAIN_ENUM` (`subdomain_enumeration`), `JAVASCRIPT_ANALYSIS`,
`SERVICE_DETECTION`, `DNS_RESOLUTION`, `PORT_SCAN`, `WEB_CRAWL`,
`TECHNOLOGY_DETECTION`, `SSL_ANALYSIS`, `VULNERABILITY_SCAN`,
`CUSTOM_SIGNATURE`, `FULL_RECON`

### `ScanStatus`
`QUEUED`, `RUNNING`, `PAUSED`, `COMPLETED`, `CANCELLED`, `FAILED`

---

## Finding

**File:** `finding.py` · **Table:** `findings` · **Exposure:** API

A discovered vulnerability or security issue, with triage status, evidence
and bounty information.

| Field | Type | Notes |
|---|---|---|
| `scan_id` | FK → `scans.id` | Nullable, indexed, `ON DELETE SET NULL` (findings survive scan deletion; manual findings have no scan) |
| `target_id` | FK → `targets.id` | Not null, indexed, `ON DELETE CASCADE` |
| `signature_id` | FK → `signatures.id` | Nullable, `ON DELETE SET NULL` |
| `title` | String(500) | Not null |
| `description` | Text | Nullable |
| `severity` | Enum `Severity` | Not null, indexed, default `INFO` |
| `status` | Enum `FindingStatus` | Not null, default `NEW` |
| `cvss_score` | String(10) | Nullable |
| `cve_id` | String(50) | Nullable |
| `cwe_id` | String(50) | Nullable |
| `evidence` | JSON | Default `{}` |
| `remediation` | Text | Nullable |
| `affected_url` | Text | Nullable |
| `affected_parameter` | String(255) | Nullable |
| `poc` | Text | Nullable, proof of concept |
| `is_duplicate` | Boolean | Default `False` |
| `duplicate_of_id` | FK → `findings.id` | Nullable, `ON DELETE SET NULL`; no ORM relationship is defined |
| `reported_at` | DateTime (tz) | Nullable; aware UTC (migration `b5c8e2f41d07`) |
| `bounty_amount` | Integer | Nullable |

**Relationships:** `scan` (backref `Scan.findings`), `target` (backref
`Target.findings`), `signature` (backref `Signature.findings`).

**Methods:** `mark_false_positive()`, `mark_reported()`. `mark_reported()`
sets `REPORTED` and records `reported_at` as an aware UTC time; the first
report time is kept if the finding is reported again, as in the API.

### `Severity`
`INFO`, `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`

### `FindingStatus`
`NEW`, `TRIAGING`, `VALIDATED`, `REPORTED`, `ACCEPTED`, `RESOLVED`,
`DUPLICATE`, `FALSE_POSITIVE`, `WONT_FIX`

---

## Signature

**File:** `signature.py` · **Table:** `signatures` · **Exposure:** API

Detection signatures (templates): what to look for and how to detect it.
Built-in signatures are synced from the bundled template directory and are
read-only. User signatures are created and edited in the workstation.

| Field | Type | Notes |
|---|---|---|
| `name` | String(255) | Not null, indexed (not unique) |
| `signature_id` | String(100) | Not null, unique, indexed |
| `signature_type` | Enum `SignatureType` | Not null |
| `version` | String(50) | Not null, default `'1.0'` |
| `author` | String(100) | Nullable |
| `description` | Text | Nullable |
| `icon` | String(50) | Nullable |
| `severity` | String(20) | Default `'info'` (a plain string, not the `Severity` enum) |
| `language` | Enum `SignatureLanguage` | Not null, default `YAML` |
| `template` | Text | Not null, the signature body |
| `matchers` | JSON | Default `[]` |
| `extractors` | JSON | Default `[]` |
| `references` | JSON | Default `[]` |
| `tags` | JSON | Default `[]` |
| `cve_id` | String(50) | Nullable |
| `cwe_id` | String(50) | Nullable |
| `is_active` | Boolean | Indexed, default `True` |
| `is_verified` | Boolean | Default `False` |
| `false_positive_rate` | Integer | Default `0` |
| `execution_count` | Integer | Default `0` |
| `success_count` | Integer | Default `0` |
| `category` | String(100) | Nullable, indexed |
| `requires_auth` | Boolean | Default `False` |
| `source` | Enum `SignatureSource` | Not null, indexed, default `USER` |
| `source_path` | String(500) | Nullable, template file of a built-in signature |
| `signature_metadata` | JSON | Default `{}` |

**Indexes:** `ix_signature_type_active (signature_type, is_active)`.

**Relationships:** `findings` (backref from `Finding.signature`).

**Methods:** `increment_execution()`, `increment_success()`, `activate()`,
`deactivate()`, `success_rate` (property, integer percentage, `0` when never
executed).

### `SignatureType`
`VULNERABILITY`, `CONFIGURATION`, `INFORMATION_DISCLOSURE`,
`TECHNOLOGY_DETECTION`, `CUSTOM`

### `SignatureSource`
`BUILTIN` (synced from templates, read-only), `USER`

### `SignatureLanguage`
`YAML`, `JSON`
