@clear-capabilities/agentic-security-scanner 0.172.0 → 0.173.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 (202) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bin/agentic-security.js +37 -0
  3. package/dist/119.index.js +197 -0
  4. package/dist/128.index.js +129 -0
  5. package/dist/1293.index.js +5689 -0
  6. package/dist/1336.index.js +101 -101
  7. package/dist/1351.index.js +133 -0
  8. package/dist/1387.index.js +271 -0
  9. package/dist/1437.index.js +23 -0
  10. package/dist/1445.index.js +110 -0
  11. package/dist/1505.index.js +151 -0
  12. package/dist/1557.index.js +293 -0
  13. package/dist/1621.index.js +311 -0
  14. package/dist/1751.index.js +160 -0
  15. package/dist/1765.index.js +727 -0
  16. package/dist/1861.index.js +690 -0
  17. package/dist/1898.index.js +116 -0
  18. package/dist/1906.index.js +433 -0
  19. package/dist/1920.index.js +1 -291
  20. package/dist/208.index.js +1631 -0
  21. package/dist/2199.index.js +0 -239
  22. package/dist/2223.index.js +159 -0
  23. package/dist/2530.index.js +152 -0
  24. package/dist/2565.index.js +116 -0
  25. package/dist/2574.index.js +127 -0
  26. package/dist/2620.index.js +345 -0
  27. package/dist/2773.index.js +98 -0
  28. package/dist/2775.index.js +32 -0
  29. package/dist/2966.index.js +171 -0
  30. package/dist/2972.index.js +87 -0
  31. package/dist/2991.index.js +131 -0
  32. package/dist/3063.index.js +833 -0
  33. package/dist/3075.index.js +227 -0
  34. package/dist/3121.index.js +297 -0
  35. package/dist/3314.index.js +263 -0
  36. package/dist/3480.index.js +1822 -0
  37. package/dist/3481.index.js +24 -0
  38. package/dist/3506.index.js +268 -0
  39. package/dist/3533.index.js +591 -0
  40. package/dist/3653.index.js +450 -0
  41. package/dist/3822.index.js +131 -0
  42. package/dist/3868.index.js +292 -0
  43. package/dist/3917.index.js +152 -0
  44. package/dist/3918.index.js +192 -0
  45. package/dist/4090.index.js +288 -0
  46. package/dist/4121.index.js +1190 -0
  47. package/dist/4142.index.js +0 -239
  48. package/dist/4336.index.js +436 -0
  49. package/dist/4387.index.js +532 -0
  50. package/dist/4413.index.js +302 -0
  51. package/dist/4476.index.js +4510 -0
  52. package/dist/4491.index.js +133 -0
  53. package/dist/4538.index.js +185 -0
  54. package/dist/4684.index.js +319 -0
  55. package/dist/4740.index.js +165 -0
  56. package/dist/4780.index.js +209 -0
  57. package/dist/4802.index.js +225 -0
  58. package/dist/4812.index.js +379 -0
  59. package/dist/4835.index.js +126 -0
  60. package/dist/494.index.js +226 -0
  61. package/dist/4991.index.js +549 -0
  62. package/dist/5199.index.js +305 -0
  63. package/dist/5216.index.js +109 -0
  64. package/dist/5439.index.js +301 -0
  65. package/dist/5443.index.js +97 -0
  66. package/dist/5496.index.js +377 -0
  67. package/dist/550.index.js +2 -1
  68. package/dist/5801.index.js +588 -0
  69. package/dist/5858.index.js +223 -0
  70. package/dist/5933.index.js +143 -0
  71. package/dist/601.index.js +23 -0
  72. package/dist/6173.index.js +273 -0
  73. package/dist/6291.index.js +1871 -0
  74. package/dist/6312.index.js +666 -0
  75. package/dist/634.index.js +16182 -0
  76. package/dist/644.index.js +87 -0
  77. package/dist/6508.index.js +283 -0
  78. package/dist/6560.index.js +645 -0
  79. package/dist/6576.index.js +422 -0
  80. package/dist/6579.index.js +271 -0
  81. package/dist/6745.index.js +305 -0
  82. package/dist/6818.index.js +21642 -0
  83. package/dist/6972.index.js +167 -0
  84. package/dist/6995.index.js +163 -0
  85. package/dist/7249.index.js +191 -0
  86. package/dist/7372.index.js +1197 -0
  87. package/dist/7405.index.js +23 -6
  88. package/dist/7546.index.js +541 -0
  89. package/dist/76.index.js +448 -0
  90. package/dist/7879.index.js +163 -0
  91. package/dist/8025.index.js +130 -0
  92. package/dist/8054.index.js +248 -0
  93. package/dist/8097.index.js +201 -0
  94. package/dist/8126.index.js +191 -0
  95. package/dist/8178.index.js +78 -0
  96. package/dist/818.index.js +212 -0
  97. package/dist/8382.index.js +93 -0
  98. package/dist/8408.index.js +261 -0
  99. package/dist/8540.index.js +174 -0
  100. package/dist/8635.index.js +802 -0
  101. package/dist/8688.index.js +410 -0
  102. package/dist/8699.index.js +779 -0
  103. package/dist/8891.index.js +457 -0
  104. package/dist/8916.index.js +885 -0
  105. package/dist/9146.index.js +170 -0
  106. package/dist/9168.index.js +841 -0
  107. package/dist/9292.index.js +369 -0
  108. package/dist/9382.index.js +338 -48
  109. package/dist/9422.index.js +866 -0
  110. package/dist/9440.index.js +453 -0
  111. package/dist/9479.index.js +152 -0
  112. package/dist/9481.index.js +220 -0
  113. package/dist/9539.index.js +100 -0
  114. package/dist/9547.index.js +103 -0
  115. package/dist/9560.index.js +41 -61
  116. package/dist/9692.index.js +90 -0
  117. package/dist/9800.index.js +213 -1
  118. package/dist/9899.index.js +138 -0
  119. package/dist/9981.index.js +206 -0
  120. package/dist/999.index.js +117 -0
  121. package/dist/agentic-security.mjs +28 -28
  122. package/dist/agentic-security.mjs.sha256 +1 -1
  123. package/package.json +31 -6
  124. package/src/context-intelligence/CLAUDE.md +4 -0
  125. package/src/context-intelligence/adapters/haskell-hie.js +28 -1
  126. package/src/context-intelligence/candidates.js +2 -1
  127. package/src/context-intelligence/canonical.js +25 -0
  128. package/src/context-intelligence/capabilities.js +2 -1
  129. package/src/context-intelligence/cli.js +16 -10
  130. package/src/context-intelligence/config.js +4 -1
  131. package/src/context-intelligence/controls.js +108 -10
  132. package/src/context-intelligence/counterexample.js +200 -0
  133. package/src/context-intelligence/cross-route.js +111 -0
  134. package/src/context-intelligence/entrypoints.js +2 -2
  135. package/src/context-intelligence/evaluation/index.js +11 -4
  136. package/src/context-intelligence/evaluation/scripted-reader.js +12 -2
  137. package/src/context-intelligence/findings.js +166 -0
  138. package/src/context-intelligence/invariants.js +197 -0
  139. package/src/context-intelligence/queue.js +6 -1
  140. package/src/context-intelligence/reachability.js +10 -4
  141. package/src/context-intelligence/review.js +129 -16
  142. package/src/dataflow/access-paths.js +11 -0
  143. package/src/dataflow/analysis-limits.js +66 -0
  144. package/src/dataflow/engine.js +272 -20
  145. package/src/dataflow/service-edges.js +174 -0
  146. package/src/dataflow/summaries.js +7 -1
  147. package/src/discovery/judge.js +2 -1
  148. package/src/engine.js +82 -14
  149. package/src/fix/apply-fix-service.js +55 -8
  150. package/src/fix/batch-journal.js +84 -0
  151. package/src/fix/exploit-replay.js +51 -0
  152. package/src/fix/footprint.js +65 -0
  153. package/src/fix/patch-policy.js +49 -0
  154. package/src/fix/secret-persistence.js +39 -0
  155. package/src/fix/test-commands.js +84 -0
  156. package/src/fix/verification-adapters.js +97 -0
  157. package/src/fix/verification-record.js +243 -0
  158. package/src/fix/verify-patch.js +89 -0
  159. package/src/ir/CLAUDE.md +5 -0
  160. package/src/ir/callgraph.js +23 -1
  161. package/src/ir/module-resolver.js +315 -0
  162. package/src/ir/parser-js.js +21 -2
  163. package/src/ir/semantic-graph.js +245 -0
  164. package/src/lineage/build-attested-correlation.js +63 -0
  165. package/src/lineage/deployment-identity.js +76 -0
  166. package/src/mcp/tools.js +13 -34
  167. package/src/pipeline/canonical-output.js +64 -0
  168. package/src/pipeline/detector-runner.js +7 -0
  169. package/src/pipeline/scan-health.js +14 -0
  170. package/src/pipeline/supervised-analyzers.js +125 -0
  171. package/src/pipeline/supervised-child.js +17 -0
  172. package/src/pipeline/telemetry.js +79 -0
  173. package/src/posture/accuracy-scorecard.js +98 -9
  174. package/src/posture/artifact-registry.js +5 -0
  175. package/src/posture/assurance/evidence-registry.js +215 -0
  176. package/src/posture/assurance/release-package-verify.js +135 -0
  177. package/src/posture/assurance/release-package.js +118 -0
  178. package/src/posture/assurance/release-verdict.js +94 -0
  179. package/src/posture/assurance/waiver.js +200 -0
  180. package/src/posture/compliance-truth.js +100 -0
  181. package/src/posture/evaluation/scan-child.js +3 -1
  182. package/src/posture/evaluation/why-missed.js +3 -1
  183. package/src/posture/exploitability-evidence.js +141 -0
  184. package/src/posture/fix-verify.js +4 -2
  185. package/src/posture/fleet/exposure-ranking.js +115 -0
  186. package/src/posture/fleet/service-chain-graph.js +150 -0
  187. package/src/posture/graph-reconciliation.js +154 -0
  188. package/src/posture/provenance/coverage.js +103 -0
  189. package/src/posture/provenance/git-evidence.js +84 -0
  190. package/src/posture/provenance/origin-resolver.js +7 -1
  191. package/src/posture/provenance/predicate-replay.js +14 -4
  192. package/src/posture/runtime-correlation.js +61 -15
  193. package/src/posture/runtime-explanation.js +116 -0
  194. package/src/posture/runtime-trace-ingest.js +194 -0
  195. package/src/posture/scan-checkpoint.js +38 -10
  196. package/src/posture/waf-ingest.js +7 -2
  197. package/src/report/index.js +4 -0
  198. package/src/report/oscal.js +38 -0
  199. package/src/report/perspectives.js +150 -0
  200. package/src/sast/_comment-strip.js +8 -1
  201. package/src/sast/ruby.js +26 -0
  202. package/src/util/string-memo.js +38 -0
