knownprintDocs

Install

Run knownprint from your domain

Why knownprint's script and its requests go through a /kp/ path on your own site, what the proxy rule does, what you receive with your account, and how to fix a rule that does not work.

knownprint runs from your own domain. Your web server forwards one path of your site, /kp/, to knownprint, and your pages load the script from that path. The script, its identification requests and the cookie knownprint keeps all belong to your site. If your site sends a Content Security Policy, it must also allow the knownprint host your account names (Content Security Policy).

This page explains what the proxy rule does and what it needs from you. The step by step recipes are on their own pages:

Your serverRecipe
nginxInstall on nginx
nginx behind Cloudflare's proxied DNSSites behind Cloudflare
CaddyInstall on Caddy

Once the rule works, add the script to your pages with the browser agent.

Why the script runs first party

Serving knownprint from your own domain gives you four things:

  • Requests that reach knownprint. Content blockers and browser privacy features treat a request to your own domain as part of your site. A script or request on a third-party analytics or security hostname is far more often blocked, delayed or stripped of its cookies.
  • A cookie your server sets. knownprint's cookie is set by the answer your own server returns, on your own host, so it is your site's own first-party cookie. Privacy lists its attributes.
  • The visitor's real address. Your server sees the visitor's connection and passes its address on, signed with your proxy secret. Without that, knownprint would see only your server's address. See The visitor's address.
  • A simple Content Security Policy. The script and its identification requests come from your own origin, so 'self' covers them, beside the one knownprint host the policy lists. See Content Security Policy.

What the proxy rule does

The rule is a block of configuration you add to the server that terminates TLS for your site. For every request under /kp/ it:

  1. forwards the request to knownprint, at the address that comes with your account;
  2. adds your proxy secret, the visitor's address and your site's hostname, so knownprint knows the request came through your server and from whom;
  3. removes every cookie except knownprint's own, so your session cookies never leave your server;
  4. sets the cache lifetime of each path, so the script is cached and identifications never are.

It also serves your disclosure file at /.well-known/knownprint.json from a file on your server.

The rule leaves the browser's own request headers, Origin among them, as the browser sent them, and passes knownprint's Set-Cookie back to the browser on the paths that set a cookie. Do not add rules of your own that remove or rewrite headers on /kp/ paths.

Everything outside /kp/ and the disclosure file is untouched: your site keeps working exactly as before.

What you receive with your account

WhatWhat it isWhere it goes
The proxy recipeThe configuration files for your server: for nginx, a file for the http block, a file for your site's server block, a variant of that file for sites behind Cloudflare and an example of the secret file; for Caddy, one snippet. Your copy already names the knownprint address your server forwards to.Your web server
A proxy secret32 characters, issued for each environment. It proves that a request came through your server.Your web server only (a file for nginx, an environment variable for Caddy)
The disclosure fileknownprint.json, the machine-readable disclosure your server publishes./usr/local/share/knownprint/knownprint.json on your web server
A public keypk_live_ or pk_test_ and 32 charactersYour pages (the browser agent)
A secret keysk_live_ or sk_test_ and 32 charactersYour backend (verify in your backend)

You set two things in the recipe yourself: the proxy secret, and the three fields of the disclosure file that describe your business (Privacy lists them). The recipe sets everything else, including every header knownprint reads from your server. Keep the files as you received them, apart from the response headers the nginx page tells you to repeat; a changed line can stop the rule working or let your own cookies through.

The proxy secret

Each environment has its own proxy secret, so your test and live environments each have one. Use the secret of the environment whose public key your pages load: a staging site with a test key uses the test environment's secret.

Treat the proxy secret like a password:

  • Keep it out of version control, logs, tickets and chat messages. Whoever holds it can send requests that knownprint takes as coming from your server, with any visitor address they choose.
  • Store it only where the recipe says: a file readable by root and the nginx group, or an environment file readable only by root for Caddy.
  • Rotate it if it may have leaked.

An environment can hold several proxy secrets at once, so you can rotate without downtime:

  1. Create a new proxy secret with POST /v1/keys and the body {"kind": "proxy_secret"}, using a secret key with the keys:manage scope. The answer is 201 and carries the new value once, in value, with its id.
  2. Put the new value in your server's configuration on every server that answers for your domain, then reload nginx (step 2) or restart Caddy (Rotating the secret).
  3. Retire the old secret with DELETE /v1/keys/{id}, which answers 204.
