@gate-forge/pack-playwright 0.1.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.
Files changed (140) hide show
  1. package/LICENSE +202 -0
  2. package/bin/gateforge-witness.js +40 -0
  3. package/dist/attestation/proxy.d.ts +40 -0
  4. package/dist/attestation/proxy.d.ts.map +1 -0
  5. package/dist/attestation/proxy.js +78 -0
  6. package/dist/attestation/proxy.js.map +1 -0
  7. package/dist/constants.d.ts +130 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +138 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/discovery/adapters.d.ts +167 -0
  12. package/dist/discovery/adapters.d.ts.map +1 -0
  13. package/dist/discovery/adapters.js +276 -0
  14. package/dist/discovery/adapters.js.map +1 -0
  15. package/dist/discovery/discover.d.ts +57 -0
  16. package/dist/discovery/discover.d.ts.map +1 -0
  17. package/dist/discovery/discover.js +544 -0
  18. package/dist/discovery/discover.js.map +1 -0
  19. package/dist/discovery/index.d.ts +15 -0
  20. package/dist/discovery/index.d.ts.map +1 -0
  21. package/dist/discovery/index.js +15 -0
  22. package/dist/discovery/index.js.map +1 -0
  23. package/dist/discovery/inference.d.ts +63 -0
  24. package/dist/discovery/inference.d.ts.map +1 -0
  25. package/dist/discovery/inference.js +173 -0
  26. package/dist/discovery/inference.js.map +1 -0
  27. package/dist/discovery/pytest-adapter.d.ts +205 -0
  28. package/dist/discovery/pytest-adapter.d.ts.map +1 -0
  29. package/dist/discovery/pytest-adapter.js +548 -0
  30. package/dist/discovery/pytest-adapter.js.map +1 -0
  31. package/dist/discovery/reconcile.d.ts +106 -0
  32. package/dist/discovery/reconcile.d.ts.map +1 -0
  33. package/dist/discovery/reconcile.js +268 -0
  34. package/dist/discovery/reconcile.js.map +1 -0
  35. package/dist/discovery/runner-env.d.ts +80 -0
  36. package/dist/discovery/runner-env.d.ts.map +1 -0
  37. package/dist/discovery/runner-env.js +139 -0
  38. package/dist/discovery/runner-env.js.map +1 -0
  39. package/dist/discovery/static-discovery.d.ts +121 -0
  40. package/dist/discovery/static-discovery.d.ts.map +1 -0
  41. package/dist/discovery/static-discovery.js +1028 -0
  42. package/dist/discovery/static-discovery.js.map +1 -0
  43. package/dist/discovery/supervised-run.d.ts +110 -0
  44. package/dist/discovery/supervised-run.d.ts.map +1 -0
  45. package/dist/discovery/supervised-run.js +328 -0
  46. package/dist/discovery/supervised-run.js.map +1 -0
  47. package/dist/discovery/trusted-config.d.ts +103 -0
  48. package/dist/discovery/trusted-config.d.ts.map +1 -0
  49. package/dist/discovery/trusted-config.js +117 -0
  50. package/dist/discovery/trusted-config.js.map +1 -0
  51. package/dist/fixture/evidence.d.ts +191 -0
  52. package/dist/fixture/evidence.d.ts.map +1 -0
  53. package/dist/fixture/evidence.js +366 -0
  54. package/dist/fixture/evidence.js.map +1 -0
  55. package/dist/fixture/fixture.d.ts +37 -0
  56. package/dist/fixture/fixture.d.ts.map +1 -0
  57. package/dist/fixture/fixture.js +38 -0
  58. package/dist/fixture/fixture.js.map +1 -0
  59. package/dist/fixture/witness-client.d.ts +164 -0
  60. package/dist/fixture/witness-client.d.ts.map +1 -0
  61. package/dist/fixture/witness-client.js +253 -0
  62. package/dist/fixture/witness-client.js.map +1 -0
  63. package/dist/index.d.ts +64 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +55 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/json.d.ts +16 -0
  68. package/dist/json.d.ts.map +1 -0
  69. package/dist/json.js +21 -0
  70. package/dist/json.js.map +1 -0
  71. package/dist/reporter/ledger.d.ts +105 -0
  72. package/dist/reporter/ledger.d.ts.map +1 -0
  73. package/dist/reporter/ledger.js +197 -0
  74. package/dist/reporter/ledger.js.map +1 -0
  75. package/dist/reporter/reporter.cjs +105 -0
  76. package/dist/reporter/reporter.cjs.map +1 -0
  77. package/dist/reporter/reporter.d.cts +35 -0
  78. package/dist/reporter/reporter.d.cts.map +1 -0
  79. package/dist/reporter/reporter.d.ts +167 -0
  80. package/dist/reporter/reporter.d.ts.map +1 -0
  81. package/dist/reporter/reporter.js +673 -0
  82. package/dist/reporter/reporter.js.map +1 -0
  83. package/dist/setup.d.ts +49 -0
  84. package/dist/setup.d.ts.map +1 -0
  85. package/dist/setup.js +167 -0
  86. package/dist/setup.js.map +1 -0
  87. package/dist/supervisor/client.d.ts +73 -0
  88. package/dist/supervisor/client.d.ts.map +1 -0
  89. package/dist/supervisor/client.js +164 -0
  90. package/dist/supervisor/client.js.map +1 -0
  91. package/dist/supervisor/drain.d.ts +45 -0
  92. package/dist/supervisor/drain.d.ts.map +1 -0
  93. package/dist/supervisor/drain.js +235 -0
  94. package/dist/supervisor/drain.js.map +1 -0
  95. package/dist/supervisor/index.d.ts +16 -0
  96. package/dist/supervisor/index.d.ts.map +1 -0
  97. package/dist/supervisor/index.js +13 -0
  98. package/dist/supervisor/index.js.map +1 -0
  99. package/dist/supervisor/spool.d.ts +137 -0
  100. package/dist/supervisor/spool.d.ts.map +1 -0
  101. package/dist/supervisor/spool.js +263 -0
  102. package/dist/supervisor/spool.js.map +1 -0
  103. package/dist/surface.d.ts +134 -0
  104. package/dist/surface.d.ts.map +1 -0
  105. package/dist/surface.js +139 -0
  106. package/dist/surface.js.map +1 -0
  107. package/dist/witness/adapter-registry.d.ts +38 -0
  108. package/dist/witness/adapter-registry.d.ts.map +1 -0
  109. package/dist/witness/adapter-registry.js +158 -0
  110. package/dist/witness/adapter-registry.js.map +1 -0
  111. package/dist/witness/bin.d.ts +21 -0
  112. package/dist/witness/bin.d.ts.map +1 -0
  113. package/dist/witness/bin.js +172 -0
  114. package/dist/witness/bin.js.map +1 -0
  115. package/dist/witness/browser.d.ts +173 -0
  116. package/dist/witness/browser.d.ts.map +1 -0
  117. package/dist/witness/browser.js +580 -0
  118. package/dist/witness/browser.js.map +1 -0
  119. package/dist/witness/classifications.d.ts +42 -0
  120. package/dist/witness/classifications.d.ts.map +1 -0
  121. package/dist/witness/classifications.js +87 -0
  122. package/dist/witness/classifications.js.map +1 -0
  123. package/dist/witness/env-attestation.d.ts +98 -0
  124. package/dist/witness/env-attestation.d.ts.map +1 -0
  125. package/dist/witness/env-attestation.js +202 -0
  126. package/dist/witness/env-attestation.js.map +1 -0
  127. package/dist/witness/loopback-pins.d.ts +79 -0
  128. package/dist/witness/loopback-pins.d.ts.map +1 -0
  129. package/dist/witness/loopback-pins.js +244 -0
  130. package/dist/witness/loopback-pins.js.map +1 -0
  131. package/dist/witness/server.d.ts +34 -0
  132. package/dist/witness/server.d.ts.map +1 -0
  133. package/dist/witness/server.js +2539 -0
  134. package/dist/witness/server.js.map +1 -0
  135. package/dist/witness/types.d.ts +643 -0
  136. package/dist/witness/types.d.ts.map +1 -0
  137. package/dist/witness/types.js +2 -0
  138. package/dist/witness/types.js.map +1 -0
  139. package/package.json +64 -0
  140. package/python/gateforge_persistence_intents.py +100 -0
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Classification loading for the witness (engine-side).
3
+ *
4
+ * The witness needs each resource's `primaryKey` (to bind/stamp
5
+ * persistence records consistently with ADR 0001 D3) and the
6
+ * `evidenceAdapter` alias (resourceId -> adapter file name). It loads
7
+ * the SAME classifications document the run's pipeline uses —
8
+ * `GATEFORGE_CLASSIFICATIONS` — validated fail-closed with the frozen
9
+ * core schema. The map is exposed (primaryKey only) on
10
+ * `GET /classifications` so the reporter can compute faithful per-claim
11
+ * ledger verdicts via `evaluateObligation`.
12
+ */
13
+ import { readFileSync } from 'node:fs';
14
+ import { parse as parseYaml } from 'yaml';
15
+ import { ClassificationFileSchema, } from '@gate-forge/core';
16
+ import { AdapterRegistryError } from './adapter-registry.js';
17
+ /**
18
+ * Loads the classifications document.
19
+ *
20
+ * Args:
21
+ * path: absolute path to the classifications YAML (or null/'' = none).
22
+ *
23
+ * Returns:
24
+ * Record<string, Classification>: validated per-resource map (empty
25
+ * when no document is configured).
26
+ *
27
+ * Throws:
28
+ * AdapterRegistryError: fail-closed load/validation problems.
29
+ */
30
+ export function loadClassifications(path) {
31
+ if (path === null || path === undefined || path === '')
32
+ return {};
33
+ let raw;
34
+ try {
35
+ raw = readFileSync(path, 'utf8');
36
+ }
37
+ catch (error) {
38
+ throw new AdapterRegistryError(`cannot read classifications file '${path}': ${error.message}`);
39
+ }
40
+ let document;
41
+ try {
42
+ document = parseYaml(raw);
43
+ }
44
+ catch (error) {
45
+ throw new AdapterRegistryError(`classifications file '${path}' is not valid YAML: ${error.message}`);
46
+ }
47
+ const parsed = ClassificationFileSchema.safeParse(document);
48
+ if (!parsed.success) {
49
+ const issue = parsed.error.issues[0];
50
+ throw new AdapterRegistryError(`classifications file '${path}' is invalid: ` +
51
+ `${issue === undefined ? 'unknown issue' : `${issue.path.join('.')}: ${issue.message}`}`);
52
+ }
53
+ // Normalize keys to plane-qualified resource ids (ADR 0001 D5.3):
54
+ // a bare `accounts:` entry with `plane: tenant` is keyed
55
+ // `tenant.accounts`; an already-qualified key passes through.
56
+ const qualified = {};
57
+ for (const [key, entry] of Object.entries(parsed.data.resources)) {
58
+ qualified[key.includes('.') ? key : `${entry.plane}.${key}`] = entry;
59
+ }
60
+ return qualified;
61
+ }
62
+ /** Projects a classification for the reporter surface. */
63
+ export function toClassificationView(entry) {
64
+ return {
65
+ primaryKey: [...entry.primaryKey],
66
+ exposure: entry.exposure,
67
+ plane: entry.plane,
68
+ ...(entry.evidenceAdapter === undefined ? {} : { evidenceAdapter: entry.evidenceAdapter }),
69
+ ...(entry.evidenceLane === undefined ? {} : { evidenceLane: entry.evidenceLane }),
70
+ lifecycle: {
71
+ create: entry.lifecycle.create,
72
+ read: entry.lifecycle.read,
73
+ update: entry.lifecycle.update,
74
+ delete: entry.lifecycle.delete,
75
+ ...(entry.lifecycle.deleteSemantics === undefined
76
+ ? {}
77
+ : { deleteSemantics: entry.lifecycle.deleteSemantics }),
78
+ ...(entry.lifecycle.archiveFields === undefined
79
+ ? {}
80
+ : { archiveFields: entry.lifecycle.archiveFields }),
81
+ ...(entry.lifecycle.updateableFields === undefined
82
+ ? {}
83
+ : { updateableFields: [...entry.lifecycle.updateableFields] }),
84
+ },
85
+ };
86
+ }
87
+ //# sourceMappingURL=classifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifications.js","sourceRoot":"","sources":["../../src/witness/classifications.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EACL,wBAAwB,GAEzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AA2B7D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAA+B;IACjE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAClE,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,oBAAoB,CAC5B,qCAAqC,IAAI,MAAO,KAAe,CAAC,OAAO,EAAE,CAC1E,CAAC;IACJ,CAAC;IACD,IAAI,QAAiB,CAAC;IACtB,IAAI,CAAC;QACH,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,oBAAoB,CAC5B,yBAAyB,IAAI,wBAAyB,KAAe,CAAC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,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AM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI;YAC1B,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;YAC9B,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,KAAK,SAAS;gBAC/C,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;YACzD,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,KAAK,SAAS;gBAC7C,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;YACrD,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,gBAAgB,KAAK,SAAS;gBAChD,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,CAAC;SACjE;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,98 @@
1
+ import { type PinDnsLookup } from './loopback-pins.js';
2
+ /** One failed attestation, carrying the actionable diagnostic. */
3
+ export declare class AttestationError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ /**
7
+ * Whether a base URL is loopback. Accepts the standard loopback
8
+ * hostnames/IPs (localhost, 127.0.0.0/8, ::1).
9
+ *
10
+ * Args:
11
+ * baseUrl: absolute http(s) URL.
12
+ *
13
+ * Returns:
14
+ * boolean: true when the host is a recognized loopback host.
15
+ */
16
+ export declare function isLoopbackUrl(baseUrl: string): boolean;
17
+ /**
18
+ * Asserts the attestation subject is loopback (GF-10). Called at witness
19
+ * startup for the target and before EVERY adapter read for the read
20
+ * base. Hostnames that are not literally loopback are resolved through
21
+ * the OS resolver (hosts file + DNS): a name whose addresses are ALL
22
+ * loopback (127.0.0.0/8, ::1) is loopback by construction — the
23
+ * disposable-stack pattern of tenant subdomains mapped to 127.0.0.1.
24
+ * Mixed records, unresolvable names, and lookup failures all reject
25
+ * (fail closed). Approved addresses are PINNED per hostname for the
26
+ * process lifetime (see `loopback-pins.ts`): later DNS changes never
27
+ * move established connections — the check validates
28
+ * OPERATOR-provided bases (never suite input — suites cannot set
29
+ * target/adapter bases), and every egress binds to the startup
30
+ * approval.
31
+ *
32
+ * Args:
33
+ * baseUrl: the base to verify.
34
+ * what: human label for diagnostics ("attestation subject", "adapter 'x'").
35
+ *
36
+ * Throws:
37
+ * AttestationError: when the base is not loopback — the run is BLOCKED
38
+ * before any request is constructed (plan invariant 5).
39
+ */
40
+ export declare function assertLoopback(baseUrl: string, what: string): Promise<void>;
41
+ /** Signature of the DNS lookup injected for tests (defaults to the OS resolver). */
42
+ export type DnsLookup = PinDnsLookup;
43
+ /** Clears the pin store (tests only — production paths pin once and bind). */
44
+ export declare function clearLoopbackCacheForTests(): void;
45
+ /**
46
+ * Whether a base URL is loopback, resolving non-literal hostnames. The
47
+ * sync string check (`isLoopbackUrl`) runs first; only names it rejects
48
+ * reach the resolver, which pins all-loopback answers (see
49
+ * `loopback-pins.ts` — first resolution wins, later DNS changes never
50
+ * replace the pins).
51
+ *
52
+ * Args:
53
+ * baseUrl: absolute http(s) URL.
54
+ * lookupFn: DNS lookup (default: OS resolver via `node:dns/promises`).
55
+ *
56
+ * Returns:
57
+ * Promise<boolean>: true when literally loopback or ALL resolved
58
+ * addresses are loopback. False on mixed records, unresolvable names,
59
+ * lookup failures, and non-http(s) URLs.
60
+ */
61
+ export declare function isLoopbackUrlResolving(baseUrl: string, lookupFn?: DnsLookup): Promise<boolean>;
62
+ /** The observed fingerprint + attestation scope of one target probe. */
63
+ export interface EnvProbe {
64
+ /** Fingerprint marker value, or null when the target presents none. */
65
+ fingerprint: string | null;
66
+ /** Attestation-scope marker value, or null. */
67
+ scope: string | null;
68
+ }
69
+ /**
70
+ * Probes a target's env fingerprint: GET the base and read the marker
71
+ * header. Any transport failure probes as `{fingerprint: null, scope:
72
+ * null}` — absence is a mismatch, never a pass (fail closed).
73
+ *
74
+ * Args:
75
+ * baseUrl: target base to probe.
76
+ * timeoutMs: per-request timeout.
77
+ *
78
+ * Returns:
79
+ * EnvProbe: observed markers (null when absent/unreachable).
80
+ */
81
+ export declare function probeEnvFingerprint(baseUrl: string, timeoutMs: number): Promise<EnvProbe>;
82
+ /**
83
+ * The same-environment rule for one adapter read (GF-13). The adapter
84
+ * base must present a marker EQUAL to the adapter's declared
85
+ * environmentFingerprint, and (when the run pins one) that fingerprint
86
+ * must equal the run's target fingerprint — the adapter may not read a
87
+ * different environment than the UI under test.
88
+ *
89
+ * Args:
90
+ * probe: observed markers at the adapter base.
91
+ * adapterFingerprint: the adapter's declared environmentFingerprint.
92
+ * targetFingerprint: the run's pinned fingerprint, or null when unset.
93
+ *
94
+ * Returns:
95
+ * string | null: mismatch description, or null when attested.
96
+ */
97
+ export declare function envFingerprintMismatch(probe: EnvProbe, adapterFingerprint: string, targetFingerprint: string | null): string | null;
98
+ //# sourceMappingURL=env-attestation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-attestation.d.ts","sourceRoot":"","sources":["../../src/witness/env-attestation.ts"],"names":[],"mappings":"AAuBA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAK5B,kEAAkE;AAClE,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAatD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQjF;AAED,oFAAoF;AACpF,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC;AAErC,8EAA8E;AAC9E,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,SAAyB,GAClC,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAED,wEAAwE;AACxE,MAAM,WAAW,QAAQ;IACvB,uEAAuE;IACvE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,+CAA+C;IAC/C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,QAAQ,CAAC,CAsBnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,QAAQ,EACf,kBAAkB,EAAE,MAAM,EAC1B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAC/B,MAAM,GAAG,IAAI,CAef"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Minimal v1 environment attestation (GF-10, GF-13; ADR 0002, plan
3
+ * invariant 5, docs/research/environment_attestation.md L0/L1 spirit).
4
+ *
5
+ * Two positive checks, both fail-closed:
6
+ *
7
+ * 1. Loopback-only targets (GF-10): the attestation subject (the SUT the
8
+ * UI drives) and every adapter read base MUST be a loopback address.
9
+ * A non-loopback target blocks the run BEFORE any adapter read is
10
+ * constructed — the witness never builds a request against an
11
+ * unattested base.
12
+ * 2. Env-fingerprint marker (GF-13, minimal v1 attestation): every
13
+ * adapter base must answer GET `/` with an
14
+ * `x-gateforge-env-fingerprint` header equal to the adapter's
15
+ * declared `environmentFingerprint`; when the run also pins
16
+ * `targetFingerprint`, the adapter must read the SAME environment
17
+ * the UI drives (adapter fingerprint === run fingerprint). Absent or
18
+ * mismatched markers reject the record — never `satisfied`.
19
+ *
20
+ * L2 signed statements are deferred per ADR 0002 ("L2 signing deferred").
21
+ */
22
+ import { lookup } from 'node:dns/promises';
23
+ import { ATTESTATION_SCOPE_HEADER, ENV_FINGERPRINT_HEADER, LOOPBACK_HOSTS } from '../constants.js';
24
+ import { clearPinnedLoopbackForTests, pinLoopbackIps, pinnedGet, } from './loopback-pins.js';
25
+ /** Default DNS lookup: the OS resolver, all records. */
26
+ const defaultLookup = (host) => lookup(host, { all: true, verbatim: true });
27
+ /** One failed attestation, carrying the actionable diagnostic. */
28
+ export class AttestationError extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = 'AttestationError';
32
+ }
33
+ }
34
+ /**
35
+ * Whether a base URL is loopback. Accepts the standard loopback
36
+ * hostnames/IPs (localhost, 127.0.0.0/8, ::1).
37
+ *
38
+ * Args:
39
+ * baseUrl: absolute http(s) URL.
40
+ *
41
+ * Returns:
42
+ * boolean: true when the host is a recognized loopback host.
43
+ */
44
+ export function isLoopbackUrl(baseUrl) {
45
+ let parsed;
46
+ try {
47
+ parsed = new URL(baseUrl);
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
53
+ return false;
54
+ const host = parsed.hostname;
55
+ if (LOOPBACK_HOSTS[host])
56
+ return true;
57
+ if (/^127(\.\d{1,3}){3}$/.test(host))
58
+ return true;
59
+ if (host === '0.0.0.0')
60
+ return true;
61
+ return false;
62
+ }
63
+ /**
64
+ * Asserts the attestation subject is loopback (GF-10). Called at witness
65
+ * startup for the target and before EVERY adapter read for the read
66
+ * base. Hostnames that are not literally loopback are resolved through
67
+ * the OS resolver (hosts file + DNS): a name whose addresses are ALL
68
+ * loopback (127.0.0.0/8, ::1) is loopback by construction — the
69
+ * disposable-stack pattern of tenant subdomains mapped to 127.0.0.1.
70
+ * Mixed records, unresolvable names, and lookup failures all reject
71
+ * (fail closed). Approved addresses are PINNED per hostname for the
72
+ * process lifetime (see `loopback-pins.ts`): later DNS changes never
73
+ * move established connections — the check validates
74
+ * OPERATOR-provided bases (never suite input — suites cannot set
75
+ * target/adapter bases), and every egress binds to the startup
76
+ * approval.
77
+ *
78
+ * Args:
79
+ * baseUrl: the base to verify.
80
+ * what: human label for diagnostics ("attestation subject", "adapter 'x'").
81
+ *
82
+ * Throws:
83
+ * AttestationError: when the base is not loopback — the run is BLOCKED
84
+ * before any request is constructed (plan invariant 5).
85
+ */
86
+ export async function assertLoopback(baseUrl, what) {
87
+ if (!(await isLoopbackUrlResolving(baseUrl))) {
88
+ throw new AttestationError(`${what} base '${baseUrl}' is not loopback; gateforge only attests disposable ` +
89
+ 'loopback environments (plan invariant 5, GF-10). A bare URL with no provider ' +
90
+ 'contract is not a mutation target.');
91
+ }
92
+ }
93
+ /** Clears the pin store (tests only — production paths pin once and bind). */
94
+ export function clearLoopbackCacheForTests() {
95
+ clearPinnedLoopbackForTests();
96
+ }
97
+ /**
98
+ * Whether a base URL is loopback, resolving non-literal hostnames. The
99
+ * sync string check (`isLoopbackUrl`) runs first; only names it rejects
100
+ * reach the resolver, which pins all-loopback answers (see
101
+ * `loopback-pins.ts` — first resolution wins, later DNS changes never
102
+ * replace the pins).
103
+ *
104
+ * Args:
105
+ * baseUrl: absolute http(s) URL.
106
+ * lookupFn: DNS lookup (default: OS resolver via `node:dns/promises`).
107
+ *
108
+ * Returns:
109
+ * Promise<boolean>: true when literally loopback or ALL resolved
110
+ * addresses are loopback. False on mixed records, unresolvable names,
111
+ * lookup failures, and non-http(s) URLs.
112
+ */
113
+ export async function isLoopbackUrlResolving(baseUrl, lookupFn = defaultLookup) {
114
+ if (isLoopbackUrl(baseUrl))
115
+ return true;
116
+ let host;
117
+ try {
118
+ const parsed = new URL(baseUrl);
119
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
120
+ return false;
121
+ host = parsed.hostname;
122
+ }
123
+ catch {
124
+ return false;
125
+ }
126
+ try {
127
+ await pinLoopbackIps(host, lookupFn);
128
+ return true;
129
+ }
130
+ catch {
131
+ return false;
132
+ }
133
+ }
134
+ /**
135
+ * Probes a target's env fingerprint: GET the base and read the marker
136
+ * header. Any transport failure probes as `{fingerprint: null, scope:
137
+ * null}` — absence is a mismatch, never a pass (fail closed).
138
+ *
139
+ * Args:
140
+ * baseUrl: target base to probe.
141
+ * timeoutMs: per-request timeout.
142
+ *
143
+ * Returns:
144
+ * EnvProbe: observed markers (null when absent/unreachable).
145
+ */
146
+ export async function probeEnvFingerprint(baseUrl, timeoutMs) {
147
+ try {
148
+ const controller = new AbortController();
149
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
150
+ try {
151
+ // Pinned egress: attested hostnames connect to their
152
+ // startup-approved loopback IPs (Host preserved); unpinned names
153
+ // behave exactly as before.
154
+ const response = await pinnedGet(baseUrl, {
155
+ timeoutMs,
156
+ signal: controller.signal,
157
+ });
158
+ return {
159
+ fingerprint: response.headers.get(ENV_FINGERPRINT_HEADER),
160
+ scope: response.headers.get(ATTESTATION_SCOPE_HEADER),
161
+ };
162
+ }
163
+ finally {
164
+ clearTimeout(timer);
165
+ }
166
+ }
167
+ catch {
168
+ return { fingerprint: null, scope: null };
169
+ }
170
+ }
171
+ /**
172
+ * The same-environment rule for one adapter read (GF-13). The adapter
173
+ * base must present a marker EQUAL to the adapter's declared
174
+ * environmentFingerprint, and (when the run pins one) that fingerprint
175
+ * must equal the run's target fingerprint — the adapter may not read a
176
+ * different environment than the UI under test.
177
+ *
178
+ * Args:
179
+ * probe: observed markers at the adapter base.
180
+ * adapterFingerprint: the adapter's declared environmentFingerprint.
181
+ * targetFingerprint: the run's pinned fingerprint, or null when unset.
182
+ *
183
+ * Returns:
184
+ * string | null: mismatch description, or null when attested.
185
+ */
186
+ export function envFingerprintMismatch(probe, adapterFingerprint, targetFingerprint) {
187
+ if (probe.fingerprint === null) {
188
+ return `adapter target presents no '${ENV_FINGERPRINT_HEADER}' marker; ` +
189
+ 'the environment is not attested (GF-13)';
190
+ }
191
+ if (probe.fingerprint !== adapterFingerprint) {
192
+ return `adapter target fingerprint '${probe.fingerprint}' does not match the adapter's ` +
193
+ `declared environmentFingerprint '${adapterFingerprint}' (GF-13)`;
194
+ }
195
+ if (targetFingerprint !== null && probe.fingerprint !== targetFingerprint) {
196
+ return `adapter target fingerprint '${probe.fingerprint}' differs from the run's attested ` +
197
+ `target fingerprint '${targetFingerprint}': the adapter would read a different ` +
198
+ 'environment than the UI under test (GF-13)';
199
+ }
200
+ return null;
201
+ }
202
+ //# sourceMappingURL=env-attestation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-attestation.js","sourceRoot":"","sources":["../../src/witness/env-attestation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,SAAS,GAEV,MAAM,oBAAoB,CAAC;AAE5B,wDAAwD;AACxD,MAAM,aAAa,GAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1F,kEAAkE;AAClE,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,I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AAC,WAAW,iCAAiC;YACtF,oCAAoC,kBAAkB,WAAW,CAAC;IACtE,CAAC;IACD,IAAI,iBAAiB,KAAK,IAAI,IAAI,KAAK,CAAC,WAAW,KAAK,iBAAiB,EAAE,CAAC;QAC1E,OAAO,+BAA+B,KAAK,CAAC,WAAW,oCAAoC;YACzF,uBAAuB,iBAAiB,wCAAwC;YAChF,4CAA4C,CAAC;IACjD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,79 @@
1
+ /** DNS lookup signature (injectable for tests; default: OS resolver). */
2
+ export type PinDnsLookup = (host: string) => Promise<ReadonlyArray<{
3
+ address: string;
4
+ family: number;
5
+ }>>;
6
+ /** Whether one address is loopback (127.0.0.0/8 or ::1). */
7
+ export declare function isLoopbackAddress(address: string): boolean;
8
+ /** Clears all pins (tests only — production paths pin once and bind). */
9
+ export declare function clearPinnedLoopbackForTests(): void;
10
+ /**
11
+ * Resolves a hostname and pins ALL-loopback addresses, or rejects.
12
+ * The first successful pinning wins for the process lifetime: later
13
+ * resolutions (including hostile mid-run DNS changes) never replace
14
+ * it — connections bind to the startup-approved set.
15
+ *
16
+ * Args:
17
+ * hostname: the operator-provided hostname to attest.
18
+ * lookupFn: DNS lookup (default: OS resolver, all records).
19
+ *
20
+ * Returns:
21
+ * The pinned loopback IP list (IPv4 first, then IPv6, stable order).
22
+ *
23
+ * Throws:
24
+ * Error: on empty/mixed/public/unresolvable answers.
25
+ */
26
+ export declare function pinLoopbackIps(hostname: string, lookupFn?: PinDnsLookup): Promise<string[]>;
27
+ /**
28
+ * Snapshot copy of current pins (hostname → approved IPs).
29
+ *
30
+ * Returns:
31
+ * A detached copy for launch-arg construction.
32
+ */
33
+ export declare function pinnedLoopbackIps(): Map<string, string[]>;
34
+ /**
35
+ * Builds the Chromium `--host-resolver-rules` value binding every
36
+ * pinned hostname to its approved IPs (`MAP host ip`, comma-separated,
37
+ * deterministic order). IP literals are emitted bare (brackets are URL
38
+ * syntax and would break rule parsing).
39
+ *
40
+ * Args:
41
+ * pins: hostname → approved IPs (default: live snapshot).
42
+ *
43
+ * Returns:
44
+ * The rules string, or null when nothing is pinned (no flag then).
45
+ */
46
+ export declare function hostResolverRules(pins?: ReadonlyMap<string, readonly string[]>): string | null;
47
+ /** Pinned GET result (fetch-compatible subset used by adapter/probe reads). */
48
+ export interface PinnedGetResult {
49
+ status: number;
50
+ headers: Headers;
51
+ json(): Promise<unknown>;
52
+ text(): Promise<string>;
53
+ }
54
+ /**
55
+ * GET through the startup pins: when the URL's hostname is pinned, the
56
+ * TCP connection goes to the pinned IP while the original Host header
57
+ * (host + non-default port) and path are preserved — tenant routing
58
+ * intact, destination bound. Unpinned hostnames use plain global fetch
59
+ * (previous behavior, unchanged).
60
+ *
61
+ * Args:
62
+ * url: absolute http(s) URL.
63
+ * options: timeout, headers, abort signal, redirect budget.
64
+ *
65
+ * Returns:
66
+ * Status + headers + body readers.
67
+ *
68
+ * Throws:
69
+ * Error: on transport failure, redirect overflow, or (https) the
70
+ * pinned IP failing certificate verification — fail closed, never
71
+ * plaintext fallback.
72
+ */
73
+ export declare function pinnedGet(url: string, options: {
74
+ timeoutMs: number;
75
+ headers?: Record<string, string>;
76
+ signal?: AbortSignal;
77
+ maxRedirects?: number;
78
+ }): Promise<PinnedGetResult>;
79
+ //# sourceMappingURL=loopback-pins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopback-pins.d.ts","sourceRoot":"","sources":["../../src/witness/loopback-pins.ts"],"names":[],"mappings":"AA4BA,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,CACzB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAC;AAEjE,4DAA4D;AAC5D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAKD,yEAAyE;AACzE,w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