@@ -0,0 +1,302 @@
1
+ export const id = 4413;
2
+ export const ids = [4413];
3
+ export const modules = {
4
+
5
+ /***/ 14413:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
+ /* harmony export */ buildPolicyBundle: () => (/* binding */ buildPolicyBundle),
10
+ /* harmony export */ ensurePolicyKeyPair: () => (/* binding */ ensurePolicyKeyPair),
11
+ /* harmony export */ loadPolicyBundles: () => (/* binding */ loadPolicyBundles),
12
+ /* harmony export */ loadPolicyPublicKey: () => (/* binding */ loadPolicyPublicKey),
13
+ /* harmony export */ rE: () => (/* binding */ computePolicyDrift),
14
+ /* harmony export */ resolveEffectivePolicy: () => (/* binding */ resolveEffectivePolicy),
15
+ /* harmony export */ signPolicyBundle: () => (/* binding */ signPolicyBundle)
16
+ /* harmony export */ });
17
+ /* unused harmony exports POLICY_BUNDLE_SCHEMA, SCOPES, canonicalPolicyBytes, verifyPolicyBundle */
18
+ /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
19
+ /* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48161);
20
+ /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(76760);
21
+ /* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(77598);
22
+ /* harmony import */ var _evidence_bundle_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(32876);
23
+ /* harmony import */ var _state_dir_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(69259);
24
+ // Signed, portable policy bundles (assurance-hardening PRD FR-1001).
25
+ //
26
+ // "Support signed portable policy bundles with organization, repository, and
27
+ // environment inheritance" | "Tampered or expired policy is rejected;
28
+ // effective policy is explainable."
29
+ //
30
+ // WHY REUSE evidence-bundle.js's Ed25519 SCHEME, NOT integrity.js's HMAC
31
+ // -------------------------------------------------------------------------
32
+ // A policy bundle is authored by one party (typically a central security
33
+ // team, "the organization") and distributed to many repositories that never
34
+ // had the signing key. integrity.js's per-install symmetric HMAC is
35
+ // tamper-evidence for the SAME install that wrote it — a different install
36
+ // verifying a bundle it didn't sign is exactly the case that scheme cannot
37
+ // serve. evidence-bundle.js already solved this for findings: Ed25519,
38
+ // verify with only the public key. This module reuses that primitive
39
+ // directly (canonicalisation shape, allowlist-signed-fields discipline,
40
+ // exclusive-create key generation) rather than inventing a third signing
41
+ // mechanism, per this session's own established "survey before building a
42
+ // parallel primitive" practice (see D-0023/D-0025 for the same discipline
43
+ // applied to identity and exception mechanisms respectively).
44
+ //
45
+ // EA-03 LESSON, APPLIED HERE FROM THE START
46
+ // -------------------------------------------------------------------------
47
+ // evidence-bundle.js's own history (see its EA-03 comment) is the reason
48
+ // `canonicalPolicyBytes` signs an explicit ALLOWLIST and `verifyPolicyBundle`
49
+ // REJECTS any top-level key outside it: a bundle with a field stapled on
50
+ // after signing must fail verification, not silently pass with the addition
51
+ // unverified. Getting this right on the first pass — rather than discovering
52
+ // the gap the way evidence-bundle.js did — is the entire point of writing it
53
+ // down here.
54
+ //
55
+ // SCOPE — WHAT THIS MODULE DOES NOT DO
56
+ // -------------------------------------------------------------------------
57
+ // It does not invent a policy SCHEMA — `policy` is an opaque object; whatever
58
+ // keys a bundle carries (egress rules, severity floors, approved providers,
59
+ // anything else this repo already treats as policy) are merged the same way.
60
+ // It does not implement deep/recursive merging — inheritance is shallow,
61
+ // top-level-key override (organization -> repository -> environment, most
62
+ // specific wins per key), matching how every other flat policy config file
63
+ // in this repo (egress-policy.yml, compliance-severity-policy.json, …) is
64
+ // already shaped. A future consumer needing nested-key inheritance is new,
65
+ // separate scope, not assumed here.
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ const POLICY_BUNDLE_SCHEMA = 'agentic-security/policy-bundle@1';
75
+
76
+ const SCOPES = ['organization', 'repository', 'environment'];
77
+ // Inheritance order — later entries override earlier ones, per top-level key.
78
+ const INHERITANCE_ORDER = ['organization', 'repository', 'environment'];
79
+
80
+ function keyDir() {
81
+ const xdg = process.env.XDG_CONFIG_HOME || node_path__WEBPACK_IMPORTED_MODULE_2__.join(node_os__WEBPACK_IMPORTED_MODULE_1__.homedir(), '.config');
82
+ return node_path__WEBPACK_IMPORTED_MODULE_2__.join(xdg, 'agentic-security', 'policy-bundles');
83
+ }
84
+
85
+ /** A SEPARATE Ed25519 keypair from evidence-bundle.js's finding-attestation
86
+ * key — signing "this policy is authentic" and "this finding really came
87
+ * from a scan run by me" are different trust domains and must not share a
88
+ * key. Reuses evidence-bundle.js's hardened, race-safe generation logic
89
+ * directly (its exclusive-create collision handling is the kind of code
90
+ * worth NOT re-implementing) rather than duplicating it — the separation
91
+ * that matters is the DIRECTORY (`policy-bundles/`, isolated from
92
+ * evidence-bundle.js's own key dir), not the leaf filenames, which are
93
+ * `attest-key.pem`/`attest-key.pub.pem` regardless of caller (a
94
+ * evidence-bundle.js internal, not overridable here) — a readability wart,
95
+ * not a security one, since the directory is what prevents key reuse. */
96
+ function ensurePolicyKeyPair(dir = keyDir()) {
97
+ return (0,_evidence_bundle_js__WEBPACK_IMPORTED_MODULE_4__.ensureKeyPair)(dir);
98
+ }
99
+
100
+ /**
101
+ * Deterministic JSON, keys sorted at every level — identical algorithm to
102
+ * evidence-bundle.js's canonicalJson (duplicated rather than imported: it is
103
+ * a pure, three-line function, and importing it would couple this module's
104
+ * signature format to evidence-bundle.js's internals for no real benefit).
105
+ */
106
+ function canonicalJson(value) {
107
+ if (value === null || typeof value !== 'object') return JSON.stringify(value ?? null);
108
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
109
+ const keys = Object.keys(value).sort();
110
+ return `{${keys.map(k => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(',')}}`;
111
+ }
112
+
113
+ // The complete set of fields a legitimately-built bundle carries, BEFORE
114
+ // signing. This is the signed allowlist AND (in verifyPolicyBundle) the
115
+ // complete set of keys a signed bundle is permitted to have alongside
116
+ // `signature` — see the EA-03 note above for why both matter.
117
+ const BUNDLE_FIELDS = ['schema', 'scope', 'policy', 'issuedAt', 'expiresAt'];
118
+ const BUNDLE_TOP_LEVEL_KEYS = new Set([...BUNDLE_FIELDS, 'signature']);
119
+
120
+ function canonicalPolicyBytes(bundle) {
121
+ const signed = {};
122
+ for (const k of BUNDLE_FIELDS) signed[k] = bundle[k] ?? null;
123
+ return Buffer.from(canonicalJson(signed), 'utf8');
124
+ }
125
+
126
+ /**
127
+ * Build an unsigned bundle. `policy` is caller-supplied and opaque — this
128
+ * module does not validate its shape, only its provenance and freshness.
129
+ */
130
+ function buildPolicyBundle(scope, policy, { issuedAt, expiresAt } = {}) {
131
+ if (!SCOPES.includes(scope)) return null;
132
+ if (!policy || typeof policy !== 'object' || Array.isArray(policy)) return null;
133
+ return {
134
+ schema: POLICY_BUNDLE_SCHEMA,
135
+ scope,
136
+ policy,
137
+ issuedAt: issuedAt ?? new Date().toISOString(),
138
+ expiresAt: expiresAt ?? null,
139
+ };
140
+ }
141
+
142
+ /** Sign a bundle. Returns a new object; the input is not mutated. */
143
+ function signPolicyBundle(bundle, privateKeyPem) {
144
+ const sig = node_crypto__WEBPACK_IMPORTED_MODULE_3__.sign(null, canonicalPolicyBytes(bundle), privateKeyPem);
145
+ return {
146
+ ...bundle,
147
+ signature: { algorithm: 'ed25519', canonicalisation: POLICY_BUNDLE_SCHEMA, value: sig.toString('base64') },
148
+ };
149
+ }
150
+
151
+ /**
152
+ * Verify a bundle: signature authenticity AND freshness. Never throws — a
153
+ * malformed or tampered bundle from an untrusted source (a repo checking out
154
+ * whatever an org distributed) is an expected input, not exceptional.
155
+ *
156
+ * @returns {{ok: boolean, reason: string|null}}
157
+ */
158
+ function verifyPolicyBundle(bundle, publicKeyPem, { now = Date.now() } = {}) {
159
+ if (!bundle || typeof bundle !== 'object') return { ok: false, reason: 'bundle is not an object' };
160
+ if (bundle.schema !== POLICY_BUNDLE_SCHEMA) return { ok: false, reason: `unrecognised schema: ${bundle.schema}` };
161
+ if (!SCOPES.includes(bundle.scope)) return { ok: false, reason: `unrecognised scope: ${bundle.scope}` };
162
+ const unknownKeys = Object.keys(bundle).filter(k => !BUNDLE_TOP_LEVEL_KEYS.has(k));
163
+ if (unknownKeys.length) {
164
+ return { ok: false, reason: `unrecognised top-level key(s) not covered by the signature: ${unknownKeys.join(', ')}` };
165
+ }
166
+ const sig = bundle.signature;
167
+ if (!sig?.value) return { ok: false, reason: 'bundle is unsigned' };
168
+ if (sig.algorithm !== 'ed25519') return { ok: false, reason: `unsupported algorithm: ${sig.algorithm}` };
169
+ if (!publicKeyPem) return { ok: false, reason: 'no public key supplied' };
170
+ let sigOk = false;
171
+ try {
172
+ sigOk = node_crypto__WEBPACK_IMPORTED_MODULE_3__.verify(null, canonicalPolicyBytes(bundle), publicKeyPem, Buffer.from(sig.value, 'base64'));
173
+ } catch (e) {
174
+ return { ok: false, reason: `verification error: ${e.message}` };
175
+ }
176
+ if (!sigOk) return { ok: false, reason: 'signature does not match the bundle contents — it was modified after signing' };
177
+ if (bundle.expiresAt) {
178
+ const exp = Date.parse(bundle.expiresAt);
179
+ if (!Number.isFinite(exp)) return { ok: false, reason: `expiresAt is not a valid date: ${bundle.expiresAt}` };
180
+ if (exp < now) return { ok: false, reason: `policy expired on ${bundle.expiresAt}` };
181
+ }
182
+ return { ok: true, reason: null };
183
+ }
184
+
185
+ /**
186
+ * Merge verified bundles into one effective policy, in inheritance order
187
+ * (organization -> repository -> environment; most specific wins per key).
188
+ * A tampered or expired bundle is EXCLUDED from the merge (rejected, not
189
+ * silently dropped — its scope and reason are reported so a rejection is
190
+ * visible, not just absent). `provenance[key]` names which scope's bundle
191
+ * last set that key — the "effective policy is explainable" half of the
192
+ * acceptance criterion.
193
+ *
194
+ * @param {Array<{scope: string, bundle: object}>} entries
195
+ * @param {string} publicKeyPem
196
+ * @returns {{effective: object, provenance: Record<string,string>,
197
+ * accepted: string[], rejected: Array<{scope:string, reason:string}>}}
198
+ */
199
+ function resolveEffectivePolicy(entries, publicKeyPem, { now = Date.now() } = {}) {
200
+ const byScope = new Map();
201
+ for (const e of entries || []) {
202
+ if (e && SCOPES.includes(e.scope)) byScope.set(e.scope, e.bundle);
203
+ }
204
+ const effective = {};
205
+ const provenance = {};
206
+ const accepted = [];
207
+ const rejected = [];
208
+ for (const scope of INHERITANCE_ORDER) {
209
+ const bundle = byScope.get(scope);
210
+ if (!bundle) continue;
211
+ const v = verifyPolicyBundle(bundle, publicKeyPem, { now });
212
+ if (!v.ok) { rejected.push({ scope, reason: v.reason }); continue; }
213
+ accepted.push(scope);
214
+ for (const [k, val] of Object.entries(bundle.policy)) {
215
+ effective[k] = val;
216
+ provenance[k] = scope;
217
+ }
218
+ }
219
+ return { effective, provenance, accepted, rejected };
220
+ }
221
+
222
+ /**
223
+ * Load whichever policy bundle files exist under
224
+ * `.agentic-security/policy-bundles/{organization,repository,environment}.json`.
225
+ * Degrades gracefully — a missing directory or missing/malformed individual
226
+ * file is simply absent from the result, never thrown. Read-first-in-try/
227
+ * catch throughout (no existsSync-then-readFileSync — D-0012/D-0022).
228
+ */
229
+ function loadPolicyBundles(scanRoot) {
230
+ if (!scanRoot) return [];
231
+ const entries = [];
232
+ for (const scope of SCOPES) {
233
+ let fp;
234
+ try { fp = (0,_state_dir_js__WEBPACK_IMPORTED_MODULE_5__.statePath)(scanRoot, 'policy-bundles', `${scope}.json`); } catch { continue; }
235
+ let raw;
236
+ try { raw = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(fp, 'utf8'); } catch { continue; }
237
+ try {
238
+ const bundle = JSON.parse(raw);
239
+ if (bundle && typeof bundle === 'object') entries.push({ scope, bundle });
240
+ } catch { /* malformed — skip, do not throw */ }
241
+ }
242
+ return entries;
243
+ }
244
+
245
+ /**
246
+ * Read the operator-supplied public key an org distributes alongside its
247
+ * bundles, from `.agentic-security/policy-bundle-public-key.pem`. Returns
248
+ * null (not a throw) if absent or unreadable — resolution then rejects
249
+ * every bundle for lack of a key, same as any other "no public key
250
+ * supplied" case in verifyPolicyBundle.
251
+ */
252
+ function loadPolicyPublicKey(scanRoot) {
253
+ if (!scanRoot) return null;
254
+ let fp;
255
+ try { fp = (0,_state_dir_js__WEBPACK_IMPORTED_MODULE_5__.statePath)(scanRoot, 'policy-bundle-public-key.pem'); } catch { return null; }
256
+ try { return node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(fp, 'utf8'); } catch { return null; }
257
+ }
258
+
259
+ /**
260
+ * FR-1006 ("policy drift"): does this repository's LOCALLY resolved effective
261
+ * policy diverge from what the organization-scope bundle alone specifies —
262
+ * and is anything the repo is relying on actually being rejected (tampered
263
+ * or expired) rather than enforced? Both are GOVERNANCE gaps, distinct from
264
+ * risk findings, which is the exact distinction FR-1006's acceptance
265
+ * criterion asks fleet output to make.
266
+ *
267
+ * No bundles configured at all is a no-op (`null`), matching this session's
268
+ * established convention: drift can only be reported relative to a
269
+ * baseline, and a repo with no organization bundle has no baseline to drift
270
+ * from.
271
+ *
272
+ * @returns {{accepted: string[], rejected: Array<{scope,reason}>,
273
+ * overrides: Array<{key, organizationValue, effectiveValue, overriddenBy}>}
274
+ * | null}
275
+ */
276
+ function computePolicyDrift(scanRoot) {
277
+ const entries = loadPolicyBundles(scanRoot);
278
+ if (!entries.length) return null;
279
+ const publicKeyPem = loadPolicyPublicKey(scanRoot);
280
+ const { effective, provenance, accepted, rejected } = resolveEffectivePolicy(entries, publicKeyPem);
281
+
282
+ const overrides = [];
283
+ const orgEntry = entries.find(e => e.scope === 'organization');
284
+ if (orgEntry && accepted.includes('organization')) {
285
+ for (const [key, organizationValue] of Object.entries(orgEntry.bundle.policy || {})) {
286
+ const overriddenBy = provenance[key];
287
+ if (overriddenBy && overriddenBy !== 'organization' && !_deepEqual(effective[key], organizationValue)) {
288
+ overrides.push({ key, organizationValue, effectiveValue: effective[key], overriddenBy });
289
+ }
290
+ }
291
+ }
292
+ return { accepted, rejected, overrides };
293
+ }
294
+
295
+ function _deepEqual(a, b) {
296
+ return JSON.stringify(a) === JSON.stringify(b);
297
+ }
298
+
299
+
300
+ /***/ })
301
+
302
+ };