SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE
Developers

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:

  1. 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).
  2. A development folder is trusted (by: 'development'). SHADE_DEV_MODULES is refused in production (devModulesRefusal), so no folder is ever passed there.
  3. 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 its signature; 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.
  4. 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).
  5. Otherwise a server package doesn't run (null): it can't be installed, and at start it is left out with the reason signature, or approval for 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, trusted or approval key 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 sandbox either. 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 and shade-module build refuses to build it: "sandbox" is not allowed: SHADE sets it for sandbox packages only, never the module. validateModule takes 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.
  • trust and approvals are reserved module names (reservedNames()): the management areas /api/packages/trust and /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): apiRoutes mounts none of /api/packages/approvals (404; approvals being reserved, the modules' dispatcher finds nothing there either); every service in shade/features/packages/server/approvals.ts answers NOT_FOUND whoever asks; modulePackagesForStart gets approvalsOn: false, so an approved package is left out at start with reason approval and Approvals are switched off on this instance.
  • On: the services, each packages.manage plus assertSignedIn (so never a module's own actor: plugins.* is never grantable), under the shade:module-packages advisory lock where they write, in one transaction, audited:
    RouteServiceWhat it does
    POST /api/packages/approvalssubmitForApprovalChecks the file as installing does besides the signature (packageProblems: schema, trust claims, shade range, shared modules); refuses a sandbox package, a package a trusted key signed and an untrusted module's name; stores it in module_package_pending (one per name, replaced by a new upload). packages.approval-requested
    GET /api/packages/approvalslistPendingApprovalsThe waiting packages with their checks
    GET /api/packages/approvals/:nameapprovalReviewThe checks, the advisory list's date, the consent (summaryOf with signedBy: null) or why it can't be approved now, and the admin's SecondFactors
    POST /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 and packages.approve-failed; else a ticket and packages.approve-reauthenticated
    POST /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 and packages.approve-failed unless it is this team member's, this session's and this hash's), then module_approvals (hash, version, checks, approver, time), the package stored with approval_id and no signature (storePackage, as installing: the consent checked again under the lock, capability states), the pending row deleted. packages.approve
    POST /api/packages/approvals/:name/discarddiscardPendingApprovalpackages.approval-discarded
    DELETE /api/packages/approvals/:idrevokeModuleApprovalSets revoked_at, switches the module off (also under the shade:plugins lock) and announces it, so every container switches it off and the workers stop its processes and skip its schedules; switchInstalledModule refuses 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's verifyPassword, then a TOTP (six digits) through verifyTOTP or a backup code through verifyBackupCode on the current session, or a passkey assertion through Better Auth's own verification, stopped before it makes a session by the passkey module's authentication.afterVerification hook (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 the ApprovalIdentity the 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 with take (GETDEL), so it is used once whatever happens next.
  • The checks (approvalChecks(pkg, advisories) in server/approval-checks.ts, pure, nothing of the package runs): imports (importedModules, RISKY_NODE_MODULES flagged); 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); bundled against the advisory list shipped in server/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) without bundled; hosts in https?:// literals of module.mjs not declared by network (wildcards cover subdomains); imports of the SDK's testing entries; process.env reads; admin-dist/style.css rules outside [data-shade-module="<name>"] (unscopedRules). Each finding has an id (<kind>:<subject>) that acknowledged must list. The checks as the admin saw them are kept in module_approvals.checks.
  • Alerts: the plugins rule of features/errors/server/alerts.ts reads packages.approve and packages.revoke too, so every admin is emailed.
  • At start: modulePackagesForStart(db, keys, { approvalsOn }) reads every row of module_approvals (approvalsForTrust) for trustOf; 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 the module_packages row, so the approved version keeps running.

Where it shows

  • The instance's trust: GET /api/packages/trust (packages.read, admins), instanceTrust in shade/features/packages/server/trust-info.ts, returns TrustInfo (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 in InstanceTrustCard.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, a UCollapsible closed by default. While approvals are on, ModuleApprovalPanel.vue (upload, waiting packages, approved packages with Revoke) and ModuleApprovalModal.vue (the checks with a box per finding, the consent, signing in again with a code or a passkey through usePasskeyAssertion, the typed name) sit below the server packages.
  • Each module's trust: InstalledModuleInfo.trust on GET /api/packages/catalog, a ModuleTrustView made by moduleTrustView from what the API worked out at start (runtime.moduleTrust()): signature with the key's name, approval with the approver's name (listInstalledModules looks it up; null for an account deleted since), the time and the hash, development without its folder's path, or untrusted from the sandbox package with who signed it. ModuleTrustBadge.vue shows Trusted or Untrusted as a button opening a UPopover (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 and trustClaimProblems; sandbox refused 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.