Trust
A module is trusted or untrusted, and SHADE decides which; a module never does. A trusted module runs
inside the API's process and can do anything it can. An untrusted module runs in the sandbox (workerd) with only what
its capabilities give it. What each kind may declare is in the capabilities; this page is how
the kind is decided and shown.
How trust is decided
One pure function decides, trustOf in shade/kernel/modules/trust.ts. Its only inputs are the package and the
instance's state:
trustOf({
format, // 1: a sandbox package, 2: a server package
file, // the whole package file, as installed
trustedKeys, // SHADE_TRUSTED_MODULE_KEYS, parsed
approvals, // rows of module_approvals, revoked ones included
approvalsOn, // SHADE_PACKAGE_APPROVAL
devFolder // the module's folder from SHADE_DEV_MODULES, or null
}): ModuleTrust | null
The rules, in order:
- A sandbox package is untrusted, whoever signed it:
{ level: 'untrusted', by: 'sandbox', signedBy }. A signature by a trusted key only names who made it (signedBy). - A development folder is trusted (
by: 'development').SHADE_DEV_MODULESis refused in production (devModulesRefusal), so no folder is ever passed there. - A server package signed by a trusted key is trusted (
by: 'signature', with the key's name). The signature is Ed25519 over the canonical JSON of the file without itssignature; a file changed after signing, a key the instance doesn't list, or a signature under a listed name made with another key, is no signature. - A server package an admin approved is trusted (
by: 'approval') while approvals are on and an approval that isn't revoked is for exactly this package: SHA-256 of the canonical JSON of the whole file, so one changed byte is another hash (the approval flow below). - Otherwise a server package doesn't run (
null): it can't be installed, and at start it is left out with the reasonsignature, orapprovalfor a package installed by an approval that no longer holds (approvals switched off, the approval revoked, or the stored file not the approved one), saying which.
trustOf runs at install and at every start (checkedPackage and modulePackagesForStart in
shade/features/packages/server/packages.ts; the API for development folders in
apps/api/src/bootstrap/runtime.ts). The answer is never stored in the manifest, never given to the module and never
read from a service context. A module learns only whether it may use a capability (hasCapability).
The canonical JSON, the signature check, the hash and the key fingerprint are shade/kernel/modules/signing.ts
(Node's own crypto); shade/features/packages/server/signatures.ts builds on it (key pairs, signing, and the
errors an install shows).
Nothing a module writes claims trust
- A manifest with a
trust,trustedorapprovalkey is refused by the loader (validateModule), whatever the module's kind and even if a feature registered such a part:"trust" is not allowed: SHADE decides whether a module is trusted, never the module. - A trusted module may not set
sandboxeither. Only the code that builds a sandbox package's module sets it, and the Modules screen reads it to show a module as untrusted; a server package setting it still runs in the API's process, so the loader refuses it at start andshade-module buildrefuses to build it:"sandbox" is not allowed: SHADE sets it for sandbox packages only, never the module.validateModuletakes the module's trust from its caller, never from the manifest. - A server package with one of those keys is refused at install (VALIDATION, the key as the issue's path) and left out
at start (reason
invalid), signed or not. The package schema strips unknown keys, so the check (trustClaimProblems,TRUST_CLAIM_KEYS) runs on the file as uploaded. - A sandbox package's schema is strict, so the keys are unknown and refused.
trustandapprovalsare reserved module names (reservedNames()): the management areas/api/packages/trustand/api/packages/approvals.
The approval flow
A server package no trusted key signed becomes trusted when an admin approves exactly its hash,
after signing in again with the password and two-factor or a passkey. It exists only where the operator set
SHADE_PACKAGE_APPROVAL=true, read by apps/api/src/config.ts into config.moduleApprovals and nowhere else (no
database row, no admin switch).
- Off (the default):
apiRoutesmounts none of/api/packages/approvals(404;approvalsbeing reserved, the modules' dispatcher finds nothing there either); every service inshade/features/packages/server/approvals.tsanswers NOT_FOUND whoever asks;modulePackagesForStartgetsapprovalsOn: false, so an approved package is left out at start with reasonapprovaland Approvals are switched off on this instance. - On: the services, each
packages.manageplusassertSignedIn(so never a module's own actor:plugins.*is never grantable), under theshade:module-packagesadvisory lock where they write, in one transaction, audited:Route Service What it does POST /api/packages/approvalssubmitForApprovalChecks the file as installing does besides the signature ( packageProblems: schema, trust claims,shaderange, shared modules); refuses a sandbox package, a package a trusted key signed and an untrusted module's name; stores it inmodule_package_pending(one per name, replaced by a new upload).packages.approval-requestedGET /api/packages/approvalslistPendingApprovalsThe waiting packages with their checks GET /api/packages/approvals/:nameapprovalReviewThe checks, the advisory list's date, the consent ( summaryOfwithsignedBy: null) or why it can't be approved now, and the admin'sSecondFactorsPOST /api/packages/approvals/reauthenticate/optionsapprovalPasskeyOptionsA passkey challenge for the admin's own passkeys, with its cookie POST /api/packages/approvals/reauthenticatereauthenticateForApprovalSigning in again: FORBIDDEN ( NEEDS_SECOND_FACTOR) without a second factor; five attempts a quarter hour per team member (hitRateLimit, RATE_LIMITED); a wrong password or factor is VALIDATION andpackages.approve-failed; else a ticket andpackages.approve-reauthenticatedPOST /api/packages/approvals/:name/approveapproveModulePackage{ hash, ticket, typedName, accepted, acknowledged }: the typed name, every finding acknowledged, the consent and what the package builds on (checkConsent, read only, so a VALIDATION leaves the ticket for the corrected call), the ticket taken from the cache (FORBIDDEN andpackages.approve-failedunless it is this team member's, this session's and this hash's), thenmodule_approvals(hash, version, checks, approver, time), the package stored withapproval_idand no signature (storePackage, as installing: the consent checked again under the lock, capability states), the pending row deleted.packages.approvePOST /api/packages/approvals/:name/discarddiscardPendingApprovalpackages.approval-discardedDELETE /api/packages/approvals/:idrevokeModuleApprovalSets revoked_at, switches the module off (also under theshade:pluginslock) and announces it, so every container switches it off and the workers stop its processes and skip its schedules;switchInstalledModulerefuses to switch it on again.packages.revoke - Signing in again is the team part's
confirmIdentity(shade/features/team/server/confirm-identity.ts): the password through Better Auth'sverifyPassword, then a TOTP (six digits) throughverifyTOTPor a backup code throughverifyBackupCodeon the current session, or a passkey assertion through Better Auth's own verification, stopped before it makes a session by the passkey module'sauthentication.afterVerificationhook (confirmWithPasskey), which also checks the passkey is this team member's. It answers the session's id or null, never which part was wrong; the password is checked first, so a wrong one spends no backup code.teamIdentity(auth, ctx, headers)wraps it as theApprovalIdentitythe services take. - The ticket: 32 random bytes (base64url), kept in the cache port (
ctx.cache, Redis) only under its SHA-256 for five minutes (APPROVAL_TICKET_TTL_MS), bound to the team member, the session, the module's name and the hash, and taken withtake(GETDEL), so it is used once whatever happens next. - The checks (
approvalChecks(pkg, advisories)inserver/approval-checks.ts, pure, nothing of the package runs): imports (importedModules,RISKY_NODE_MODULESflagged); the declaration (capabilities, uses, admin places), which every start holds the code to (unlistedCapabilities,unlistedAdminPlaces: reading what the code does means running its manifest, so it isn't compared before approval);bundledagainst the advisory list shipped inserver/advisories.ts(SHIPPED_ADVISORIES: a package, an npm range, a GHSA id,asOf; brought up to date before each release; no outside call),null(unknown) withoutbundled; hosts inhttps?://literals ofmodule.mjsnot declared bynetwork(wildcards cover subdomains); imports of the SDK's testing entries;process.envreads;admin-dist/style.cssrules outside[data-shade-module="<name>"](unscopedRules). Each finding has an id (<kind>:<subject>) thatacknowledgedmust list. The checks as the admin saw them are kept inmodule_approvals.checks. - Alerts: the
pluginsrule offeatures/errors/server/alerts.tsreadspackages.approveandpackages.revoketoo, so every admin is emailed. - At start:
modulePackagesForStart(db, keys, { approvalsOn })reads every row ofmodule_approvals(approvalsForTrust) fortrustOf; an approved package runs while its hash matches an approval that isn't revoked. A new upload of the same module only waits: only approving replaces themodule_packagesrow, so the approved version keeps running.
Where it shows
- The instance's trust:
GET /api/packages/trust(packages.read, admins),instanceTrustinshade/features/packages/server/trust-info.ts, returnsTrustInfo(shared/trust.ts): each trusted key's name and fingerprint (the first 8 hex characters of SHA-256 of the key's 32 bytes, never the key),approvalsOn(SHADE_PACKAGE_APPROVAL),approved(while it is on: each installed package whose approval holds, with its approval's id, version, hash, approver's name and time),untrustedAllowed(the Allow untrusted modules switch),development(development folders loaded) and the counts of trusted and untrusted modules running. The Modules page shows it inInstanceTrustCard.vue: a plain summary of what trusted and untrusted mean, the counts and the untrusted switch first, and the keys, approvals, development folders and each approved package with its hash in Technical details, aUCollapsibleclosed by default. While approvals are on,ModuleApprovalPanel.vue(upload, waiting packages, approved packages with Revoke) andModuleApprovalModal.vue(the checks with a box per finding, the consent, signing in again with a code or a passkey throughusePasskeyAssertion, the typed name) sit below the server packages. - Each module's trust:
InstalledModuleInfo.trustonGET /api/packages/catalog, aModuleTrustViewmade bymoduleTrustViewfrom what the API worked out at start (runtime.moduleTrust()):signaturewith the key's name,approvalwith the approver's name (listInstalledModuleslooks it up; null for an account deleted since), the time and the hash,developmentwithout its folder's path, oruntrustedfrom the sandbox package with who signed it.ModuleTrustBadge.vueshows Trusted or Untrusted as a button opening aUPopover(click or tap, so touch works) with one sentence on what it means and who signed or approved it (no hash); the button's accessible label carries the same sentence. It is null where the answer isn't known (the answers of switching a module and saving its settings).
The texts are under plugins.trust.* in shade/features/packages/admin/locales/{en,nl}.json, with the
glossary's Dutch words (vertrouwd, niet-vertrouwd, ondertekend, goedgekeurd).
Tests
shade/test/kernel/modules/trust.test.ts: trust never read from a manifest (claims refused by the loader, the sandbox package's schema andtrustClaimProblems;sandboxrefused on a trusted module; a package claiming it still doesn't run); a sandbox package untrusted even when a trusted key signed it (approved or in a folder too); a server package nobody signed or approved not run (unknown key, another key under a listed name, changed after signing, a key taken out); an approval only for its hash (one changed byte, another version, revoked, another name); approvals ignored while off; a development folder only outside production; the key fingerprint.shade/test/features/packages/server/packages.test.ts: each package's trust at start, and a package claiming trust refused at install and left out at start, signed or not.shade/test/features/packages/server/trust-info.test.ts: the instance's trust (keys by fingerprint and never the key, the untrusted switch, development, counts, admins only) and each module's badge (a sandbox package untrusted whatever else is said, a folder's path never shown, no badge where nothing was worked out, an approver by name).shade/test/features/packages/server/approvals.test.ts(Postgres, real team sign-in and two-factor codes): every call NOT_FOUND while approvals are off; approving only after signing in again within five minutes, never with the password alone, a backup code once; five attempts a quarter hour; an admin with neither factor refused and told to set one up; a ticket used once, for one session, one team member and one hash; the approval recorded, audited and alerted; the approved version running until the next is approved; a package changed after approval and one with approvals off left out at start, saying why; a module's actor, an editor and nobody refused; a revoked package switched off and left out; a sandbox package, a trust claim or a signed package never approved.shade/test/features/packages/server/approval-checks.test.ts: risky imports, environment reads, test entries, undeclared hosts, unscoped styles and bundled packages on the advisory list, each a finding; a real build's stylesheet counts as scoped.apps/api/test/config.test.ts: "reads SHADE_PACKAGE_APPROVAL as off by default";apps/api/test/sweep/access.test.ts: no approval route while it is off, and every approval route's answer for every kind of actor (access-table.ts).e2e/tests/modules-packages.spec.ts: the trust card's summary, counts and untrusted switch, the technical details closed until opened (keys by fingerprint, approvals on, no development folders, no approved packages), and the installed package's Trusted with its meaning and Signed by shade-tests-packages., and no hash;e2e/tests/modules-untrusted.spec.ts: Untrusted with its accessible name, and Signed by shade-tests. in the signed sandbox package's popover;e2e/tests/modules-approvals.spec.ts: an admin uploads a package nobody signed (made in the test from a fixture without its signature), is told to set up a second factor, adds a passkey, ticks each finding, signs in again with the password and the passkey, approves it, sees it under Approved packages with its hash, and revokes it.