intentumdiff-python 0.0.1__py3-none-win_amd64.whl → 0.0.2b2__py3-none-win_amd64.whl
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.
- intentumdiff/__init__.py +2 -0
- intentumdiff/__main__.py +12 -0
- intentumdiff/_differ_presentation.py +35 -682
- intentumdiff/_differ_runtime.py +13 -47
- intentumdiff/analysis/compile_commands.py +26 -141
- intentumdiff/analysis/cross_file.py +2 -4
- intentumdiff/analysis/guardrail_reports.py +7 -5
- intentumdiff/analysis/guardrails.py +110 -122
- intentumdiff/analysis/invariances.py +4 -1003
- intentumdiff/analysis/schema_resolver.py +49 -273
- intentumdiff/analysis/text_review.py +4 -3
- intentumdiff/analysis/user_schemas.py +55 -237
- intentumdiff/api.py +21 -0
- intentumdiff/cache/sqlite_store.py +5 -23
- intentumdiff/cli/__init__.py +59 -0
- intentumdiff/cli/_commands.py +174 -67
- intentumdiff/cli/_parser.py +11 -1
- intentumdiff/cli/_shared.py +96 -112
- intentumdiff/content_type.py +13 -30
- intentumdiff/core/commit_differ.py +105 -220
- intentumdiff/core/diffignore.py +28 -34
- intentumdiff/core/index.py +16 -18
- intentumdiff/core/indexer.py +148 -168
- intentumdiff/core/models.py +53 -14
- intentumdiff/differ.py +278 -605
- intentumdiff/github_app.py +35 -19
- intentumdiff/intentumdiff_rust_core/intentumdiff_rust_core.dll +0 -0
- intentumdiff/live_server.py +180 -17
- intentumdiff/lsp/client.py +7 -1
- intentumdiff/lsp/enricher.py +19 -119
- intentumdiff/lsp/exceptions.py +6 -7
- intentumdiff/lsp_server/_codelens.py +24 -57
- intentumdiff/lsp_server/_diagnostics.py +23 -51
- intentumdiff/lsp_server/_handlers.py +66 -8
- intentumdiff/lsp_server/server.py +28 -7
- intentumdiff/plugins/adapter.py +5 -0
- intentumdiff/plugins/builtins.py +7 -14
- intentumdiff/plugins/exceptions.py +4 -0
- intentumdiff/plugins/hub.py +1 -2
- intentumdiff/plugins/loader.py +229 -215
- intentumdiff/plugins/registry.py +249 -197
- intentumdiff/rust_core.py +744 -784
- intentumdiff/serve/_app.py +3 -10
- intentumdiff/sources/base.py +24 -0
- intentumdiff/sources/file_source.py +15 -2
- intentumdiff/sources/git_source.py +120 -58
- intentumdiff/sources/live_buffer_source.py +45 -5
- intentumdiff/sources/patch_source.py +36 -109
- intentumdiff/vcs/_safe_path.py +7 -0
- intentumdiff/vcs/base.py +6 -0
- intentumdiff/vcs/git_backend.py +1 -1
- intentumdiff/vcs/git_cli.py +38 -18
- intentumdiff/vcs/hg_backend.py +1 -1
- intentumdiff/vcs/perforce_backend.py +7 -1
- intentumdiff/vcs/svn_backend.py +1 -1
- intentumdiff/wasm/abap_parser.wasm +0 -0
- intentumdiff/wasm/adf_parser.wasm +0 -0
- intentumdiff/wasm/asciidoc_parser.wasm +0 -0
- intentumdiff/wasm/asm_parser.wasm +0 -0
- intentumdiff/wasm/assemblyscript_parser.wasm +0 -0
- intentumdiff/wasm/astro_parser.wasm +0 -0
- intentumdiff/wasm/bash_parser.wasm +0 -0
- intentumdiff/wasm/clojure_parser.wasm +0 -0
- intentumdiff/wasm/cmake_parser.wasm +0 -0
- intentumdiff/wasm/cpp_parser.wasm +0 -0
- intentumdiff/wasm/csharp_parser.wasm +0 -0
- intentumdiff/wasm/css_parser.wasm +0 -0
- intentumdiff/wasm/dart_parser.wasm +0 -0
- intentumdiff/wasm/databricks_parser.wasm +0 -0
- intentumdiff/wasm/dax_parser.wasm +0 -0
- intentumdiff/wasm/delphi_parser.wasm +0 -0
- intentumdiff/wasm/dockerfile_parser.wasm +0 -0
- intentumdiff/wasm/elixir_parser.wasm +0 -0
- intentumdiff/wasm/freebasic_parser.wasm +0 -0
- intentumdiff/wasm/generic_parser.wasm +0 -0
- intentumdiff/wasm/gitignore_parser.wasm +0 -0
- intentumdiff/wasm/go_parser.wasm +0 -0
- intentumdiff/wasm/gomod_parser.wasm +0 -0
- intentumdiff/wasm/graphql_parser.wasm +0 -0
- intentumdiff/wasm/groovy_parser.wasm +0 -0
- intentumdiff/wasm/haskell_parser.wasm +0 -0
- intentumdiff/wasm/html_parser.wasm +0 -0
- intentumdiff/wasm/html_renderer.wasm +0 -0
- intentumdiff/wasm/ini_parser.wasm +0 -0
- intentumdiff/wasm/java_parser.wasm +0 -0
- intentumdiff/wasm/js_ts_parser.wasm +0 -0
- intentumdiff/wasm/json_parser.wasm +0 -0
- intentumdiff/wasm/kotlin_parser.wasm +0 -0
- intentumdiff/wasm/latex_parser.wasm +0 -0
- intentumdiff/wasm/llm_renderer.wasm +0 -0
- intentumdiff/wasm/lua_parser.wasm +0 -0
- intentumdiff/wasm/make_parser.wasm +0 -0
- intentumdiff/wasm/markdown_parser.wasm +0 -0
- intentumdiff/wasm/mdx_parser.wasm +0 -0
- intentumdiff/wasm/ocaml_parser.wasm +0 -0
- intentumdiff/wasm/odin_parser.wasm +0 -0
- intentumdiff/wasm/parser_manifest.json +81 -2
- intentumdiff/wasm/patch_renderer.wasm +0 -0
- intentumdiff/wasm/perl_parser.wasm +0 -0
- intentumdiff/wasm/php_parser.wasm +0 -0
- intentumdiff/wasm/plsql_parser.wasm +0 -0
- intentumdiff/wasm/po_parser.wasm +0 -0
- intentumdiff/wasm/postscript_parser.wasm +0 -0
- intentumdiff/wasm/powershell_parser.wasm +0 -0
- intentumdiff/wasm/proto_parser.wasm +0 -0
- intentumdiff/wasm/puppet_parser.wasm +0 -0
- intentumdiff/wasm/python_parser.wasm +0 -0
- intentumdiff/wasm/qsharp_parser.wasm +0 -0
- intentumdiff/wasm/r_parser.wasm +0 -0
- intentumdiff/wasm/reasonml_parser.wasm +0 -0
- intentumdiff/wasm/ruby_parser.wasm +0 -0
- intentumdiff/wasm/rust_parser.wasm +0 -0
- intentumdiff/wasm/sas_parser.wasm +0 -0
- intentumdiff/wasm/scala_parser.wasm +0 -0
- intentumdiff/wasm/scss_parser.wasm +0 -0
- intentumdiff/wasm/sql_parser.wasm +0 -0
- intentumdiff/wasm/squirrel_parser.wasm +0 -0
- intentumdiff/wasm/svelte_parser.wasm +0 -0
- intentumdiff/wasm/swift_parser.wasm +0 -0
- intentumdiff/wasm/terminal_renderer.wasm +0 -0
- intentumdiff/wasm/terraform_parser.wasm +0 -0
- intentumdiff/wasm/toml_parser.wasm +0 -0
- intentumdiff/wasm/tsql_parser.wasm +0 -0
- intentumdiff/wasm/vbnet_parser.wasm +0 -0
- intentumdiff/wasm/vue_parser.wasm +0 -0
- intentumdiff/wasm/wasm_provenance.json +884 -0
- intentumdiff/wasm/wat_parser.wasm +0 -0
- intentumdiff/wasm/xml_parser.wasm +0 -0
- intentumdiff/wasm/yaml_parser.wasm +0 -0
- intentumdiff/wasm/zig_parser.wasm +0 -0
- intentumdiff_python-0.0.2b2.dist-info/METADATA +156 -0
- intentumdiff_python-0.0.2b2.dist-info/RECORD +171 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/WHEEL +1 -1
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/sboms/intentumdiff-rust-core.cyclonedx.json +905 -379
- intentumdiff/core/cst_serializer.py +0 -101
- intentumdiff_python-0.0.1.dist-info/METADATA +0 -112
- intentumdiff_python-0.0.1.dist-info/RECORD +0 -165
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/entry_points.txt +0 -0
- {intentumdiff_python-0.0.1.dist-info → intentumdiff_python-0.0.2b2.dist-info}/licenses/LICENSE +0 -0
intentumdiff/plugins/loader.py
CHANGED
|
@@ -22,6 +22,8 @@ import importlib.metadata as _importlib_metadata
|
|
|
22
22
|
import json
|
|
23
23
|
import logging
|
|
24
24
|
import os
|
|
25
|
+
import platform
|
|
26
|
+
import re
|
|
25
27
|
import ssl
|
|
26
28
|
import threading
|
|
27
29
|
import time as _time
|
|
@@ -35,11 +37,15 @@ from wasmtime.component import Component, Linker
|
|
|
35
37
|
from intentumdiff.plugins.exceptions import (
|
|
36
38
|
PluginFuelExhausted,
|
|
37
39
|
PluginLoadError,
|
|
40
|
+
PluginSecurityError,
|
|
38
41
|
PluginOutputError,
|
|
39
42
|
PluginSandboxViolation,
|
|
40
43
|
)
|
|
41
44
|
|
|
42
45
|
logger = logging.getLogger(__name__)
|
|
46
|
+
|
|
47
|
+
# Emitted once per process, not once per plugin load: there are 78 plugins.
|
|
48
|
+
_OVERRIDE_WARNED: bool = False
|
|
43
49
|
_MAX_TELEMETRY_RECORDS = 128
|
|
44
50
|
|
|
45
51
|
# ---------------------------------------------------------------------------
|
|
@@ -52,8 +58,16 @@ _MAX_TELEMETRY_RECORDS = 128
|
|
|
52
58
|
# fast offline check. For a live OSV scan run: ``intentumdiff security-check``.
|
|
53
59
|
_VULNERABLE_WASMTIME_VERSIONS: frozenset[str] = frozenset({
|
|
54
60
|
"44.0.0", # CVE-2026-44216 / GHSA-p8xm-42r7-89xg — host panic via memory64
|
|
61
|
+
# GHSA-mghf-wjfp-p5xm — aarch64 br_table sandbox escape (critical).
|
|
62
|
+
# GHSA-9pvw-hwfg-92h5 — host panic through component streams/futures.
|
|
63
|
+
# Pre-patch Python bindings listed below contain affected native Wasmtime.
|
|
64
|
+
"45.0.0",
|
|
65
|
+
"46.0.1",
|
|
66
|
+
"47.0.1",
|
|
67
|
+
"48.0.0",
|
|
68
|
+
"49.0.0",
|
|
55
69
|
})
|
|
56
|
-
_WASMTIME_ADVISORY = "
|
|
70
|
+
_WASMTIME_ADVISORY = "GHSA-p8xm-42r7-89xg / GHSA-mghf-wjfp-p5xm / GHSA-9pvw-hwfg-92h5"
|
|
57
71
|
_WASMTIME_ADVISORY_URL = (
|
|
58
72
|
"https://github.com/bytecodealliance/wasmtime/security/advisories/"
|
|
59
73
|
"GHSA-p8xm-42r7-89xg"
|
|
@@ -72,50 +86,112 @@ def _is_trusted_wasm_path(wasm_path: str | Path | None) -> bool:
|
|
|
72
86
|
return False
|
|
73
87
|
|
|
74
88
|
|
|
75
|
-
#:
|
|
89
|
+
#: First-party bundled Wasm is always verified before execution. There is no
|
|
90
|
+
#: release runtime waiver: absent, malformed or divergent provenance is unsafe.
|
|
76
91
|
_PROVENANCE_MANIFEST = _BUILTIN_WASM_DIR / "wasm_provenance.json"
|
|
77
|
-
#: Opt-in to make a bundled-wasm provenance mismatch a hard load failure (release/CI). Off by
|
|
78
|
-
#: default so a dev tree without the manifest — or with a stale one after a manual wasm copy —
|
|
79
|
-
#: is not broken; the mismatch is still logged.
|
|
80
|
-
_ENFORCE_PROVENANCE_ENV = "INTENTUMDIFF_ENFORCE_WASM_PROVENANCE"
|
|
81
92
|
|
|
82
93
|
|
|
83
|
-
def _verify_builtin_provenance(path: Path) -> None:
|
|
84
|
-
"""
|
|
94
|
+
def _verify_builtin_provenance(path: Path) -> bytes | None:
|
|
95
|
+
"""Check bundled Wasm against the shipping manifest and return those bytes.
|
|
85
96
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
``INTENTUMDIFF_ENFORCE_WASM_PROVENANCE=1``. A missing/unreadable manifest (a dev build without
|
|
90
|
-
the package-time provenance step) is skipped — verification is optional by design (#89).
|
|
97
|
+
Read and hash the same buffer that will be passed to Wasmtime; checking a
|
|
98
|
+
path and reopening it later permits replacement between the two operations.
|
|
99
|
+
Third-party plugin provenance is checked independently by the plugin hub.
|
|
91
100
|
"""
|
|
92
|
-
if not _is_trusted_wasm_path(path)
|
|
93
|
-
return
|
|
101
|
+
if not _is_trusted_wasm_path(path):
|
|
102
|
+
return None
|
|
94
103
|
try:
|
|
95
104
|
manifest = json.loads(_PROVENANCE_MANIFEST.read_text(encoding="utf-8"))
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
except (OSError, ValueError, UnicodeError) as exc:
|
|
106
|
+
raise PluginSecurityError(
|
|
107
|
+
str(path), f"bundled Wasm provenance manifest is missing or invalid: {exc}"
|
|
108
|
+
) from exc
|
|
109
|
+
if not isinstance(manifest, dict) or manifest.get("schema_version") != 1:
|
|
110
|
+
raise PluginSecurityError(str(path), "bundled Wasm provenance has invalid schema")
|
|
111
|
+
artifacts = manifest.get("artifacts")
|
|
99
112
|
if not isinstance(artifacts, dict):
|
|
100
|
-
|
|
101
|
-
name =
|
|
113
|
+
raise PluginSecurityError(str(path), "bundled Wasm provenance lacks artifacts map")
|
|
114
|
+
name = path.name
|
|
102
115
|
expected = artifacts.get(name)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
if not isinstance(expected, dict):
|
|
117
|
+
raise PluginSecurityError(
|
|
118
|
+
str(path), f"bundled Wasm {name!r} is not listed in the provenance manifest"
|
|
119
|
+
)
|
|
120
|
+
digest = expected.get("sha256")
|
|
121
|
+
size = expected.get("size_bytes")
|
|
122
|
+
if (not isinstance(digest, str) or len(digest) != 64
|
|
123
|
+
or any(c not in "0123456789abcdef" for c in digest)
|
|
124
|
+
or not isinstance(size, int) or isinstance(size, bool) or size < 0):
|
|
125
|
+
raise PluginSecurityError(str(path), f"bundled Wasm {name!r} has invalid provenance metadata")
|
|
126
|
+
try:
|
|
127
|
+
payload = path.read_bytes()
|
|
128
|
+
except OSError as exc:
|
|
129
|
+
raise PluginSecurityError(str(path), f"bundled Wasm cannot be read: {exc}") from exc
|
|
130
|
+
if len(payload) != size or hashlib.sha256(payload).hexdigest() != digest:
|
|
131
|
+
raise PluginSecurityError(str(path), f"bundled Wasm {name!r} does not match provenance SHA-256/size")
|
|
132
|
+
return payload
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _check_rust_component_load_policy(path: Path) -> bytes | None:
|
|
136
|
+
"""Ask Rust before compilation; return the exact approved bytes if guarded.
|
|
137
|
+
|
|
138
|
+
Python owns only host I/O and error translation; Rust decides whether the
|
|
139
|
+
digest is compatible. A protected component must compile from the *same*
|
|
140
|
+
bytes that were hashed, rather than reopening the file after validation.
|
|
141
|
+
An empty digest probes the restriction without reading unrelated plugins.
|
|
142
|
+
"""
|
|
143
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
144
|
+
|
|
145
|
+
name, system, machine = path.name, platform.system(), platform.machine()
|
|
146
|
+
|
|
147
|
+
def reason_for(digest: str) -> str | None:
|
|
148
|
+
status = _c_abi_call("parser_component_availability", name, system, machine, digest)
|
|
149
|
+
if not isinstance(status, dict) or "reason" not in status:
|
|
150
|
+
raise PluginLoadError(str(path), "malformed Rust component availability response")
|
|
151
|
+
reason = status["reason"]
|
|
152
|
+
if reason is not None and not isinstance(reason, str):
|
|
153
|
+
raise PluginLoadError(str(path), "invalid Rust component availability reason type")
|
|
154
|
+
return reason
|
|
155
|
+
|
|
156
|
+
if reason_for("") is None:
|
|
111
157
|
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
158
|
+
try:
|
|
159
|
+
approved_bytes = path.read_bytes()
|
|
160
|
+
except OSError as exc:
|
|
161
|
+
raise PluginLoadError(str(path), f"cannot hash staged Wasm component: {exc}") from exc
|
|
162
|
+
reason = reason_for(hashlib.sha256(approved_bytes).hexdigest())
|
|
163
|
+
if reason is not None:
|
|
164
|
+
raise PluginLoadError(str(path), reason)
|
|
165
|
+
return approved_bytes
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _is_known_vulnerable_wasmtime(version: str) -> bool:
|
|
170
|
+
"""Reject vulnerable Wasmtime release *ranges*, not just sampled versions.
|
|
171
|
+
|
|
172
|
+
GHSA-mghf-wjfp-p5xm affects every release below 36.0.19,
|
|
173
|
+
37.0.0 through 48.0.6, and 49.0.0 through 49.0.3.
|
|
174
|
+
GHSA-9pvw-hwfg-92h5 also affects 46.0.0 through 48.0.6 and
|
|
175
|
+
49.0.0 through 49.0.3. An unparseable/prerelease version cannot
|
|
176
|
+
establish the patched runtime identity and must fail closed.
|
|
177
|
+
"""
|
|
178
|
+
if version in _VULNERABLE_WASMTIME_VERSIONS:
|
|
179
|
+
return True
|
|
180
|
+
match = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)", version)
|
|
181
|
+
if match is None:
|
|
182
|
+
return True
|
|
183
|
+
major, _minor, patch = (int(part) for part in match.groups())
|
|
184
|
+
if major < 36:
|
|
185
|
+
return True
|
|
186
|
+
if major == 36:
|
|
187
|
+
return patch < 19
|
|
188
|
+
if 37 <= major < 48:
|
|
189
|
+
return True
|
|
190
|
+
if major == 48:
|
|
191
|
+
return patch < 7
|
|
192
|
+
if major == 49:
|
|
193
|
+
return patch < 4
|
|
194
|
+
return False
|
|
119
195
|
|
|
120
196
|
|
|
121
197
|
def _check_wasmtime_version(
|
|
@@ -129,19 +205,22 @@ def _check_wasmtime_version(
|
|
|
129
205
|
Wasm module to panic the host process by allocating an extremely large
|
|
130
206
|
WebAssembly table under the default on-demand allocator with memory64.
|
|
131
207
|
|
|
132
|
-
The
|
|
133
|
-
|
|
134
|
-
for stale or
|
|
208
|
+
The release-candidate Python dependency pins wasmtime==50.0.1, the
|
|
209
|
+
available Python binding after the 2026 ARM64 Wasmtime advisories.
|
|
210
|
+
This offline runtime gate remains as defense-in-depth for stale or
|
|
211
|
+
manually pinned environments. Rust Core independently pins 48.0.7.
|
|
135
212
|
|
|
136
|
-
See: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-
|
|
213
|
+
See: https://github.com/bytecodealliance/wasmtime/security/advisories/GHSA-mghf-wjfp-p5xm
|
|
137
214
|
"""
|
|
138
215
|
try:
|
|
139
216
|
version = _importlib_metadata.version("wasmtime")
|
|
140
|
-
except _importlib_metadata.PackageNotFoundError:
|
|
141
|
-
|
|
142
|
-
|
|
217
|
+
except _importlib_metadata.PackageNotFoundError as exc:
|
|
218
|
+
raise PluginSecurityError(
|
|
219
|
+
"<wasmtime-version-check>",
|
|
220
|
+
"wasmtime distribution metadata is absent; cannot verify a patched native runtime",
|
|
221
|
+
) from exc
|
|
143
222
|
|
|
144
|
-
if
|
|
223
|
+
if not _is_known_vulnerable_wasmtime(version):
|
|
145
224
|
return
|
|
146
225
|
|
|
147
226
|
override = os.environ.get("INTENTUMDIFF_ALLOW_VULNERABLE_WASMTIME", "").strip()
|
|
@@ -156,11 +235,12 @@ def _check_wasmtime_version(
|
|
|
156
235
|
)
|
|
157
236
|
return
|
|
158
237
|
|
|
159
|
-
raise
|
|
238
|
+
raise PluginSecurityError(
|
|
160
239
|
"<wasmtime-version-check>",
|
|
161
|
-
f"wasmtime=={version} is in the known-vulnerable blocklist "
|
|
162
|
-
f"
|
|
163
|
-
f"
|
|
240
|
+
f"wasmtime=={version} is in the known-vulnerable blocklist or its "
|
|
241
|
+
f"version cannot be verified as patched "
|
|
242
|
+
f"({_WASMTIME_ADVISORY} — unsafe host behaviour including aarch64 "
|
|
243
|
+
f"sandbox escape or process panic). Upgrade wasmtime or set INTENTUMDIFF_ALLOW_VULNERABLE_WASMTIME=1 "
|
|
164
244
|
f"to override (not recommended). Run 'intentumdiff security-check' for a live "
|
|
165
245
|
f"OSV scan. See: {_WASMTIME_ADVISORY_URL}",
|
|
166
246
|
)
|
|
@@ -404,19 +484,30 @@ def _check_osv_cache_or_block(
|
|
|
404
484
|
# Stamp is fresh but no cache file: the last fetch failed.
|
|
405
485
|
override = os.environ.get("INTENTUMDIFF_ALLOW_VULNERABLE_WASMTIME", "").strip()
|
|
406
486
|
if override in ("1", "true", "yes"):
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
487
|
+
# Worth saying — a safety check has been deliberately disabled — but worth
|
|
488
|
+
# saying ONCE. Emitting it per plugin load repeated it up to 78 times a run.
|
|
489
|
+
global _OVERRIDE_WARNED
|
|
490
|
+
if not _OVERRIDE_WARNED:
|
|
491
|
+
_OVERRIDE_WARNED = True
|
|
492
|
+
logger.warning(
|
|
493
|
+
"INTENTUMDIFF_ALLOW_VULNERABLE_WASMTIME: loading plugins with "
|
|
494
|
+
"unverified OSV status — last advisory fetch failed."
|
|
495
|
+
)
|
|
411
496
|
return
|
|
412
497
|
if trusted or _is_trusted_wasm_path(wasm_path):
|
|
413
|
-
|
|
498
|
+
# DEBUG, not WARNING. This fires on every ordinary run whenever the machine
|
|
499
|
+
# is offline or the advisory cache has expired, and there is nothing for the
|
|
500
|
+
# user to do about it: first-party plugins ship inside the wheel and
|
|
501
|
+
# third-party ones stay blocked either way. Emitting it at warning level put
|
|
502
|
+
# alarming text — naming a "allow vulnerable" override — on stderr beside
|
|
503
|
+
# correct results, which is precisely how 0.0.1 came to look broken.
|
|
504
|
+
logger.debug(
|
|
414
505
|
"Loading first-party trusted Wasm plugin with unverified OSV "
|
|
415
506
|
"status because the last advisory fetch failed. Third-party "
|
|
416
507
|
"plugins remain blocked without INTENTUMDIFF_ALLOW_VULNERABLE_WASMTIME=1."
|
|
417
508
|
)
|
|
418
509
|
return
|
|
419
|
-
raise
|
|
510
|
+
raise PluginSecurityError(
|
|
420
511
|
"<osv-check>",
|
|
421
512
|
"The OSV advisory check failed on its last attempt (network "
|
|
422
513
|
"unavailable?). Plugin loading is blocked to protect against "
|
|
@@ -443,7 +534,7 @@ def _check_osv_cache_or_block(
|
|
|
443
534
|
)
|
|
444
535
|
return
|
|
445
536
|
aliases = ", ".join(v.get("aliases", []))
|
|
446
|
-
raise
|
|
537
|
+
raise PluginSecurityError(
|
|
447
538
|
"<osv-check>",
|
|
448
539
|
f"OSV advisory {v['id']}"
|
|
449
540
|
+ (f" ({aliases})" if aliases else "")
|
|
@@ -546,61 +637,6 @@ def _bounded_plugin_text(plugin_id: str, export_name: str, value: Any) -> str:
|
|
|
546
637
|
return text
|
|
547
638
|
|
|
548
639
|
|
|
549
|
-
def _check_json_text_limits(cst_json: str) -> None:
|
|
550
|
-
size = len(cst_json.encode("utf-8"))
|
|
551
|
-
if size > _HOST_UTILS_MAX_JSON_BYTES:
|
|
552
|
-
raise _host_utils_error(
|
|
553
|
-
f"JSON payload is {size} bytes; limit is "
|
|
554
|
-
f"{_HOST_UTILS_MAX_JSON_BYTES} bytes"
|
|
555
|
-
)
|
|
556
|
-
|
|
557
|
-
depth = 0
|
|
558
|
-
in_string = False
|
|
559
|
-
escaped = False
|
|
560
|
-
for ch in cst_json:
|
|
561
|
-
if in_string:
|
|
562
|
-
if escaped:
|
|
563
|
-
escaped = False
|
|
564
|
-
elif ch == "\\":
|
|
565
|
-
escaped = True
|
|
566
|
-
elif ch == '"':
|
|
567
|
-
in_string = False
|
|
568
|
-
continue
|
|
569
|
-
if ch == '"':
|
|
570
|
-
in_string = True
|
|
571
|
-
elif ch in "[{":
|
|
572
|
-
depth += 1
|
|
573
|
-
if depth > _HOST_UTILS_MAX_JSON_DEPTH:
|
|
574
|
-
raise _host_utils_error(
|
|
575
|
-
f"JSON nesting depth exceeds {_HOST_UTILS_MAX_JSON_DEPTH}"
|
|
576
|
-
)
|
|
577
|
-
elif ch in "]}":
|
|
578
|
-
depth = max(0, depth - 1)
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
def _check_trivia_type_limits(trivia_types: list[str]) -> None:
|
|
582
|
-
if len(trivia_types) > _HOST_UTILS_MAX_TRIVIA_TYPES:
|
|
583
|
-
raise _host_utils_error(
|
|
584
|
-
f"trivia type count is {len(trivia_types)}; limit is "
|
|
585
|
-
f"{_HOST_UTILS_MAX_TRIVIA_TYPES}"
|
|
586
|
-
)
|
|
587
|
-
|
|
588
|
-
total = 0
|
|
589
|
-
for trivia_type in trivia_types:
|
|
590
|
-
size = len(str(trivia_type).encode("utf-8"))
|
|
591
|
-
if size > _HOST_UTILS_MAX_TRIVIA_TYPE_BYTES:
|
|
592
|
-
raise _host_utils_error(
|
|
593
|
-
f"trivia type is {size} bytes; limit is "
|
|
594
|
-
f"{_HOST_UTILS_MAX_TRIVIA_TYPE_BYTES} bytes"
|
|
595
|
-
)
|
|
596
|
-
total += size
|
|
597
|
-
if total > _HOST_UTILS_MAX_TRIVIA_BYTES:
|
|
598
|
-
raise _host_utils_error(
|
|
599
|
-
f"trivia type payload is {total} bytes; limit is "
|
|
600
|
-
f"{_HOST_UTILS_MAX_TRIVIA_BYTES} bytes"
|
|
601
|
-
)
|
|
602
|
-
|
|
603
|
-
|
|
604
640
|
def _truncate_utf8(text: str, max_bytes: int) -> str:
|
|
605
641
|
encoded = text.encode("utf-8")
|
|
606
642
|
if len(encoded) <= max_bytes:
|
|
@@ -610,107 +646,22 @@ def _truncate_utf8(text: str, max_bytes: int) -> str:
|
|
|
610
646
|
return encoded[:budget].decode("utf-8", errors="ignore") + marker.decode("ascii")
|
|
611
647
|
|
|
612
648
|
|
|
613
|
-
def
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
raise _host_utils_error(f"invalid JSON: {exc.msg}") from exc
|
|
619
|
-
|
|
620
|
-
stack: list[tuple[Any, int]] = [(data, 1)]
|
|
621
|
-
count = 0
|
|
622
|
-
while stack:
|
|
623
|
-
node, depth = stack.pop()
|
|
624
|
-
count += 1
|
|
625
|
-
if count > _HOST_UTILS_MAX_JSON_NODES:
|
|
626
|
-
raise _host_utils_error(
|
|
627
|
-
f"JSON node count exceeds {_HOST_UTILS_MAX_JSON_NODES}"
|
|
628
|
-
)
|
|
629
|
-
if depth > _HOST_UTILS_MAX_JSON_DEPTH:
|
|
630
|
-
raise _host_utils_error(
|
|
631
|
-
f"JSON nesting depth exceeds {_HOST_UTILS_MAX_JSON_DEPTH}"
|
|
632
|
-
)
|
|
633
|
-
if isinstance(node, dict):
|
|
634
|
-
stack.extend((value, depth + 1) for value in node.values())
|
|
635
|
-
elif isinstance(node, list):
|
|
636
|
-
stack.extend((value, depth + 1) for value in node)
|
|
637
|
-
return data
|
|
649
|
+
def _host_limits() -> dict[str, int]:
|
|
650
|
+
return {"max_bytes": _HOST_UTILS_MAX_JSON_BYTES, "max_depth": _HOST_UTILS_MAX_JSON_DEPTH,
|
|
651
|
+
"max_nodes": _HOST_UTILS_MAX_JSON_NODES, "max_trivia_types": _HOST_UTILS_MAX_TRIVIA_TYPES,
|
|
652
|
+
"max_trivia_type_bytes": _HOST_UTILS_MAX_TRIVIA_TYPE_BYTES,
|
|
653
|
+
"max_trivia_bytes": _HOST_UTILS_MAX_TRIVIA_BYTES}
|
|
638
654
|
|
|
639
655
|
|
|
640
656
|
def _strip_trivia_impl(cst_json: str, trivia_types: list[str]) -> str:
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
data = _load_limited_cst_json(cst_json)
|
|
645
|
-
if not isinstance(data, dict):
|
|
646
|
-
return json.dumps(data, separators=(",", ":"), ensure_ascii=False)
|
|
647
|
-
|
|
648
|
-
results: dict[int, Any] = {}
|
|
649
|
-
stack: list[tuple[Any, bool]] = [(data, False)]
|
|
650
|
-
while stack:
|
|
651
|
-
node, visited = stack.pop()
|
|
652
|
-
if not isinstance(node, dict):
|
|
653
|
-
results[id(node)] = node
|
|
654
|
-
continue
|
|
655
|
-
if not visited:
|
|
656
|
-
stack.append((node, True))
|
|
657
|
-
children = node.get("children")
|
|
658
|
-
if isinstance(children, list):
|
|
659
|
-
stack.extend((child, False) for child in reversed(children))
|
|
660
|
-
continue
|
|
661
|
-
if node.get("type") in trivia_set:
|
|
662
|
-
results[id(node)] = None
|
|
663
|
-
continue
|
|
664
|
-
children = node.get("children")
|
|
665
|
-
if isinstance(children, list):
|
|
666
|
-
filtered = [
|
|
667
|
-
results[id(child)]
|
|
668
|
-
for child in children
|
|
669
|
-
if results.get(id(child)) is not None
|
|
670
|
-
]
|
|
671
|
-
results[id(node)] = dict(node, children=filtered)
|
|
672
|
-
else:
|
|
673
|
-
results[id(node)] = node
|
|
674
|
-
|
|
675
|
-
result = results[id(data)]
|
|
676
|
-
return json.dumps(result, separators=(",", ":"), ensure_ascii=False)
|
|
657
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
658
|
+
return json.dumps(_c_abi_call("host_strip_trivia", cst_json, trivia_types, _host_limits()),
|
|
659
|
+
separators=(",", ":"), ensure_ascii=False)
|
|
677
660
|
|
|
678
661
|
|
|
679
662
|
def _structural_hash_impl(cst_json: str) -> str:
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
Algorithm matches the engine: SHA-256, hex-encoded.
|
|
684
|
-
leaf: sha256(type + ":" + text)
|
|
685
|
-
internal: sha256(type + "|" + "|".join(hash(child) for child in children))
|
|
686
|
-
"""
|
|
687
|
-
|
|
688
|
-
data = _load_limited_cst_json(cst_json)
|
|
689
|
-
hashes: dict[int, str] = {}
|
|
690
|
-
stack: list[tuple[Any, bool]] = [(data, False)]
|
|
691
|
-
while stack:
|
|
692
|
-
node, visited = stack.pop()
|
|
693
|
-
if not isinstance(node, dict):
|
|
694
|
-
hashes[id(node)] = hashlib.sha256(str(node).encode()).hexdigest()
|
|
695
|
-
continue
|
|
696
|
-
children = node.get("children")
|
|
697
|
-
has_children = isinstance(children, list) and bool(children)
|
|
698
|
-
if has_children and not visited:
|
|
699
|
-
stack.append((node, True))
|
|
700
|
-
stack.extend((child, False) for child in reversed(children))
|
|
701
|
-
continue
|
|
702
|
-
# Accept BOTH key spellings (#49 item 2, latent bug): CST nodes carry
|
|
703
|
-
# type/text, but FullParse SemanticNode trees carry node_type/label — the
|
|
704
|
-
# old type/text-only reads hashed FullParse trees as all-blank SHAPE.
|
|
705
|
-
node_type = node.get("node_type") or node.get("type", "")
|
|
706
|
-
if has_children:
|
|
707
|
-
child_hashes = "|".join(hashes[id(c)] for c in children)
|
|
708
|
-
payload = f"{node_type}|{child_hashes}"
|
|
709
|
-
else:
|
|
710
|
-
text = node.get("label", node.get("text", ""))
|
|
711
|
-
payload = f"{node_type}:{text}"
|
|
712
|
-
hashes[id(node)] = hashlib.sha256(payload.encode()).hexdigest()
|
|
713
|
-
return hashes[id(data)]
|
|
663
|
+
from intentumdiff.rust_core import _c_abi_call
|
|
664
|
+
return _c_abi_call("host_structural_hash", cst_json, _host_limits())
|
|
714
665
|
|
|
715
666
|
|
|
716
667
|
def _log_impl(level: str, message: str) -> None:
|
|
@@ -782,6 +733,7 @@ class LoadedPlugin:
|
|
|
782
733
|
fuel: int,
|
|
783
734
|
iface_name: str,
|
|
784
735
|
trusted: bool = False,
|
|
736
|
+
compiled_wasm_sha256: str | None = None,
|
|
785
737
|
) -> None:
|
|
786
738
|
self._wasm_path = wasm_path
|
|
787
739
|
self._instance = instance
|
|
@@ -789,6 +741,8 @@ class LoadedPlugin:
|
|
|
789
741
|
self._fuel = fuel
|
|
790
742
|
self._iface_name = iface_name
|
|
791
743
|
self._trusted = trusted
|
|
744
|
+
# Digest of the *compiled* Wasm buffer, not a later filesystem snapshot.
|
|
745
|
+
self._compiled_wasm_sha256 = compiled_wasm_sha256
|
|
792
746
|
# Cache the interface-level ExportIndex for nested function lookups
|
|
793
747
|
self._iface_idx = instance.get_export_index(store, iface_name)
|
|
794
748
|
# Wasm Store is not thread-safe; serialise all calls through this lock.
|
|
@@ -803,6 +757,11 @@ class LoadedPlugin:
|
|
|
803
757
|
"""Path of the ``.wasm`` file that backs this plugin instance."""
|
|
804
758
|
return self._wasm_path
|
|
805
759
|
|
|
760
|
+
@property
|
|
761
|
+
def compiled_wasm_sha256(self) -> str | None:
|
|
762
|
+
"""SHA-256 of the exact Wasm bytes compiled for this live instance."""
|
|
763
|
+
return self._compiled_wasm_sha256
|
|
764
|
+
|
|
806
765
|
@property
|
|
807
766
|
def trusted(self) -> bool:
|
|
808
767
|
"""True when the plugin was loaded through a trusted first-party path."""
|
|
@@ -946,6 +905,7 @@ class LoadedPlugin:
|
|
|
946
905
|
fresh = load_plugin(self._wasm_path, self._fuel, trusted=self._trusted)
|
|
947
906
|
self._instance = fresh._instance
|
|
948
907
|
self._store = fresh._store
|
|
908
|
+
self._compiled_wasm_sha256 = fresh._compiled_wasm_sha256
|
|
949
909
|
self._iface_idx = fresh._instance.get_export_index(fresh._store, self._iface_name)
|
|
950
910
|
self._tainted = False
|
|
951
911
|
|
|
@@ -980,12 +940,24 @@ class LoadedPlugin:
|
|
|
980
940
|
if not unlimited:
|
|
981
941
|
try:
|
|
982
942
|
self._store.set_fuel(fuel)
|
|
983
|
-
except WasmtimeError:
|
|
943
|
+
except WasmtimeError as exc:
|
|
944
|
+
# Never dispatch an unmetered guest; this store is tainted.
|
|
984
945
|
status = "fuel_set_failed"
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
946
|
+
self._tainted = True
|
|
947
|
+
self._record_telemetry(
|
|
948
|
+
func_name=func_name,
|
|
949
|
+
fuel_budget=fuel,
|
|
950
|
+
fuel_unlimited=False,
|
|
951
|
+
fuel_consumed=None,
|
|
952
|
+
fuel_remaining=None,
|
|
953
|
+
elapsed_ms=(_time.perf_counter() - started) * 1000.0,
|
|
954
|
+
status=status,
|
|
955
|
+
args=args,
|
|
988
956
|
)
|
|
957
|
+
raise PluginSecurityError(
|
|
958
|
+
self._wasm_path,
|
|
959
|
+
f"required Wasm fuel cap could not be applied: {exc}",
|
|
960
|
+
) from exc
|
|
989
961
|
|
|
990
962
|
try:
|
|
991
963
|
# Two-level lookup: interface instance → function
|
|
@@ -1152,13 +1124,26 @@ def load_plugin(
|
|
|
1152
1124
|
_unlimited = fuel == -1
|
|
1153
1125
|
path = Path(wasm_path)
|
|
1154
1126
|
trusted = trusted or _is_trusted_wasm_path(path)
|
|
1155
|
-
_verify_builtin_provenance(path)
|
|
1127
|
+
verified_component_bytes = _verify_builtin_provenance(path) # #89, always fail closed
|
|
1156
1128
|
_check_wasmtime_version(path, trusted=trusted) # fast sync blocklist
|
|
1157
1129
|
_check_osv_cache_or_block(path, trusted=trusted) # fast sync OSV gate
|
|
1158
1130
|
_maybe_start_osv_check() # async refresh
|
|
1159
1131
|
|
|
1160
1132
|
if not path.exists():
|
|
1161
1133
|
raise PluginLoadError(str(path), "file not found")
|
|
1134
|
+
approved_component_bytes = _check_rust_component_load_policy(path)
|
|
1135
|
+
if (verified_component_bytes is not None and approved_component_bytes is not None
|
|
1136
|
+
and verified_component_bytes != approved_component_bytes):
|
|
1137
|
+
raise PluginSecurityError(str(path), "bundled Wasm changed between provenance and Rust approval")
|
|
1138
|
+
component_bytes = (approved_component_bytes
|
|
1139
|
+
if approved_component_bytes is not None else verified_component_bytes)
|
|
1140
|
+
if component_bytes is None:
|
|
1141
|
+
# Third-party components also compile from an owned, hashed buffer;
|
|
1142
|
+
# Component.from_file would hide which revision Wasmtime actually read.
|
|
1143
|
+
try:
|
|
1144
|
+
component_bytes = path.read_bytes()
|
|
1145
|
+
except OSError as exc:
|
|
1146
|
+
raise PluginLoadError(str(path), f"cannot read Wasm component: {exc}") from exc
|
|
1162
1147
|
|
|
1163
1148
|
try:
|
|
1164
1149
|
cfg = Config()
|
|
@@ -1167,6 +1152,26 @@ def load_plugin(
|
|
|
1167
1152
|
# exposes the setter (added in wasmtime-py post-44.0.0 builds).
|
|
1168
1153
|
if hasattr(cfg, "wasm_memory64"):
|
|
1169
1154
|
cfg.wasm_memory64 = False # type: ignore[attr-defined]
|
|
1155
|
+
|
|
1156
|
+
# Every plugin gets its OWN Engine, and wasmtime reserves a large contiguous virtual
|
|
1157
|
+
# address range per linear memory - 4 GiB by default on 64-bit, plus a guard region.
|
|
1158
|
+
# With 73 parsers that is roughly 292 GiB of RESERVED (not committed) address space.
|
|
1159
|
+
#
|
|
1160
|
+
# x86-64 shrugs at that. Windows on ARM64 does not: loading every parser in one
|
|
1161
|
+
# process - which language_ids() and every other inventory API does - fail-fasts with
|
|
1162
|
+
# STATUS_STACK_BUFFER_OVERRUN (0xC0000409) and no Python traceback, because the
|
|
1163
|
+
# failure happens in the allocator rather than in Python.
|
|
1164
|
+
#
|
|
1165
|
+
# Found by running the suite on windows-11-arm for the first time (#9). It was never
|
|
1166
|
+
# only a test problem: any arm64 user listing supported languages would have hit it.
|
|
1167
|
+
#
|
|
1168
|
+
# A parser reads a source file. 64 MiB is already generous, and memory can still grow
|
|
1169
|
+
# past the reservation by moving, so this caps address space, not capability.
|
|
1170
|
+
if hasattr(cfg, "memory_reservation"):
|
|
1171
|
+
cfg.memory_reservation = 64 * 1024 * 1024 # type: ignore[attr-defined]
|
|
1172
|
+
if hasattr(cfg, "memory_guard_size"):
|
|
1173
|
+
cfg.memory_guard_size = 64 * 1024 # type: ignore[attr-defined]
|
|
1174
|
+
|
|
1170
1175
|
if _unlimited:
|
|
1171
1176
|
logger.warning(
|
|
1172
1177
|
"Unlimited Wasm fuel for plugin %r — calls are uncapped and "
|
|
@@ -1175,7 +1180,9 @@ def load_plugin(
|
|
|
1175
1180
|
)
|
|
1176
1181
|
engine = Engine(cfg)
|
|
1177
1182
|
|
|
1178
|
-
|
|
1183
|
+
# Compile precisely the bytes whose digest is bound to this instance.
|
|
1184
|
+
# First-party protected components were approved by Rust above.
|
|
1185
|
+
component = Component(engine, component_bytes)
|
|
1179
1186
|
|
|
1180
1187
|
linker = Linker(engine)
|
|
1181
1188
|
linker.add_wasip2()
|
|
@@ -1183,18 +1190,18 @@ def load_plugin(
|
|
|
1183
1190
|
# Register host-utils imports using add_instance context manager.
|
|
1184
1191
|
# root must be closed before instantiate() is called.
|
|
1185
1192
|
root = linker.root()
|
|
1186
|
-
with root.add_instance("intentdiff:plugin/host-utils") as host:
|
|
1193
|
+
with root.add_instance("intentdiff:plugin/host-utils@1.0.0") as host:
|
|
1187
1194
|
host.add_func(
|
|
1188
1195
|
"strip-trivia",
|
|
1189
|
-
lambda store,
|
|
1196
|
+
lambda store, cst_json, trivia_types: _strip_trivia_impl(cst_json, list(trivia_types)),
|
|
1190
1197
|
)
|
|
1191
1198
|
host.add_func(
|
|
1192
1199
|
"structural-hash",
|
|
1193
|
-
lambda store,
|
|
1200
|
+
lambda store, cst_json: _structural_hash_impl(cst_json),
|
|
1194
1201
|
)
|
|
1195
1202
|
host.add_func(
|
|
1196
1203
|
"log",
|
|
1197
|
-
lambda store,
|
|
1204
|
+
lambda store, level, message: _log_impl(level, message),
|
|
1198
1205
|
)
|
|
1199
1206
|
root.close()
|
|
1200
1207
|
|
|
@@ -1207,7 +1214,13 @@ def load_plugin(
|
|
|
1207
1214
|
# after the balloon.
|
|
1208
1215
|
store.set_limits(memory_size=_plugin_memory_limit_bytes())
|
|
1209
1216
|
if not _unlimited:
|
|
1210
|
-
|
|
1217
|
+
try:
|
|
1218
|
+
store.set_fuel(fuel)
|
|
1219
|
+
except WasmtimeError as exc:
|
|
1220
|
+
# Do not instantiate without the mandatory CPU budget.
|
|
1221
|
+
raise PluginSecurityError(
|
|
1222
|
+
str(path), f"required Wasm fuel cap could not be applied during load: {exc}"
|
|
1223
|
+
) from exc
|
|
1211
1224
|
|
|
1212
1225
|
instance = linker.instantiate(store, component)
|
|
1213
1226
|
|
|
@@ -1233,6 +1246,7 @@ def load_plugin(
|
|
|
1233
1246
|
fuel,
|
|
1234
1247
|
iface_name,
|
|
1235
1248
|
trusted=trusted,
|
|
1249
|
+
compiled_wasm_sha256=hashlib.sha256(component_bytes).hexdigest(),
|
|
1236
1250
|
)
|
|
1237
1251
|
|
|
1238
1252
|
except (PluginLoadError, PluginSandboxViolation):
|