Commit Graph

27 Commits

Author SHA1 Message Date
Teknium
6e1f1dec1b feat(plugins): desktop surface lint refuses reaching the preview webview
A catalog plugin that queries or creates a `<webview>` scripts the preview
page without declaring `preview.executeJavaScript` or asking the user.
Admission now fails it as "preview guest reach"; `ctx.preview` stays clean.
2026-10-23 15:42:04 -07:00
Teknium
0983654319 fix(plugins): drop the prototype-patching rule from the Desktop surface lint
The rule could not tell a bundled library's own classes from patching a renderer global: it kept
failing legitimate bundles (three.js once minified to $-names) and still missed a bare $ receiver.
Prototype writes in a Desktop plugin are now read by the catalog reviewer instead; the policy in the
catalog docs stays, with a note that review checks it by hand. eval/new Function, non-SDK imports,
script injection and app-DOM reach are still linted.
2026-10-21 08:17:10 -07:00
Teknium
493208879a fix(plugins): a regex after return is not division
An expression must follow return/typeof/throw/etc., so a `/` there can only
open a regex; offering the division reading left the regex text visible and
refused `return /Track = vector/` as a rebinding of Track. `of` keeps both
readings because it is also a plain identifier.
2026-10-19 07:39:24 -07:00
Teknium
108b5791d3 fix(plugins): follow both readings of an ambiguous slash; keys are not targets
- After `)` or `}` a `/` can open a regex or be division; picking either
  one lets a crafted literal hide code (a quote inside `if (x) /"/` blanked
  the patch after it). The scanner now follows every legal reading at once
  and blanks a character only when ALL live readings agree it is literal
  text. The true reading is always among them, so executable code is never
  blanked; a regex after `if (...)` is also read correctly again.
- In a destructuring pattern, a class name used only as a key
  (`{Track: value} = o`) is not a rebinding of Track.
2026-10-19 07:39:24 -07:00
Teknium
1cf3ac3cb0 fix(plugins): ternary destructuring rebinds; ambiguous slashes never hide code
- A destructuring assignment after `?`, `:`, `&&`, `||`, `!`, return, yield
  or void now counts as rebinding X (`c ? [S] = [window.Storage] : 0`).
- Drop the if-condition regex heuristic: it scanned raw text backwards, so
  `Number("if (") / (Storage.prototype.x = spy) / 3` read as a regex and the
  patch between the slashes was blanked. Every ambiguity now resolves toward
  scanning as code: a wrong guess there only refuses a bundle for review,
  while a wrong guess the other way hides a patch.
