---

title: Integrity
description: The integrity block says whether an identification was replayed or altered and which origin it ran on; this page lists what your backend must check before trusting an event.
---

The signals tell you about the visitor. The `integrity` block tells you about the identification request itself: whether it was sent before, whether it arrived as the agent built it, and which site it ran on. Your backend reads it, together with a few checks of its own, before it trusts anything else in the event.

## The integrity block

```json
{
  "integrity": {
    "nonce": "n9ZhyiA4uoRgnatmUdjAWt",
    "origin": "https://shop.example.com",
    "clock_skew_ms": 0,
    "replayed": false,
    "ja4_match": null,
    "nonce_cross_tuple": null,
    "sec_fetch_ok": true,
    "client_hash_ok": true
  }
}
```

| Field               | Type            | Meaning                                                                                                                                                                                        |
| ------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `replayed`          | boolean         | `true` when this identification was sent before. Refuse it. See [Replayed requests](#replayed-requests).                                                                                       |
| `client_hash_ok`    | boolean         | `false` when the request was altered or not sent by the agent. See [Altered requests](#altered-requests).                                                                                      |
| `origin`            | string          | The origin the page ran on: scheme, host and port, never a path or query (`https://shop.example.com`). Always one of the allowed origins of the public key that made the request.              |
| `nonce`             | string          | The one-time value of the challenge this identification answered: 22 characters. Each identification has its own.                                                                              |
| `clock_skew_ms`     | number          | The browser's clock minus knownprint's, in milliseconds, when they differ by more than a minute. `0` when they are within a minute of each other. Positive means the browser's clock is ahead. |
| `sec_fetch_ok`      | boolean or null | `false` is a sign the request did not come from a normal page load. `null` when it could not be told.                                                                                          |
| `ja4_match`         | boolean or null | Reserved for knownprint's own use.                                                                                                                                                             |
| `nonce_cross_tuple` | boolean or null | Reserved. Always `null` today.                                                                                                                                                                 |

Some requests never become events at all, so you will not find them in `integrity`. knownprint refuses an identification whose challenge has expired, whose nonce was already used, whose origin is not among the key's allowed origins, whose address is outside the key's allowed IP ranges, or whose token or payload is invalid. The browser agent receives an error and no request id. The codes are listed in [Errors](/api/errors).

## Replayed requests

A replay is an identification that was sent before, for example by a script that captured one real browser's identification and sends it again to pass as that browser. knownprint records a replay instead of refusing it, so that you can see it:

- The event has `integrity.replayed` set to `true`.
- The event is not billable (`billable` is `false`).
- A replay does not move the visitor's history and does not count towards [`high_activity`](/signals/activity).
- Reading a replay's request id may answer 404 `not_found`.

What to do: refuse the action. A replayed event's visitor id is the visitor whose identification was captured, not the client in front of you.

## Altered requests

`client_hash_ok` is `false` when the request was altered or not sent by the agent. A `true` value is not proof on its own that the agent sent the request.

What to do: treat the event as untrusted. Refuse sensitive actions, or step up with a second factor. Do not use its visitor id to grant anything.

Older events stored before this check existed can lack the field. Treat a missing `client_hash_ok` as unknown.

## Origin and clock

`integrity.origin` is the page origin the identification ran on. knownprint has already refused any origin that is not on the public key's allowed list, so a surprising origin here usually means a key shared between your sites. Compare it with the site where the action happens: an identification from your marketing site should not authorise a payment on your checkout.

`clock_skew_ms` is an observation, not a verdict. Many devices have clocks that are minutes off. A very large skew is worth logging beside other findings.

`sec_fetch_ok` is `false` as a sign the request did not come from a normal page load. Log it beside the other findings.

## What your backend must check

knownprint cannot know which of your requests an identification was meant for. Your backend ties the two together. [Verify a request in your backend](/install/server) gives the full procedure with its code; in short, before acting on an event:

1. **Read the event server side.** Take the request id from your page's form or request, and read the event with your secret key. Never trust a visitor id, a score or a signal that the browser sends you directly.
2. **Treat a missing event as a failure.** A 404 `not_found` means no such event in this environment: an invented id, an id from another environment, or some replays.
3. **Accept each request id once.** Record each request id the first time you see it, before any other check, and refuse one you have seen before. knownprint marks identifications sent before, but only you know that the same request id was already used for a login.
4. **Check freshness.** `received_at` is no more than 10 seconds before now (allow up to 60 seconds the other way for a clock that runs behind). An identification made for this action is seconds old; an older one was saved for later.
5. **Check `integrity.replayed`** is `false` and **`integrity.client_hash_ok`** is not `false`.
6. **Check `integrity.origin`** is the origin of the site where the action happens.
7. **Check the address.** `network.ip` is the address your own proxy reports for the request that carries the id ([The visitor address](/install/server#the-visitor-address)).
8. **Check your own ties.** If the page passed `linkedId` or `tags` to the agent, check that `linked_id` and `tags` on the event match the account and action in front of you. `url_path`, when present, is the path of the page that ran the agent.

```js title="verify.js"
const MAX_AGE_MS = 10_000; // a request id is checked within 10 seconds
const CLOCK_SKEW_MS = 60_000; // allowance for a receipt time slightly ahead of this clock
const ORIGIN = 'https://shop.example.com';

export async function verifiedEvent(requestId, { ip, accountId, seen }) {
  if (!/^evt_[a-z2-7]{26}$/.test(requestId ?? '')) return { ok: false, why: 'no_request_id' };
  // Record the id before anything else, so a stale or mismatched attempt also uses it up.
  if (!(await seen.addIfAbsent(requestId))) return { ok: false, why: 'request_id_reused' };

  const res = await fetch(`${process.env.KNOWNPRINT_API}/v1/events/${requestId}`, {
    headers: { Authorization: `Bearer ${process.env.KNOWNPRINT_SECRET_KEY}` },
    signal: AbortSignal.timeout(5000),
  });
  if (res.status === 404) return { ok: false, why: 'unknown_event' };
  if (!res.ok) return { ok: false, why: `knownprint_${res.status}` };
  const event = await res.json();

  const i = event.integrity;
  const age = Date.now() - Date.parse(event.received_at);
  if (!(age <= MAX_AGE_MS && age >= -CLOCK_SKEW_MS)) return { ok: false, why: 'stale', event };
  if (i.replayed) return { ok: false, why: 'replayed', event };
  if (i.client_hash_ok === false) return { ok: false, why: 'altered', event };
  if (i.origin !== ORIGIN) return { ok: false, why: 'origin', event };
  if (event.network.ip === null || event.network.ip !== ip)
    return { ok: false, why: 'address', event };
  if (
    accountId !== undefined &&
    event.linked_id !== null &&
    event.linked_id !== String(accountId)
  ) {
    return { ok: false, why: 'linked_id', event };
  }
  return { ok: true, event };
}
```

`seen` stands for your own store of accepted request ids, shared by every process that handles the action, whose `addIfAbsent` answers `true` only the first time it sees an id: a database table with a unique key, or Redis `SET ... NX` with an expiry of at least 70 seconds. `ip` is the address your own proxy reports, written as knownprint writes it ([The visitor address](/install/server#the-visitor-address)).

:::note Read errors
A read can also answer 409 `deletion_pending` while the visitor is being deleted, and 429 `rate_limited` when you exceed your rate limit. Neither says anything about the visitor. Decide in advance whether your flow fails open or closed when knownprint cannot be read. See [Errors](/api/errors) and [Limits](/limits).
:::

Once the event passes these checks, read its [signals](/signals) and [suspect score](/signals/suspect-score) to decide what the visitor may do.

## Related

- [`tampering`](/signals/browser#tampering): the browser lies about itself. That is a finding about the visitor's browser, not about the request, so it is a signal rather than part of `integrity`.
- [`network.reasons`](/signals/network#network-reasons): `moved_network` and `moved_country` say the browser's address changed during the identification.
- [Events](/events): every field of the event, `created_at`, `linked_id`, `tags` and `url_path` included.