Shell
curl -X POST "$KNOWNPRINT_API/v1/keys" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "proxy_secret"}'

A new or retired secret takes effect within a minute. GET /v1/keys lists your proxy secrets with their ids and creation times, never their values. API keys documents the three routes.

The paths under /kp/

Every request the script makes goes to a path under /kp/ on the page's own origin. The rule forwards them all; you never need to list them in your own configuration, but they help when you read your logs.

PathMethodWhat it isCookies forwardedCache lifetime
/kp/agent.jsGETThe loader your pages include with a script tagNone, and no cookie is setpublic, max-age=3600, s-maxage=60: browsers keep it up to an hour, shared caches up to a minute
/kp/a/{build}.js, /kp/a/{build}.s.jsGETThe script files the loader fetches, one name per releaseNone, and no cookie is setpublic, max-age=31536000, immutable: each release has its own name, so a year is safe
/kp/cPOSTThe start of each identificationknownprint's cookie onlyno-store
/kp/iPOSTThe identification itself; its answer sets knownprint's cookieknownprint's cookie onlyno-store
/kp/l/{request_id}POSTA follow-up route of the agent, which can update the stored eventknownprint's cookie onlyno-store
/kp/b/{request_id}POSTA follow-up route of the agent, which can update the stored eventknownprint's cookie onlyno-store
/.well-known/knownprint.jsonGETYour disclosure file, served from your server's disk as application/jsonNot forwardedYour server's default

Any other path under /kp/ is forwarded too and answered 404 by knownprint. A POST to /kp/l/ or /kp/b/ can be answered 410; that is normal and the script ignores it. Agent routes lists the status codes each route answers.

The script uses /kp/ on the page's origin by default. If your site cannot give up that path, the script's endpoint option points it elsewhere (The endpoint). The recipe you receive handles /kp/ only, so a different path means a different recipe: ask your knownprint contact before you change it.

Cookies

The rule passes exactly one kind of cookie to knownprint: knownprint's own first-party cookie. Every other cookie of your site, sessions, carts, consent records, analytics, stays on your server and never reaches knownprint. On the loader and the script files no cookie is forwarded at all, and any cookie in their answers is removed.

In the other direction, the answer to an identification sets knownprint's cookie through your server, on the page's own host, with HttpOnly, Secure and SameSite=Lax. Because the cookie is Secure, your pages must be served over https.

Two things on your side must leave the cookie alone:

  • Nothing between the browser and knownprint may remove or rewrite the Set-Cookie header of /kp/ answers: not your server's own rules, not a CDN, not a security product.
  • Do not write cookie rules of your own for /kp/ paths. The recipe already decides which cookie reaches knownprint, and a rule of yours could forward your own cookies or hold back knownprint's.

If your site has a "forget me" or account deletion flow, see Forget this browser and Deleting a visitor's data.

Caching

The rule sets the cache lifetime of every /kp/ answer, as the table above shows:

  • The loader may be cached by browsers for an hour and by shared caches (your CDN) for a minute. Do not give it a longer lifetime: the loader names the current release of the script files, and a loader cached for too long can ask for a release that is no longer served, which makes load() fail with load_failed.
  • The script files carry their release in their name and may be cached for a year.
  • The identification paths are no-store: never cached anywhere.

If your CDN has a "cache everything" rule, a rule that overrides cache lifetimes, or a rule that minifies or rewrites JavaScript, exclude /kp/ from it. The loader checks the integrity of the script files it fetches and refuses a copy that was changed on the way. Sites behind Cloudflare shows the settings for Cloudflare.

The visitor's address

knownprint needs the address of the visitor's connection: it is part of the event (network.ip), the network and location signals describe it, and it is the unit of the per-address rate limits.

The rule sends the address your server sees for the connection, together with your proxy secret. knownprint accepts that address only from a request that carries a valid proxy secret of the page's environment. A request without it, or with a wrong or retired secret, is taken at face value: its address is the address that connected to knownprint, which is your server. Then:

  • every event shows your server's address in network.ip;
  • the network and location signals describe your hosting provider, not the visitor;
  • all your visitors share one address in knownprint's per-address rate limits, so busy pages start to see 429 rate_limited;
  • a public key with allowed IP ranges refuses your visitors with 403 ip_not_allowed whenever your server's address is outside those ranges.

To check, identify a browser on your site and read the event from your backend: network.ip must be the public address of the machine you browsed from, not your server's.

