@steadphast/connector-nextjs 0.6.0 → 0.7.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
@@ -9,6 +9,16 @@ any classification, and never changes the response your visitor receives.
9
9
  The package is one connector with two modes: **Next.js on Vercel** (`kind: "vercel"`) and
10
10
  **Next.js self-hosted** (`kind: "self-hosted"`).
11
11
 
12
+ The optional App Router `DiscoverCollector` component has independent T0 and Family C controls.
13
+ The unreleased Family C addition ships OFF at the API (`BEHAVIORAL_ENABLED` defaults false) and
14
+ does nothing useful until Steadphast announces enablement; do not configure routes yet. Once
15
+ enabled it uses own mode, not visitor permission: exact nonsensitive routes are required, and
16
+ affirmative visitor consent is the default (a no-prompt `notice` basis applies only where Steadphast
17
+ has recorded it for the workspace and `behavioral.consentBasis` is also `"notice"`). Timing
18
+ defaults false and needs both the site and the workspace switch. See
19
+ [Family C own collection](#family-c-own-collection-unreleased); this is not a claim that the
20
+ published 0.6.0 artifact already contains Family C.
21
+
12
22
  ```text
13
23
  Visitor / bot Your Next.js deployment Steadphast
14
24
  ───────────── ─────────────────────── ──────────
@@ -32,8 +42,8 @@ authoritative terms.
32
42
  ## Requirements
33
43
 
34
44
  - Next.js 15 or 16 (`^15.0.0 || ^16.0.0`) and React 19 (`^19.0.0`) are peer dependencies.
35
- Tested with Next.js 15.5.23 (`middleware.ts`) and 16.3.2 (`proxy.ts`); other releases on
36
- those two Next.js lines are expected to work. Next.js 14 and earlier are not supported.
45
+ The exact-runtime fixtures pin Next.js 15.5.28 (`middleware.ts`) and 16.3.2 (`proxy.ts`);
46
+ other releases on those two lines are expected to work. Next.js 14 and earlier are unsupported.
37
47
  - A Steadphast API key, created in the dashboard under **Settings → API keys** with **Used with**
38
48
  set to the mode you deploy: **Next.js on Vercel** or **Next.js self-hosted**. A key is issued for
39
49
  one deployment mode and is rejected by the other.
@@ -384,6 +394,12 @@ type DiscoverNextConfig = (
384
394
  excludedHeaders?: ReadonlyArray<string>;
385
395
  recordIdPrefix?: string;
386
396
  timeoutMs?: number;
397
+ collector?: boolean;
398
+ behavioral?: {
399
+ mode?: "own" | "off" | "partner";
400
+ timing?: boolean;
401
+ routes?: ReadonlyArray<string>;
402
+ };
387
403
  };
388
404
  ```
389
405
 
@@ -394,9 +410,11 @@ type DiscoverNextConfig = (
394
410
  | `apiUrl` | Yes | The Steadphast API origin, `https://api.steadphast.ai`. See [Destination rules](#destination-rules). |
395
411
  | `apiKeyEnvVar` | No | Name of the server-only environment variable holding the API key. Defaults to `STEADPHAST_API_KEY` (`DISCOVER_API_KEY` is still read as a deprecated fallback; migrate to `STEADPHAST_API_KEY`). When set, only the named variable is read. A `NEXT_PUBLIC_*` name is rejected. |
396
412
  | `captureAllPaths` | No | Static assets (scripts, styles, images, fonts, and similar) are skipped by default, except `robots.txt` and `sitemap.xml`. Set `true` to capture every path the matcher allows. |
397
- | `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookies are captured unless you exclude them. |
413
+ | `excludedHeaders` | No | Header names (case-insensitive) to remove from the captured header map. Cookie values are never sent; list `cookie` or `set-cookie` to also drop the cookie names taken from that header (see [Cookies, query strings, and Referer](#cookies-query-strings-and-referer)). |
398
414
  | `recordIdPrefix` | No | A short label that prefixes the record IDs Steadphast assigns, useful for telling deployments apart. Defaults to `vercel-routing-middleware` or `nextjs-self-hosted`. Limit: 128 UTF-8 bytes. A longer value is not rejected at startup but makes every capture drop silently. |
399
415
  | `timeoutMs` | No | Delivery timeout in milliseconds. Defaults to `5000`. |
416
+ | `collector` | No | T0 remains explicit opt-in with `true`. An explicit `false` also vetoes Family C; leaving it undefined permits independently configured Family C without T0. |
417
+ | `behavioral` | No | Inert until Steadphast enables the API switch (`BEHAVIORAL_ENABLED` defaults false); until then approved routes only add `no-store` and a policy fetch that answers off. Once enabled: own mode, timing/default-false, exact nonsensitive `routes` required. `off` and `partner` install no own collector. Workspace/API OFF and visitor consent remain independent controls. `consentBasis: "notice"` starts the window without a consent callback only when Steadphast has also set the workspace's audited consent basis to `notice`; the default is `affirmative`. `pathCapture: true` adds click target geometry (no label, text or element identity) to click records, and only when the workspace's path capture setting is also on; default off. |
400
418
 
401
419
  `kind`, `publicOrigin`, `apiUrl`, and the `NEXT_PUBLIC_*` rule for `apiKeyEnvVar` are validated
402
420
  when the entry file is evaluated: an invalid value throws a `DiscoverConfigError`, so those
@@ -430,7 +448,9 @@ installations, ends at `platform` as in 0.5.x.
430
448
 
431
449
  - **Request:** method, URL, and headers. The connector reads nothing else. It never reads, clones,
432
450
  buffers, or transmits the request body, so every downstream body consumer in your application
433
- remains callable.
451
+ remains callable. The URL keeps its query keys but not their values, cookie values are never
452
+ sent, and `Referer` is reduced to its origin (see
453
+ [Cookies, query strings, and Referer](#cookies-query-strings-and-referer)).
434
454
  - **Platform (Vercel):** Vercel's protected client IP, request ID (`x-vercel-id`), and the JA4 and
435
455
  JA3 TLS-fingerprint digests when Vercel supplies them.
436
456
  - **Platform (self-hosted):** the client IP and request ID nginx sets in `X-Steadphast-Client-Ip`
@@ -452,10 +472,11 @@ Headers pass through two filters before anything is serialized:
452
472
  built-in exclusions ── a fixed list of recognized credential header names
453
473
  │ and a few name patterns (see below)
454
474
  ▼
455
- your excludedHeaders ── e.g. cookie, and every application-specific credential header
475
+ your excludedHeaders ── every application-specific credential header
456
476
  │
457
477
  ▼
458
- captured header map (everything else, cookies included unless excluded)
478
+ captured header map (everything else; cookie values replaced by cookie names,
479
+ Referer reduced to its origin, URL-bearing headers redacted)
459
480
  ```
460
481
 
461
482
  The built-in filter is a **limited, fixed set**, not a general secret detector. Names are compared
@@ -488,10 +509,45 @@ Every other header is captured, including custom credential headers such as `x-t
488
509
  headers your application, its upstream proxies, and its third-party integrations attach, and list
489
510
  every credential-bearing name in `excludedHeaders`.
490
511
 
491
- Other headers, including cookies, are captured by default, so exclude them explicitly wherever that
492
- is not acceptable. Excluding a header removes it from the generic header map only; it does not
493
- remove a value that a dedicated field separately carries (for example the user agent). Query
494
- strings can contain sensitive values, so avoid placing secrets or personal data in public URLs.
512
+ Excluding a header removes it from the generic header map only; it does not remove a value that a
513
+ dedicated field separately carries (for example the user agent).
514
+
515
+ ### Cookies, query strings, and Referer
516
+
517
+ These rules apply to every installation, with no configuration, from the first release after
518
+ 0.6.0 (ADR 0017 amendment, 2026-11-17):
519
+
520
+ - **Cookies.** `Cookie` and `Set-Cookie` values are never sent. The captured map instead carries
521
+ `x-steadphast-cookie-names`: the cookie names only, de-duplicated, sorted, and capped at 32 names
522
+ and 1024 bytes. A name must be 1 to 64 RFC 6265 token characters; anything else is dropped. Each
523
+ `Set-Cookie` value contributes only its first name (values are never split on commas). The
524
+ connector removes any `x-steadphast-cookie-names` header the visitor sends. List `cookie` or
525
+ `set-cookie` in `excludedHeaders` to drop the names taken from that header, or
526
+ `x-steadphast-cookie-names` to drop the marker entirely.
527
+ - **Query strings and paths.** `external_url` keeps every query key but empties every value, so
528
+ `/a?utm_source=x&token=abc&flag` is sent as `/a?utm_source=&token=&flag=`. In the path, matrix
529
+ parameter values are emptied (`;jsessionid=abc` becomes `;jsessionid=`) and an encoded query
530
+ starting at `%3F` is treated like a query. The exceptions are requests carrying signature headers
531
+ (a `Signature` header and a `Signature-Input`): one that covers `@query`, `@query-param`,
532
+ `@target-uri`, or `@request-target` keeps its full URL, and one that covers `@path` keeps its raw
533
+ path, because Steadphast needs those exact bytes to verify the RFC 9421 signature. Any visitor
534
+ can send such headers for their own request. The server empties query values before it stores
535
+ the request path either way.
536
+ - **Referer.** `Referer` (and the `Referrer` misspelling) is reduced to its origin,
537
+ `scheme://host[:port]`: path, query, and fragment are removed. A value that is not an absolute
538
+ `http:` or `https:` URL, or that carries credentials (`user@host`), a `%` escape or non-ASCII
539
+ character in the host, a backslash, or whitespace, is dropped entirely rather than repaired.
540
+ - **Other URL-bearing headers.** `Next-Router-State-Tree` and `Next-Url`, which embed the page's
541
+ query values on client navigations, are sent only as the value `present`. The proxy headers
542
+ `X-Forwarded-Uri`, `X-Original-Url`, `X-Original-Uri`, `X-Envoy-Original-Path`, and
543
+ `X-Rewrite-Url`, and any other header whose value starts with `/`, `//`, `http://`, or `https://`
544
+ and contains `?`, are sent with query values emptied, the fragment removed, and any credentials
545
+ dropped from the host.
546
+ - **Signed header values.** A signature covering one of the headers above cannot be verified from
547
+ the minimized value, so that header's raw value is never sent and the signature is reported
548
+ `unattemptable`.
549
+
550
+ Even so, avoid placing secrets or personal data in URL paths or query keys.
495
551
 
496
552
  ### Size limits
497
553
 
@@ -512,6 +568,90 @@ Delivery does not block the visitor response: the connector serializes the recor
512
568
  changes the response status, headers, or body, and never propagates an error into your composed
513
569
  handler.
514
570
 
571
+ ## Family C own collection (unreleased)
572
+
573
+ Family C ships OFF: the API switch `BEHAVIORAL_ENABLED` defaults to false, and this version is not
574
+ published until Steadphast announces enablement. Do not configure routes before then; while OFF an
575
+ approved route only adds `no-store` delivery and a policy fetch that answers off.
576
+
577
+ After enablement, use the existing `DiscoverCollector` server component on supported uncached Node
578
+ App Router documents and add `behavioral: { routes: ["/catalog"], timing: false }` to its shared
579
+ server configuration. Choose routes deliberately; authentication, payment, transaction and health
580
+ routes and sensitive fields remain excluded. An absent route list collects nothing. Explicit
581
+ `collector: false` or `behavioral.mode: "off"` wins over workspace own mode.
582
+
583
+ Workspace owners/admins can independently disable own collection or enable timing in Settings.
584
+ API OFF wins over both. Server rendering fetches current policy without
585
+ caching, with a 250 ms deadline; failure emits no T1 script. This can add bounded page-render
586
+ latency, not a wait for user interaction or a change to classification latency.
587
+
588
+ Connect your actual consent manager through the browser-safe entry:
589
+
590
+ ```ts
591
+ import {
592
+ setBehavioralConsent,
593
+ disableBehavioralCollection,
594
+ closeBehavioralRoute,
595
+ } from "@steadphast/connector-nextjs/client";
596
+
597
+ // Only after affirmative permission; also handle steadphast:behavioral-ready.
598
+ setBehavioralConsent(true);
599
+ // Revoke permission and discard this document's unsent window.
600
+ setBehavioralConsent(false, true);
601
+ // Local OFF: synchronous listener removal and discard.
602
+ disableBehavioralCollection();
603
+ // Before a programmatic SPA transition: close, never continue the window.
604
+ closeBehavioralRoute();
605
+ ```
606
+
607
+ Unknown or denied consent installs no interaction listeners. T0 permission is not Family C consent.
608
+ The one exception is the two-key `notice` basis: when the workspace policy (set only by Steadphast,
609
+ with an audited change record) and `behavioral.consentBasis` both say `notice`, the window starts at
610
+ render, or when a background page first becomes visible, without a callback. Your privacy notice
611
+ must describe the collection. Revocation and `disableBehavioralCollection()` still discard it.
612
+ The library does not retain a consent call made before the collector registers; replay your real
613
+ consent-manager state on `steadphast:behavioral-ready`. Revoked/closed documents cannot restart.
614
+ Remote workspace OFF rejects old-policy submissions and suppresses later renders, but does not
615
+ instantly remove listeners from an already-open disconnected page. There is no polling or retry.
616
+
617
+ One window ends at 30 seconds, 100 actions or first hide, with at most one 4 KiB beacon,
618
+ 30 Hz/1,024 pointer/touch samples and bounded timing intervals. Key records are timing only: the
619
+ collector reads no key identity (`keyCode` only to compare it with 229, for IME composition) and
620
+ sends no character or key class, and drops modifier, shifted, shortcut and IME composition keys.
621
+ The number of key records, which roughly tracks the length of what was typed, leaves the browser;
622
+ dwell and flight values are sent sorted and rounded down to 10 ms. Values, clipboard text,
623
+ passwords, one-time codes, hidden fields, free-text content, payment/transaction/health fields,
624
+ contenteditable content, DOM identifiers and cross-page identifiers are never collected.
625
+ With timing on (site and workspace), the window also sends one connection timing value.
626
+ Collectors from this release add further interaction counts on eligible controls and tagged form
627
+ fields. Counts only: no value, key, text or element identity.
628
+ Use `data-discover-sensitive` for sensitive subtrees, and for any password field with a "show
629
+ password" toggle. Only explicitly reviewed `data-discover-nonsensitive="true"` buttons, selects and
630
+ range/number/checkbox/radio inputs permit key/paste/input observations; tagged
631
+ text/search/email/tel/url inputs and textareas, including fields that ask for the visitor's
632
+ details, give key timing and, from a collector that reports rule version 3 counts, interaction
633
+ counts, and nothing else: never a value, key, text or which field. Never tag a sensitive control
634
+ as nonsensitive.
635
+
636
+ Open-shadow origins and exposed slot/ancestor exclusions are checked transiently; paths, nodes and
637
+ native events are not retained. Unknown or opaque origin hosts abstain even when tagged safe.
638
+ **Closed-root installation prerequisite:** mark a sensitive/opaque component's light-DOM host or
639
+ enclosing visible subtree `data-discover-sensitive`, including its slotted light-DOM controls.
640
+ A tagged nonsensitive child cannot override that boundary. Passive DOM APIs can hide an internal
641
+ sensitive slot ancestor; null `shadowRoot`/`assignedSlot` and missing exposed marks are not proof
642
+ of safety. There is no closed-root probing or prototype instrumentation. If you cannot establish
643
+ and mark the boundary, leave that route unapproved or explicitly OFF. Unmarked opaque installs
644
+ are unsupported; workspace own mode is separate from route approval and visitor consent.
645
+
646
+ The API derives a summary in memory and stores no raw record array. Pending summaries expire at
647
+ 23 hours and attached summaries at 179 days from original receipt; event/subject deletion removes
648
+ linked evidence earlier. Physical purge must remain within the 24-hour/180-day ceilings, including
649
+ outage recovery and lock/pool starvation; the safety margins are one hour and one day, and reader
650
+ expiry alone is not physical deletion. The existing event detail shows
651
+ observations and honest coverage without changing its original verdict. Behavioral predicates and
652
+ partner intake are not released; synthetic engineering controls are not the required human/agent
653
+ evaluation. Customer install/privacy wording and consent review remain required before deployment.
654
+
515
655
  ## Optional: the T0 client collector
516
656
 
517
657
  Unreleased version 0.6.0 adds the **T0 client collector**: a small clean-room script, inlined into
@@ -596,6 +736,10 @@ then removes its listeners, worker, Blob URL and iframe. The bundle is gated bel
596
736
  Availability is factual: `available`, `unsupported-api`, `script-failure`, `background-tab`,
597
737
  `early-exit` or `insufficient-observation`. Missing realms are not disagreements; discarded fields
598
738
  cannot leave stale cross-realm findings. Availability alone changes no classification verdict.
739
+ The full browser version list is sent only when the worker reports client hints to compare it
740
+ with, so an ordinary Chrome beacon fits the budget untrimmed. Trimming optional detail keeps
741
+ `available`; only a trim that removes a field the server's verdict reads, or a cross-realm
742
+ finding, reports `insufficient-observation`.
599
743
 
600
744
  **Content-Security-Policy.** Supply an independently server-generated application CSP nonce as
601
745
  `<DiscoverCollector config={discoverConfig} nonce={cspNonce} />`; never read it from an unsanitized
@@ -615,13 +759,18 @@ nix develop -c pnpm -C ts --filter @steadphast/connector-nextjs build
615
759
  nix develop -c pnpm -C ts deadcode
616
760
  ```
617
761
 
618
- The build has two public entries and two repository-only loopback fixture entries. Knip tracks
762
+ The build has three public entries and two repository-only loopback fixture entries. Knip tracks
619
763
  the build entrypoints explicitly because the Next.js fixtures import their compiled paths;
620
764
  the private entries remain excluded from package exports and published files. The hosted
621
765
  `nextjs-connector-checks` gate exercises both supported runtimes through nginx and the live API.
622
766
  The durable replay test waits for the first committed value and then for every replay job to
623
767
  settle; asynchronous acceptance does not promise FIFO completion.
624
768
 
769
+ Family C's jsdom controls exercise consent/revocation, first-hide/BFCache/SPA closure, masking,
770
+ sample/action/body bounds and timing abstention deterministically. They do not emulate native
771
+ hardware or satisfy the independent human/agent corpus; real connector → API/Postgres → reader
772
+ verification remains separate.
773
+
625
774
  ## Troubleshooting
626
775
 
627
776
  - **No events appear:** switch the Explore traffic filter to all traffic first, because the default
@@ -646,14 +795,20 @@ settle; asynchronous acceptance does not promise FIFO completion.
646
795
  the `proxy_set_header Host` lines, and `publicOrigin` agree with each other.
647
796
  - **Self-hosted URLs show the wrong host:** `publicOrigin` does not match the public scheme, host,
648
797
  and port nginx serves; it is never derived from request headers.
649
- - **Cookies still appear:** confirm `excludedHeaders: ["cookie"]` is present in the deployed entry
650
- file.
798
+ - **Cookie values or query values appear:** confirm the deployed connector is newer than 0.6.0;
799
+ 0.6.0 and earlier sent them unless excluded.
651
800
  - **Your site response fails:** inspect your own handler and application route. Steadphast delivery
652
801
  failures are swallowed and never change the response.
653
802
 
654
803
  ## Upgrading
655
804
 
656
- - **0.6.0** (unreleased) adds the opt-in T0 client collector. It also stops sending the
805
+ - **Unreleased (next version after 0.6.0)** never sends cookie values (only the
806
+ `x-steadphast-cookie-names` marker),
807
+ empties query values in `external_url` except for a request carrying signature headers that
808
+ cover the query, and reduces `Referer` to its origin. See
809
+ [Cookies, query strings, and Referer](#cookies-query-strings-and-referer). No configuration
810
+ change is needed; an existing `excludedHeaders: ["cookie"]` now also drops the cookie names.
811
+ - **0.6.0** adds the opt-in T0 client collector. It also stops sending the
657
812
  `Payment-Authorization` credential and sends the `x-steadphast-payment-credential` presence
658
813
  marker in its place. Upgrade the connector and the Steadphast API together: the API rejects an
659
814
  older envelope that still carries `Payment-Authorization`.
@@ -0,0 +1,8 @@
1
+ /** Stringified after compilation; every runtime dependency lives inside this function. */
2
+ export declare function behavioralCollector(nonce: string, endpoint: string, timing: boolean, issuedAt: number, route: string, notice?: boolean, pathCapture?: boolean): void;
3
+ /** Call from the customer's consent callback; revocation closes this document permanently. */
4
+ export declare function setBehavioralConsent(granted: boolean, revoked?: boolean): void;
5
+ /** Synchronous browser-local OFF: listeners removed and unsent buffers discarded. */
6
+ export declare function disableBehavioralCollection(): void;
7
+ /** Call before a programmatic SPA transition when the browser has no navigation event. */
8
+ export declare function closeBehavioralRoute(): void;
@@ -0,0 +1 @@
1
+ export { setBehavioralConsent, disableBehavioralCollection, closeBehavioralRoute, } from "./behavioral-collector.js";
package/dist/client.js ADDED
@@ -0,0 +1,19 @@
1
+ // src/behavioral-collector.ts
2
+ function setBehavioralConsent(granted, revoked = false) {
3
+ window.dispatchEvent(
4
+ new CustomEvent("steadphast:behavioral-consent", {
5
+ detail: { granted, revoked }
6
+ })
7
+ );
8
+ }
9
+ function disableBehavioralCollection() {
10
+ window.dispatchEvent(new Event("steadphast:behavioral-disable"));
11
+ }
12
+ function closeBehavioralRoute() {
13
+ window.dispatchEvent(new Event("steadphast:behavioral-route"));
14
+ }
15
+ export {
16
+ closeBehavioralRoute,
17
+ disableBehavioralCollection,
18
+ setBehavioralConsent
19
+ };
package/dist/config.d.ts CHANGED
@@ -29,6 +29,24 @@ export interface DiscoverNextCommonConfig {
29
29
  * from visitor headers. Disabled requests have no collector output or envelope keys.
30
30
  */
31
31
  collector?: boolean;
32
+ /**
33
+ * Family C defaults to own, independently of T0. An explicit collector:false or mode:"off"
34
+ * wins. Only exact approved pathnames are eligible; an empty route list collects nothing.
35
+ * Timing remains off unless both this switch and the workspace timing switch are true.
36
+ * Browser consent is supplied separately through the consent event, never by configuration,
37
+ * unless `consentBasis` is "notice" here AND the workspace's Steadphast-set consent basis is
38
+ * "notice" (ADR 0053 amendment, 2026-11-16): then the window starts without a prompt on a site
39
+ * whose privacy notice discloses the collection. Revocation and every OFF control still apply.
40
+ * `pathCapture` likewise needs the workspace's `path_capture_enabled` too: only with both does
41
+ * the page script add each click target's bounding box (geometry only) for pointer-path replay.
42
+ */
43
+ behavioral?: {
44
+ mode?: "own" | "off" | "partner";
45
+ timing?: boolean;
46
+ routes?: ReadonlyArray<string>;
47
+ consentBasis?: "affirmative" | "notice";
48
+ pathCapture?: boolean;
49
+ };
32
50
  }
33
51
  /** The connector configuration: the explicit deployment mode plus the common transport settings. */
34
52
  export type DiscoverNextConfig = DiscoverDeploymentMode & DiscoverNextCommonConfig;
@@ -51,6 +69,7 @@ export declare const BEACON_PATHNAME = "/v1/client/t0";
51
69
  export declare const COLLECTOR_HEADER_PREFIX = "x-steadphast-collector-";
52
70
  /** Authenticated middleware-to-render context, domain-separated from browser beacon nonces. */
53
71
  export declare const COLLECTOR_CONTEXT_HEADER = "x-steadphast-collector-context";
72
+ export declare const BEHAVIORAL_CONTEXT_HEADER = "x-steadphast-collector-behavioral";
54
73
  export declare class DiscoverConfigError extends TypeError {
55
74
  readonly name = "DiscoverConfigError";
56
75
  }