@valiron/crawler-protection 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,12 +30,14 @@ The package also includes returning-browser recognition, folded in from the form
30
30
 
31
31
  Recognition is **evidence, not a verdict**: no risk score, no block decision, no enforcement hook. `similar` means "this browser resembles one we have seen" - shared devices, corporate fleets and fresh installs all produce false links, so a `similar` link is never sufficient grounds to deny or limit service.
32
32
 
33
- Mount the middleware to expose the endpoints, then call the browser collector to begin recognition:
33
+ With SDK 0.5.0 or later, mount the middleware to expose the endpoints, then call the browser collector to begin recognition:
34
34
 
35
35
  ```ts
36
- import { DeviceIdentity, RedisIdentityStore, createNodeDeviceIdentityMiddleware } from '@valiron/crawler-protection';
36
+ import { activateCrawlerProtection, DeviceIdentity, RedisIdentityStore, createNodeDeviceIdentityMiddleware } from '@valiron/crawler-protection';
37
37
 
38
+ const activation = await activateCrawlerProtection({ apiKey: process.env.VALIRON_API_KEY!, tenant: process.env.VALIRON_TENANT! });
38
39
  const identity = new DeviceIdentity({
40
+ activation,
39
41
  salt: process.env.DEVICE_IDENTITY_SALT!, // per-deployment, 16+ chars, from a secret manager
40
42
  cookie: {
41
43
  name: '__Host-vid',
@@ -63,7 +65,7 @@ Privacy properties enforced in code:
63
65
  - The cookie carries only a random id and an HMAC - no device data.
64
66
  - `identity.forget(visitorId)` deletes a profile and its index entries (data-subject deletion hook).
65
67
 
66
- Every default here - 30-day retention, the 8/11.5 similarity threshold, the 180-day example cookie lifetime, optional privacy-signal handling - is a placeholder so the module runs, **not an approved production policy**. Before production rollout, the deployment must explicitly decide: consent flow per jurisdiction (a first-party identification cookie is not strictly necessary for most sites), DNT/GPC behavior, retention, similarity-threshold tuning against real traffic, what may consume `similar` links (recommend observe-only analytics first; the link graph is attacker-influenceable, though links and matched ids never leave the server), and cookie lifetime/rotation. Account metering/gating for this module is likewise a follow-up decision; activation is not currently required to use it.
68
+ Every default here - 30-day retention, the 8/11.5 similarity threshold, the 180-day example cookie lifetime, optional privacy-signal handling - is a placeholder so the module runs, **not an approved production policy**. Before production rollout, the deployment must explicitly decide: consent flow per jurisdiction (a first-party identification cookie is not strictly necessary for most sites), DNT/GPC behavior, retention, similarity-threshold tuning against real traffic, what may consume `similar` links (recommend observe-only analytics first; the link graph is attacker-influenceable, though links and matched ids never leave the server), and cookie lifetime/rotation. SDK 0.5.0 requires account-bound activation for this module. Each `recognize()` call consumes one bot-quota admission before identity storage. Missing/revoked/expired activation and unavailable quota checks stop recognition; its middleware returns 429 for quota exhaustion and 503 for unavailable admission. Exclude the recognition endpoint from outer request admission if it would otherwise admit that same HTTP request twice. Previous public releases cannot be retroactively restricted.
67
69
 
68
70
  ## Account activation and monthly usage
69
71
 
@@ -290,7 +292,7 @@ Directory data attribution: Verified Bots Directory by Mayank Gupta (https://ver
290
292
 
291
293
  Monthly bot quotas require Crawler SDK 0.3.0 or later. Upgrade existing 0.2.x deployments to use Free accounts and hosted per-request quota admission. Earlier public SDK versions are not retroactively metered.
292
294
 
293
- Free includes 10,000 protected HTTP requests per UTC calendar month; Pro ($149/month) includes 100,000. The bot allowance is independent from agent access and shared across an account's API keys, sites and replicas. Local access/rate denials run before hosted quota admission and do not consume the allowance. Once hosted admission succeeds, the request is counted even if a later work-capacity check fails. Quota exhaustion returns HTTP 429; an unavailable usage check fails closed with 503. This adds a hosted round trip before protected origin work. Enterprise: email founders@valiron.co.
295
+ Free includes 10,000 protected HTTP requests per UTC calendar month; Pro ($149/month) includes 100,000. The bot allowance is independent from agent access and shared across an account's API keys, sites and replicas. Local access/rate denials run before hosted quota admission and do not consume the allowance. Once hosted admission succeeds, the request is counted even if a later work-capacity check fails. Quota exhaustion returns HTTP 429; an unavailable usage check fails closed with 503. This adds a hosted round trip before protected origin work. Pro can enable additional crawler calls at 0.001 each in the subscription billing currency after explicit price acceptance; Free remains capped at 10,000. Unconfigured or inactive usage billing retains the 100,000 Pro cap. Enterprise: email founders@valiron.co.
294
296
 
295
297
  ## Security compatibility and admission recovery
296
298
 
@@ -323,3 +325,7 @@ Trust boundaries, deliberately stricter than the draft minimum:
323
325
  - Freshness is not replay protection. The draft's minimum coverage binds only `@authority`, so a captured signature can be replayed against this origin until `expires` (bounded to the draft's recommended 24-hour maximum, configurable down). Verified signers remain subject to every budget, which bounds replay damage; `profile: 'strict'` additionally requires `@method` and `@path` coverage. The strict profile is a Valiron-specific strengthening, not a standard compliance claim.
324
326
  - The protocol is a draft. Verification is signature-only and tolerates non-Web-Bot-Auth signatures on the same request; expect wire-format changes before RFC publication.
325
327
 
328
+
329
+ ## Request usage
330
+
331
+ [Dashboard → Usage](https://www.valiron.co/dashboard/usage) shows account-wide monthly crawler requests, remaining allowance, additional calls and estimated request-overage charges. It refreshes every 15 seconds while visible. Free includes 10,000; Pro includes 100,000 and separately opted-in additional requests at 0.001 each in the accepted subscription currency. Middleware has a separate allowance and opt-in. Traffic charts come from optional runtime telemetry; billing counts come from hosted admission.
@@ -1,18 +1,4 @@
1
- /**
2
- * Valiron Device Identity.
3
- *
4
- * Recognizes a returning browser from two independent signal classes:
5
- * 1. deterministic - the server-signed first-party visitor cookie
6
- * 2. probabilistic - coarsened device signals, compared per component
7
- *
8
- * The output is identification evidence, nothing more. This package has no
9
- * notion of fraud, risk, or enforcement. A 'similar' result means "this
10
- * browser resembles a browser we have seen"; it does not establish the
11
- * same person (shared devices, managed fleets, fresh installs all break
12
- * that inference), and it is never sufficient grounds to deny service.
13
- * Abuse decisions belong to the policy layer (crawler protection, the
14
- * identity gate), which may consume this evidence alongside its own.
15
- */
1
+ import { type CrawlerActivation } from "../activation";
16
2
  import { type CookieOptions } from './cookie';
17
3
  import { type RawSignals } from './signals';
18
4
  import { type IdentityStore } from './store';
@@ -44,6 +30,8 @@ export type RecognizeResult = Readonly<{
44
30
  setCookie: string;
45
31
  }>;
46
32
  export type DeviceIdentityOptions = Readonly<{
33
+ /** Account-bound activation from the server-side operator API key. */
34
+ activation: CrawlerActivation;
47
35
  /** Per-deployment salt for component hashes. Required; never shared across deployments. */
48
36
  salt: string;
49
37
  /** Bump when rotating the salt. Old profiles stop matching similarity lookups after rotation. */
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceIdentity = exports.COMPONENT_WEIGHTS = void 0;
4
+ const activation_1 = require("../activation");
2
5
  /**
3
6
  * Valiron Device Identity.
4
7
  *
@@ -14,8 +17,6 @@
14
17
  * Abuse decisions belong to the policy layer (crawler protection, the
15
18
  * identity gate), which may consume this evidence alongside its own.
16
19
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.DeviceIdentity = exports.COMPONENT_WEIGHTS = void 0;
19
20
  const node_crypto_1 = require("node:crypto");
20
21
  const cookie_1 = require("./cookie");
21
22
  const signals_1 = require("./signals");
@@ -45,6 +46,8 @@ class DeviceIdentity {
45
46
  hardMismatch;
46
47
  constructor(options) {
47
48
  this.options = options;
49
+ (0, activation_1.validateActivation)(options.activation);
50
+ (0, activation_1.assertActivation)(options.activation);
48
51
  if (typeof options.salt !== 'string' || options.salt.length < 16 || options.salt.length > 256) {
49
52
  throw new Error('Invalid identity salt');
50
53
  }
@@ -118,6 +121,8 @@ class DeviceIdentity {
118
121
  * continuity belongs only to the browser that actually holds the cookie.
119
122
  */
120
123
  async recognize(input) {
124
+ (0, activation_1.assertActivation)(this.options.activation);
125
+ await this.options.activation.consume();
121
126
  const now = this.now();
122
127
  const signals = (0, signals_1.normalizeSignals)(input.signals ?? {});
123
128
  const verified = (0, cookie_1.verifyVisitorCookie)(this.options.cookie, input.cookieHeader, now);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEVICE_IDENTITY_DEFAULT_BASE_PATH = void 0;
4
4
  exports.deviceIdentityCollectorScript = deviceIdentityCollectorScript;
5
5
  exports.createNodeDeviceIdentityMiddleware = createNodeDeviceIdentityMiddleware;
6
+ const activation_1 = require("../activation");
6
7
  const collector_script_1 = require("./collector-script");
7
8
  exports.DEVICE_IDENTITY_DEFAULT_BASE_PATH = '/api/valiron/device-identity';
8
9
  let collectorCache;
@@ -102,7 +103,9 @@ function createNodeDeviceIdentityMiddleware(config) {
102
103
  // evidence would let a caller mimicking another browser's signals
103
104
  // harvest that browser's identity.
104
105
  sendJson(response, 200, { state: recognition.state }, { 'Set-Cookie': setCookie });
105
- })().catch(next);
106
+ })().catch((error) => {
107
+ sendJson(response, error instanceof activation_1.CrawlerMonthlyLimitError ? 429 : 503, { error: error instanceof activation_1.CrawlerMonthlyLimitError ? "monthly_request_limit_exceeded" : "recognition_unavailable" });
108
+ });
106
109
  return;
107
110
  }
108
111
  next();
package/dist/index.d.ts CHANGED
@@ -15,6 +15,6 @@ export * from './gateway';
15
15
  export * from './telemetry';
16
16
  export * from './directory';
17
17
  export * from './webbotauth';
18
- export { createCrawlerActivation, activateCrawlerProtection, CRAWLER_ACTIVATION_ENDPOINT, type CrawlerActivation } from './activation';
18
+ export { CrawlerMonthlyLimitError, createCrawlerActivation, activateCrawlerProtection, CRAWLER_ACTIVATION_ENDPOINT, type CrawlerActivation } from './activation';
19
19
  export { DeviceIdentity, MemoryIdentityStore, RedisIdentityStore, createNodeDeviceIdentityMiddleware, deviceIdentityCollectorScript, serializeCookieClear, DEVICE_IDENTITY_DEFAULT_BASE_PATH, } from './device-identity';
20
20
  export type { DeviceIdentityOptions, DeviceIdentityMiddlewareConfig, Recognition, RecognitionState, RecognizeResult, IdentityStore, StoredProfile, RawSignals, ScreenSignals, CookieOptions, VerifiedCookie, } from './device-identity';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DEVICE_IDENTITY_DEFAULT_BASE_PATH = exports.serializeCookieClear = exports.deviceIdentityCollectorScript = exports.createNodeDeviceIdentityMiddleware = exports.RedisIdentityStore = exports.MemoryIdentityStore = exports.DeviceIdentity = exports.CRAWLER_ACTIVATION_ENDPOINT = exports.activateCrawlerProtection = exports.createCrawlerActivation = void 0;
17
+ exports.DEVICE_IDENTITY_DEFAULT_BASE_PATH = exports.serializeCookieClear = exports.deviceIdentityCollectorScript = exports.createNodeDeviceIdentityMiddleware = exports.RedisIdentityStore = exports.MemoryIdentityStore = exports.DeviceIdentity = exports.CRAWLER_ACTIVATION_ENDPOINT = exports.activateCrawlerProtection = exports.createCrawlerActivation = exports.CrawlerMonthlyLimitError = void 0;
18
18
  __exportStar(require("./ip"), exports);
19
19
  __exportStar(require("./verification"), exports);
20
20
  __exportStar(require("./admission"), exports);
@@ -33,6 +33,7 @@ __exportStar(require("./telemetry"), exports);
33
33
  __exportStar(require("./directory"), exports);
34
34
  __exportStar(require("./webbotauth"), exports);
35
35
  var activation_1 = require("./activation");
36
+ Object.defineProperty(exports, "CrawlerMonthlyLimitError", { enumerable: true, get: function () { return activation_1.CrawlerMonthlyLimitError; } });
36
37
  Object.defineProperty(exports, "createCrawlerActivation", { enumerable: true, get: function () { return activation_1.createCrawlerActivation; } });
37
38
  Object.defineProperty(exports, "activateCrawlerProtection", { enumerable: true, get: function () { return activation_1.activateCrawlerProtection; } });
38
39
  Object.defineProperty(exports, "CRAWLER_ACTIVATION_ENDPOINT", { enumerable: true, get: function () { return activation_1.CRAWLER_ACTIVATION_ENDPOINT; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valiron/crawler-protection",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Valiron Crawler Protection: HTTP gateway and shared workload admission for any website backend",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",