Shell
curl "$KNOWNPRINT_API/v1/events/$REQUEST_ID" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY"

Events describes the rest of the event.

Sites behind a CDN or a load balancer

The rule sends the address _your server_ sees. When a CDN or a load balancer stands in front of your server, that address is the CDN's or the load balancer's, unless your server is told to take the visitor's address from what the front end passes on. The address must be right before you go live.

  • Cloudflare with proxied DNS, in front of nginx. Use the Cloudflare variant of the recipe, which takes the visitor's address from Cloudflare's header on connections from Cloudflare's ranges only. See Sites behind Cloudflare.
  • A load balancer or another CDN in front of nginx. Configure nginx's real IP module in your server block, before the knownprint include, so that $remote_addr is the visitor's address. The example follows this list.
  • Caddy behind a CDN or a load balancer. The Caddy snippet passes the address of the connection Caddy accepted. Run it on the server that receives visitors' connections directly, and ask your knownprint contact before you put a Caddy site behind another proxy.

For nginx behind a load balancer, trust only the addresses of your own front end:

server block, before the knownprint include
# Your load balancer's addresses (example values from the documentation ranges).
set_real_ip_from 192.0.2.10;
set_real_ip_from 192.0.2.11;
# The header your load balancer writes the visitor's address into.
real_ip_header X-Forwarded-For;
real_ip_recursive on;

If your load balancer speaks the PROXY protocol, use listen 443 ssl proxy_protocol; and real_ip_header proxy_protocol; instead of the header. Never trust the header from every address: anyone could then send a request that claims any address, and it would reach knownprint signed with your proxy secret.

When several servers answer for your domain (behind a load balancer, or in several regions), every one of them needs the rule and the same proxy secret. When knownprint sends you a new version of the recipe, install it on all of them in the same change rather than one at a time over days.

Other servers

The recipes cover nginx, nginx behind Cloudflare, and Caddy. If your site runs behind another server, a hosting platform's rewrites or an edge function, ask your knownprint contact before you write a rule of your own: the cookie filtering and the headers the recipe sets must be exactly right, and a rule that forwards your session cookies or loses the visitor's address is worse than none.

Troubleshooting

What you seeLikely causeWhat to do
/kp/agent.js answers 404 from your own serverThe rule is not in the server block that answers for this host, or the server was not reloadedCheck the include in the right server block (or import knownprint in the right Caddy site block), test the configuration and reload.
/kp/ paths answer 502 or 504Your server cannot reach knownprintCheck that the upstream address in your copy of the recipe is unchanged and that your server may open outgoing connections to it.
load() rejects with load_failed for every visitorThe loader or the script files do not arrive intact: a CSP that blocks them, a CDN or optimiser that rewrites JavaScript, or a loader cached too longCheck Content Security Policy, exclude /kp/ from rewriting and from cache overrides.
403 origin_not_allowedThe page's origin is not on the public key's allowed origins, or a rule strips the Origin headerAdd the exact origin to the key; remove any rule that touches headers on /kp/.
Every event shows your server's address in network.ipThe proxy secret is missing, wrong or retired, or the request did not go through the ruleCheck the secret against your account, check that it belongs to the page's environment, and reload.
Every event shows your CDN's or load balancer's addressYour server does not take the visitor's address from the front endSee Sites behind a CDN or a load balancer.
Many 429 rate_limited answers on /kp/c or /kp/iAll visitors appear under one address (one of the two rows above)Fix the address first; see Limits for the limits themselves.
403 ip_not_allowedThe public key has allowed IP ranges and the address knownprint saw is outside them, often because it is your server'sFix the address, or the key's ranges (API keys).
Returning visitors are rarely recognisedknownprint's cookie does not survive: the page is not https, something removes Set-Cookie on /kp/i, or one of several servers forwards no cookieCheck the response headers of /kp/i in the browser's developer tools, and that every server runs the same recipe.
410 answers on /kp/l/... or /kp/b/...A follow-up of the agent was not recordedNothing: this is expected and harmless.
/.well-known/knownprint.json answers 404 or 403The file is missing or your server cannot read itInstall it at /usr/local/share/knownprint/knownprint.json, readable by everyone (mode 0644).

Server-specific errors, such as configuration test failures, are on the nginx, Caddy and Cloudflare pages. When the rule works, continue with the browser agent and, before launch, Go live.