Plugins run only verified code. /JL

This commit was merged in pull request #6.
This commit is contained in:
Lerking committed 2026-11-22 21:55:15 +01:00
1 parent a91efef114
commit aa5978ff92
6 files changed
+425 -35

No files matched your search

+33 -1
View File
@@ -1,5 +1,5 @@
# XtendR
![Latest Version](https://gitpot.lerk.ing/badges/badge/static?label=Latest+version&message=0.5.3&color=blue)
![Latest Version](https://gitpot.lerk.ing/badges/badge/static?label=Latest+version&message=0.5.4&color=blue)
A very basic Python 3.12 friendly plugin system based on the K.I.S.S principle.
@@ -30,3 +30,35 @@ The system expects a folder called 'plugins', placed at the root, along side you
Each plugin should be placed in subfolders, named as the plugin, inside the 'plugins' folder.
The example.py along with the plugins/example_plugin/example_plugin.py and plugins/example_plugin/example_plugin.json shows the workings of this plugin system.
## Security
Plugins are Python code that runs with the host's full rights, so XtendR only runs a plugin whose
manifest (`<name>.json`) and module (`<module>.py`) match an Ed25519-signed whitelist entry.
Unsigned or tampered plugins are listed but never executed. Since 0.5.4 XtendR reads each file
exactly once, checks the signature over those bytes and runs those same bytes: no second read from
disk, no `__pycache__` bytecode, no symlinked files.
Signing proves a plugin is unchanged since it was signed, not that it is safe. Keep the private key
off shared machines and pin the public key in the host application.
## Testing
python3 -m pytest tests -v
## Changes
- **0.5.4** — Plugins run exactly the code that was verified.
- *Fixed:* a `__pycache__/<module>.cpython-*.pyc` carrying the signed source's mtime and size
ran instead of the verified `.py` (the import machinery preferred the cache). `attach()` now
compiles and executes the verified bytes itself and never consults or writes bytecode.
- *Fixed:* files were read once to verify and again to import, and the manifest was parsed
before it was hashed. A file swapped in between could run unverified code or point the import
at another module. Each file is now read once (`O_NOFOLLOW`, regular files only, size-capped),
and the manifest's `module`/`class` must equal the signed entry's.
- New `signing.hash_plugin_bytes()` and `verify_plugin_bytes()`; the digest is unchanged, so
existing whitelists stay valid. `generate_keypair()` creates the private key 0600 from the
start; `Whitelist.save()` writes atomically and keeps the file's permissions.
- `setup.py` declares `cryptography>=42`; `__version__` reports 0.5.4 (was a stale 0.5.1).
- New `tests/test_integrity.py` (real keys; fails on 0.5.3 for the bypasses above). The
`XtendRBase` doctest example implements `pre_load` so it runs again.