# Security

ahto keeps the public vulnerability feeds in the lake next to your code, so it can say which
advisories touch a repository at a commit. It also says which of them are exploited in the wild and
what else in the code puts it at risk, and this page says how ahto keeps itself safe.

## The advisory feeds

```sh
ahto security sync                 # the default feeds
ahto security sync all             # every feed ahto knows
ahto security sync osv:RubyGems    # one feed; an OSV feed may be named by its ecosystem
ahto security sync --offline       # rebuild the tables from the copies of the last sync
ahto security sources              # the feeds of the last sync and how each went
```

| Feed | What it holds | Synced by default |
|---|---|---|
| `osv:Go`, `osv:crates.io`, `osv:PyPI`, `osv:Maven`, `osv:npm`, `osv:Linux` | [OSV](https://osv.dev) advisories for those ecosystems | yes |
| `kev` | CISA's [Known Exploited Vulnerabilities](https://www.cisa.gov/known-exploited-vulnerabilities-catalog) catalog | yes |
| `epss` | FIRST's [EPSS](https://www.first.org/epss/) score: how likely a CVE is to be exploited in the next 30 days | yes |
| `osv:GIT`, `osv:RubyGems`, `osv:Packagist`, `osv:NuGet`, `osv:Hex`, `osv:Pub`, `osv:Debian`, `osv:Alpine` | OSV advisories for those | with `all` or by name |

A sync downloads the feeds and replaces the advisory tables in one lake run, so a query
never sees half a sync. It keeps a copy of each download, and `--offline` reads only those.

## Asking about a repository

```sh
ahto security posture                       # grade, findings by severity, packages and manifests
ahto security deps --vulnerable             # the pinned packages that have a finding
ahto security findings --severity high      # what puts it at risk, riskiest first
ahto security findings --kev --fixable      # exploited in the wild, with a known fix
ahto security search --ecosystem Go --kev   # search the advisories themselves
ahto security show CVE-2024-1086            # one advisory, with the lake commits it names
```

`posture`, `deps` and `findings` take `--repo` (optional when the lake holds one repository)
and `--at` (`HEAD`, a ref, or a commit or tag id). `deps` reads the manifests and lockfiles
at that commit. `findings` has five kinds, chosen with `--kind`:

| Kind | What it is |
|---|---|
| `vulnerable_dependency` | a pinned package version an advisory covers |
| `vulnerable_commit` | a commit an advisory names as bringing in or fixing a flaw |
| `secret` | a value in the code that looks like a key or a token; shown as a fingerprint, never as the value |
| `dangerous_call` | a call such as a shell or `eval` with a variable, TLS checks turned off or a broken hash (rules after gosec, bandit, flawfinder and eslint-plugin-security) |
| `sensitive_file` | a file such as a private key or a credentials file |

`--stream` prints each finding as it is found. Every command takes `-o json`, `jsonl` or
`csv`.

## The advisory tables

| Table | One row per |
|---|---|
| `advisories` | advisory: id and aliases, summary, severity, CVSS score, packages, CWEs, dates |
| `advisory_events` | event of an affected range: introduced, fixed, last affected or limit, as a version or a commit |
| `advisory_versions` | version an advisory lists as affected |
| `advisory_refs` | link of an advisory: the fix, the report, the article |
| `kev` | CVE in the KEV catalog: vendor, product, date added, due date, ransomware use |
| `epss` | CVE with its chance of being exploited in the next 30 days, and its percentile |
| `advisory_sources` | feed of the last sync: when, how many records, and ok, unchanged or failed |

The functions `known_exploited_fixes` and `security_fix_commits` join them with the history:
the commits that fix a KEV CVE, and the commits whose message says they fix a flaw
(`ahto function call security_fix_commits`). The security service of the gateway serves the
same answers to the web app and to agents. The design is in
the security service design document.

## How ahto keeps itself safe

- ahto runs `git` with a cleaned environment: no hooks, and no global or system Git config.
  Mirrors are bare, so nothing is checked out and nothing in a repository runs.
- A remote URL is never written to a log or the lake with its password or token in it, and
  a token reaches `git` only through the environment of that one process
  ([private repositories](/docs/private-repositories#how-a-token-is-kept-safe)).
- Email addresses are hidden from the gateway's query answers.
- The gateway listens only on 127.0.0.1 unless you set `protocol.allow_remote`. Do not set
  it on a network you do not trust; for a gateway other people reach, set `public: true` as
  well ([configuration](/docs/configuration#public-mode)). Passkeys then work only from the
  web origins listed in `protocol.origins`, besides loopback ones: a passkey is for the host
  its origin names, and that host is one you choose, never one a request names.
- The gateway has no authentication unless the node is in its network's authority group
  (`p2p.networks[].authority.member`). Then every call, loopback too, needs a session, a
  remote call also needs the group's lease, and `ahto ui` prints a one-time code, good once
  for five minutes from this machine, that signs the first browser in. A gateway with
  `protocol.allow_remote` mints no code.

To report a vulnerability in ahto itself, see `SECURITY.md` at the root of the source.