# Seguridad

## HTTPS obligatorio

Produccion debe operar solo sobre HTTPS. Redirigir HTTP a HTTPS y activar HSTS.

## API Keys

- Una API key por cliente/sistema externo.
- Guardar hash, nunca texto plano.
- Soportar expiracion, revocacion y rotacion.
- Asociar scopes: `references:write`, `references:read`, `batches:write`, `events:read`, `reconciliation:write`.

## Bearer Token

Usar JWT para usuarios administrativos. Incluir expiracion corta, rol y tenant.

## Idempotencia

`Idempotency-Key` es obligatorio en operaciones de creacion. El backend debe guardar llave, request hash y response para devolver resultados consistentes.

## Callbacks HMAC

Cada callback debe incluir:

```text
x-signature: sha256=<hmac>
x-timestamp: 2026-06-22T10:20:30Z
x-event-id: uuid
```

El HMAC se calcula sobre:

```text
timestamp + "." + raw_body
```

## Auditoria

Registrar actor, IP, user-agent, accion, recurso, estado anterior, estado nuevo y request_id.

## Rate limiting

Aplicar limites por API key y por IP. Responder `429` con headers `X-RateLimit-*`.

## Validacion de origen

Para webhooks Openpay validar firma, IP allowlist si aplica y merchant/client esperado.