2026-10-19 07:39:24 -07:00
Teknium
0b07d25774 fix(plugins): computed keys are not patterns; a regex may follow an if condition
- `registry[Track.name] = Track` read as a destructuring pattern naming Track.
  A pattern now has to open where an expression cannot (start of statement,
  after = ( , or let/const/var) and name X itself, not X.name.
- The scanner read any `/` after `)` as division, so a regex statement after
  `if (ready)` was scanned as code. A `)` that closes an if/while/for/with
  condition now lets a regex literal start.
2026-10-19 07:39:24 -07:00
Teknium
12892c87ed fix(plugins): destructuring assignments rebind; template ${} and division stay code
- A destructuring ASSIGNMENT (`({S} = o)`, `[S] = a`), compound assignment
  (`S ||= x`), `for (S of ...)` and import bindings now count as rebinding S.
- The literal mask blanked whole template literals (hiding code in `${...}`)
  and treated `/ (...) /` division as a regex (hiding the code between). It
  is now a small scanner: string and template TEXT is blanked, `${...}` stays
  code, and `/` opens a regex only where an expression cannot end before it.
2026-10-19 07:39:24 -07:00
Teknium
88e17eecf7 fix(plugins): passing a class around or naming it in a string is not a rebinding
The rebinding check read any `(X)` or `, X)` as a binding, so
`register(Track); Track.prototype.x = ...` failed admission, and it scanned
unmasked source, so a label like "Track = vector" did too. A rebinding is now
only an assignment, a let/const/var/class/function declaration, a destructuring
declaration, or a parameter (function, method, arrow, catch), matched on source
with strings and regex literals masked.
2026-10-19 07:39:24 -07:00
Teknium
1a1a984629 fix(plugins): a prototype write passes only where X provably is the own class
Greptile (3/5) held the PR because aliases could still borrow an unrelated
class name: the alias list enumerated spellings, and window["Storage"] or
(0, window.Storage) were not on it. Enumerating spellings cannot be finished,
so the rule flips: X.prototype.y = passes only inside the body of class X /
function X, or after a class X / function X / var X = class statement in the
same block, with no rebinding of X in between. Everything else fails,
whatever the alias looks like. This also holds for minified bundles that reuse
one-letter names (three.js minified: class s{...s.prototype.isVector2=!0}).

three.module.js, three.core.js and the minified Meshy bundle: 0 findings.
2026-10-19 07:39:24 -07:00
Teknium
317f201ea8 fix(plugins): a constructor registry naming a global as a key is not an alias
The alias rule treated any `{ Array: Track }` object literal as destructuring
from a renderer global, so a bundled library keeping a type registry was refused
for writing its own Track.prototype. Destructuring now counts only when the
source is window/globalThis/self.
2026-10-19 07:39:24 -07:00
Teknium
3586e58d62 fix(plugins): an alias of a renderer global cannot borrow an unrelated class name
The declared-name set is file-wide, so `function u() { class S {} }` excused
`const S = window.Storage; S.prototype.setItem = ...` (Greptile review). Any name
bound to a renderer global (`X = Storage`, `X = window.Storage`,
`{ Storage: X } = window`) now always fails, like the global itself. The three.js
bundles still pass.
2026-10-19 07:39:24 -07:00
Teknium
f8fc25a869 fix(plugins): Desktop lint stops flagging a bundled library's own classes
The "prototype patching" admission rule matched any `X.prototype.y =` line. A
bundled library setting fields on classes it declares itself trips it: three.js
alone hits it 29 times (`var Vector2 = class _Vector2 { constructor() {
_Vector2.prototype.isVector2 = true } }`, `KeyframeTrack.prototype.ValueTypeName
= ...`), so no Desktop plugin could ship a three.js viewer.

The write now fails only when the receiver is not a class/function the file
declares, or is a renderer/browser global (Storage, HTMLElement, Array, ...),
which keeps failing even when the file shadows it with a same-named class (a
regex cannot see scope). Every attack shape the rule exists for still fails:
`Storage.prototype.setItem = ...`, an alias of a global, a shadowed global.
2026-10-19 07:39:24 -07:00
Maciej Lisiewski
2ff58849f4 ci: ruff UP037 fixes 2026-10-09 17:34:38 +02:00
Maciej Lisiewski
d76cce4f11 ci: apply all automatic linter fixes available 2026-10-08 17:22:54 +02:00
Teknium
f304cf4a7d fix(plugins): lint every Desktop entry layout the installer accepts, incl. repo-root plugin.js
The admission lint only scanned desktop/**/*.js, but the Desktop git installer (findDesktopEntry) prefers a repo-root plugin.js and publishes the root beside it, so root-layout plugins skipped the lint entirely.
2026-10-04 17:53:20 -07:00
teknium1
aa859fd4c8 feat(plugin-catalog): refuse plugins that override Hermes core or Desktop at runtime
Catalog policy (Teknium): a listed plugin extends Hermes only through public
surfaces. A plugin that replaces core functions, methods or Desktop UI in place
collides with every other plugin patching the same seam and breaks on any core
release.

- New `no core override` admission check (hermes_cli/plugin_validate_core_override.py):
  static taint pass over the import closure of __init__.py and dashboard/*.py.
  Core values are Hermes modules (plus hermes_plugins.*) and attribute chains off
  them, reached by import, importlib/sys.modules lookups, getattr, iteration, or a
  plugin helper that returns one. Rebinds are attribute assignment/deletion,
  setattr/delattr, sys.modules writes, writes into a core module's tables,
  mock.patch, and passing a core value to a helper that setattr's its parameter.
  Tests, benchmarks and CI/smoke scripts outside the import closure are not judged.
- Desktop lint: new `app DOM reach` rule (document-level queries of the app's own
  data-slot/data-tour/data-sidebar/data-testid markup, and document.body
  childList/subtree MutationObservers).
- Desktop lint bug: the comment stripper did not skip string literals, so a string
  holding `/*` (a glob like '**/*.md') opened a fake comment and hid every line up
  to the next `*/` from all rules. Strings are now matched first and kept.
- README rule 9, the plugin-catalog user guide and the plugin developer guide's
  compatibility contract state the rule.

A/B over 466 pinned trees (121 open catalog PR entries + 349 listed entries +
humalike): the new checks flag exactly the hand-verified overrides; zero crashes;
no previously reported Desktop finding disappears.
2026-10-01 12:41:57 -07:00
ethernet
c70129205f Merge remote-tracking branch 'origin/main' into ethie/pm-clean 2026-09-24 05:10:12 -04:00
teknium1
5765f8d190 fix(plugins): desktop lint masks a new RegExp("<script…") only where it is used as a matcher
Review finding (MAJOR-1): masking the first argument of every new RegExp(...)
also hid `el.innerHTML = new RegExp("<script src=x></script>").source`, a real
injection through .source — desktop_surface_findings returned 0 findings for
that line. The literal is now masked only when the constructor is the argument
of .replace/.replaceAll/.split/.match/.matchAll/.search or the receiver of
.test/.exec; every other use (.source, .toString(), template interpolation) is
a string-builder and keeps firing. The existing test gains the .source line
(must flag) and a .test() line (must not).
2026-09-24 02:03:03 -07:00
teknium1
00c9f3ec58 fix(plugins): desktop lint reads a new RegExp("<script…") pattern as a sanitiser
The regex-literal form was already masked (50e9cd7bd5); rss-reader
(#115972, desktop/plugin.js:2577) still ships "<scr"+"ipt" split strings
because the same sanitiser spelled for a dynamic flag — the string handed
straight to new RegExp( — kept scoring as 'script injection'. Mask only
that first-argument literal; a '<script' string written into the DOM and
createElement('script') + .src= still fail.

Part of #116305 (item 10).
2026-09-24 02:03:03 -07:00
ethernet
d0d4e91434 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	hermes_cli/plugins_cmd.py
#	hermes_cli/plugins_cmd_catalog.py
#	tests/hermes_cli/test_web_plugins_catalog.py
#	website/docs/reference/cli-commands.md
#	website/docs/user-guide/features/plugin-catalog.md
2026-09-22 02:59:10 -04:00
teknium1
69bb325cae fix(plugins): admission lint refuses static URL-scheme imports in desktop/plugin.js
The 'dynamic import outside the SDK' rule matched only import(); a static import 'https://…' passed admission while being the same one-line second stage. New rule 'remote import outside the SDK' mirrors the loader's allowlist so review and the app agree.
2026-09-21 22:39:35 -07:00
ethernet
9f2ba1b74d merge origin/main (779 commits) into ethie/pm-clean
Branch semantics kept where main and PM disagree: update_cmd_deps.py,
constraints-termux.txt, the Electron update-api-check module and the
post-swap hand-off test stay deleted; the pending-fleet-restart catch-up
and the local_runtime tag/download ladder stay retired (PM owns engines).

Ported from main onto the branch's shape: profile_scoped_chore for the
auto-archive and plugin-update housekeeping chores, the local-runtime
cross-process boot lock and residency cap, the checkpoint tmp_pack sweep,
the cua daemon-liveness status probe, the remote-served Desktop update
flag (posix.sh / windows.ps1), sign-in for env-pinned remote gateways
(urlDisabled on RemoteSetupFields), the uvloop extra split (uvicorn
without [standard]), and the umask-scoping spawn test.

uv.lock regenerated with pm.build_env --lock-only; new utf-8 reads from
main switched to utf-8-sig (check-windows-footguns).
2026-09-21 00:58:39 -04:00
teknium1
dad0057271 fix(plugin-guard): v8 — four intake false-positive classes step down where inert
Real catalog pins from the 2026-09-20 intake batch scored on text that cannot run on
the installing host:

1. `.github/workflows/*.yml` — a CI step's own `os.environ['RUNNER_TEMP']` read scored
   `python_os_environ/high` and made a clean plugin `caution` (remarkable). A workflow
   runs on the forge's runner; it now takes the README prose cap (one step down,
   agent-facing shapes like `curl | sh` keep full severity).
2. "pip install" inside a user-facing message literal (`"... no pip install is needed"`,
   image-utils) scored `unpinned_pip_install/medium`; mid-literal, non-command position,
   no exec verb on the line → low. `"pip install x"`, `python -m pip install`, `uv pip`,
   `subprocess.run("pip install …")` keep medium.
3. `desktop_surface_findings()` was being run by batch tooling over every `*.js`/`*.mjs`
   in a repo and flagged a Node sidecar's lazy `import('jszip')` (remarkable). The
   product check was already scoped to `desktop/`; expose that scope as
   `is_desktop_surface()` / `desktop_surface_hits()` so tooling shares it.
4. `127.0.0.1:<port>` (README, .mcp.json, client defaults) scored `hardcoded_ip_port` as
   network egress; a line whose every IP:port is loopback → low. A routable address on
   the line keeps medium.

Every finding stays in the report. PLUGIN_SCANNER_VERSION → plugin-guard-v8 so cached
verdicts on quarantined pins are re-evaluated.
2026-09-20 11:49:00 -07:00
ethernet
ce3d042f0c Merge remote-tracking branch 'origin/main' into ethie/pm-clean 2026-09-19 23:08:38 -04:00
ethernet
119bc61c3b fix: read text files with encoding=utf-8-sig in modules merged from main 2026-09-19 22:57:45 -04:00
teknium1
50e9cd7bd5 fix(plugin-guard): two intake false positives — regex literal <script, allowlist "printenv"
Desktop lint: /<script[\s\S]*?<\/script>/gi in a feed sanitiser scored as
'script injection' and failed pinned-source-validate for rss-reader. Mask
JS regex literals for the markup-shaped rule only; <script in a string
literal (an innerHTML payload) and createElement('script') still fail.

Install scanner: "printenv" as a whole-string entry of a read-only
allowlist (frozenset({..., "printenv"})) fired dump_all_env high →
caution on hermes-jev. Extend the literal-token demotion: a token that is
the ENTIRE quoted literal on a line that executes nothing steps down like
an alternation member; "sudo" inside subprocess.run([...]) and
os.system("printenv") keep high.

A/B vs origin/main: attack probes identical (23 rows), in-tree sweep 319
entries 0 worse/0 changed; both new tests red on base. Bumps
PLUGIN_SCANNER_VERSION to v6 so cached caution verdicts refresh.

Signed-off-by: teknium1 <teknium1@users.noreply.github.com>
2026-09-19 14:30:36 -07:00
teknium1
72f55062d2 feat(plugin-catalog): refuse desktop plugins that step outside the SDK surface
A desktop/plugin.js is evaluated in the Electron renderer with the app's
full authority; the runtime loader documents itself as error isolation
only and says a remote source must not reuse it without a boundary. The
catalog is that remote source, so admission now fails a plugin whose
desktop code patches prototypes, uses eval/new Function, dynamically
imports anything but the SDK (app chunks, blob/http URLs), or injects
script tags. Against the 18 desktop plugins in the current sweep the lint
passes 17 and fails the one the security review flagged for exactly these
moves. Policy written down in plugin-catalog/README.md rule 8 and the
user-facing catalog doc.
2026-09-19 03:19:18 -07:00