# Security

> Protect API keys and webhook secrets, keep card data off your servers, verify every webhook, and never trust the browser for payment state.

## API keys

- Keep keys on your server, in environment variables or a secrets manager. Never in browser JavaScript, mobile apps, Git, logs, screenshots or support tickets.
- Grant the fewest abilities that work. A website checkout needs `merchant:read`, `checkouts:read`, `checkouts:write` and `transactions:read`. See [Authentication](/docs/authentication).
- Keep `refunds:write` and `payouts:write` off keys that run on public web servers, unless that server really needs them.
- Use one key per system, named after it, so you can revoke one without breaking the others.
- Set an expiry where you can, and rotate keys on a schedule and whenever someone with access leaves.
- If a key leaks, revoke it in **Developers → API keys** at once, then create a new one.

NorthechPay stores only a SHA-256 hash of each key, shows the secret once, and never gives a key access to Moov credentials.

## Card and personal data

- Buyers type card details on Moov's hosted page. Card numbers never reach your server or the NorthechPay API. Keep it that way: do not build your own card form that posts to your server.
- Responses show only masked details, such as the card brand and last four digits.
- Do not put personal data in `title`, `description`, `merchant_reference` or `metadata`. The title and description are shown to the buyer on the Moov page, and the rest is stored and returned by the API.
- With secure onboarding, which is the default, business owners' identity data (such as SSN and date of birth) goes from the browser straight to Moov. It does not pass through the API.

## Webhooks

- Verify the `NorthechPay-Signature` on every request, against the raw body, with a constant-time comparison and the 300-second timestamp check. See [Webhooks](/docs/webhooks).
- Reject requests that fail verification before you parse or act on them.
- Keep the signing secret out of code and logs. Rotate it if it may have leaked.
- Serve the endpoint over HTTPS. It must be reachable on the public internet. NorthechPay refuses endpoints that resolve to private or reserved addresses, and does not follow redirects.
- Deduplicate by event `id` and make your handler idempotent.

## Payment state

- Mark an order paid only from your server: a verified `checkout.paid` webhook, or your own read of the checkout showing `paid: true`.
- Never trust the buyer's browser, the return to your site, a query string, or Moov's thank-you page.
- Check that the checkout's `amount` and `currency` match the order before you fulfil it.
- Never compute a spendable balance yourself. Read it from Moov through `GET /merchant/wallets`.

## Isolation

Each key sees only its own merchant. IDs from other merchants return `404 not_found`, so the API never confirms that someone else's resource exists. Never pass IDs from your buyers straight to the API without checking that they belong to the buyer's own order.

## Logging

- Log `X-Request-Id`, `error.code` and resource IDs.
- Do not log the `Authorization` header, the webhook secret, full request bodies with personal data, or full webhook payloads in plain text logs.

## What NorthechPay does on its side

- Every money-moving action and every API key change is written to an audit log.
- Webhook destinations are checked against private and reserved address ranges when saved and again before each delivery, and the checked address is pinned for the request.
- A fail-closed guard refuses any change at Moov unless Moov reports test mode.
- Each money-moving Moov request carries a durable idempotency key, and a timeout is reconciled, never retried with a new key.

## Reporting a problem

If you find a security issue, contact the NorthechPay platform operator privately, with the `X-Request-Id` of any request involved. Do not post details in public.
