Skip to content

fix: refuse DIDs the node cannot verify offline (TC-1500) - #677

Merged
samgbafa merged 4 commits into
mainfrom
fix/tc-1500-verifiable-dids
Nov 21, 2026
Merged

samgbafa merged 4 commits into
mainfrom
fix/tc-1500-verifiable-dids

Conversation

@samgbafa

@samgbafa samgbafa commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #392. Security card item 11, approved by Sam with every recommended choice. Details: TC-1500.

What changes

The node verifies a UCAN signature only when it can derive the signer's key offline. Any other DID is refused before it is decoded or resolved. The same rule now applies to the holder (aud) of every new grant posted to /delegate.

Class Accepted Refused (did_unverifiable: / did_holder_unverifiable:)
did:key Ed25519 (0xed 0x01), secp256k1 (0xe7 0x01), P-256 (0x80 0x24), compressed, base58btc. The id must be exactly 48 or 49 chars, checked before the base58 decode (M1) wrong length, a multibase other than base58btc, the one-byte 0xed prefix (z2D…), P-384, private-key codecs, off-curve points, small-order Ed25519 keys, uncompressed keys
did:jwk OKP Ed25519 and EC secp256k1/P-256 public keys; the id is at most 256 chars, checked before the base64url decode (N1) private d, other curves (P-384, X25519), off-curve points, small-order Ed25519 keys, oversized ids
did:pkh CAIP-10 eip155 (0x+40 hex), solana (32-byte base58 Ed25519 key), bip122 (Bitcoin or Dogecoin mainnet genesis); id at most 96 chars tezos, the legacy eth/sol/btc/… forms, other chain references, malformed accounts, small-order solana keys
other methods none did_method_disabled: (unchanged), before resolution and without any network connection
holder did:tinycloud:policy:<64 lowercase hex> exempt (Policy/v3 delegate; holds a policy root, never signs) any other did:tinycloud:policy: form

Points are validated through JWK::from_multicodec (did:key) and a to_multicodec round trip (did:jwk). Ed25519 keys (did:key, did:jwk, solana) must also decompress and must not be of small order (VerifyingKey::is_weak). ssi verifies with dalek's non-strict verify, so anyone could sign for a small-order key, and a grant to one would be a grant to everyone (review N1).

Status codes are unchanged: 401 on /delegate and /invoke, 403 on /revoke. Refusals increment tinycloud_did_resolution_refused_total{method,reason} with the new reasons unverifiable and holder_unverifiable.

Other changes:

  • Holder intake. check_holder is the last of delegation::check_capability_rules, which runs in the pre-lock precheck (TC-3000) and again in validate_with, so it covers /delegate, the Policy/v3 batch paths and process. It also runs in save_owner_renewal_lease. Refusals specific to the capabilities (key-delete-not-delegable, named keys, SQL caveats) keep their codes, and so do issuer refusals. Stored grants and invocations are not re-checked. Renewal-original verification (renewal.rs) is unchanged, so an existing grant still renews. Resubmitting a grant already stored still answers as already registered, on both paths: the single path already did, and process_with now does too when the only refusal is the holder (review N3).
  • Parsers tightened. The encryption-network, share-email data-plane and node-server share-email did:key parsers now use one function, tinycloud_auth::share_email_evidence::did_key_public_key. It accepts Ed25519 0xed 0x01 only, checks the length before decoding, and refuses keys that do not decompress or are of small order.
  • eip191. A Policy/v3 eip191 authority artifact must name an eip155 did:pkh issuer before key recovery.
  • did_resolution.network_methods removed. It goes through the existing REMOVED_SETTINGS path (the TC-2961 pattern): a node that still sets it starts and warns that it is ignored. /info did_resolution.network_methods stays as a constant false for existing readers. Use the documented DID method policy for UCAN verification #392's opt-in mechanism is not carried forward.
  • Not changed (review N4). eip155 accepts a wrong EIP-55 checksum or a chain id like 01, and bip122 does not check the base58check checksum. Such a holder can never sign an invocation the node verifies, so refusing it adds no protection.

The 247 did:key:z2D… grants this refuses, and why they are inert (for Bobbie)

Production holds 247 live grants (135 distinct holders) whose holder is a did:key:z2D…. After this PR, a new grant to such a holder is refused with did_holder_unverifiable:. The stored ones are untouched.

Census, from Amos's GO read of the BC replica on 11-19 at about 21:00Z (Linear TC-1500 comment cf4201f8):

Holder class Live grants Holders
did:key Ed25519 56,105 41,855
did:pkh eip155 687 294
did:key:z2D… 247 135
did:tinycloud:policy 10 10

Why the z2D grants are inert:

  1. What they are. These are the node's own per-space host keys from GET /peer/generate/<space>. Until a767302 (2026-06-05, "feat: add encryption network module", tinycloud-core/src/keys.rs), the node encoded them as [0xed] + key, a one-byte varint, instead of the 0xed 0x01 Ed25519 multicodec. Base58 of that prefix gives z2D….
  2. Who issued them. All 247 were issued by 89 eip155 wallets via SIWE, between 03-14 and 06-04. That is before the encoder fix, and none is newer. Five of those wallets were active in the last 30 days. The grants have no expiry.
  3. They cannot be exercised, after this PR. ssi's did:key resolver never decoded a one-byte 0xed did:key, so no UCAN delegation, invocation or revocation signed by a z2D DID could verify. The replica shows that no z2D DID ever issued one. The holder can't use the grant, and nobody can re-delegate from it. Before this PR, two other parsers did accept the one-byte form: the encryption-network request signer (encryption_network/service.rs) and the share-email data-plane signer (share_email/data_plane.rs). Both now use the shared 0xed 0x01 parser. Whether any z2D-signed request ever reached those two paths is a production log question (review N2), and Amos is asked to check it before deploy.
  4. Effect of this PR. The stored rows are unchanged. Re-posting such a grant answers as already registered; a new grant to a z2D holder is refused at intake rather than failing at first use. The current encoder (a767302 onward) produces z6Mk…, so no current client produces z2D holders.

Holder formats produced by every grant-creating client (for Naomi's GO)

The new intake rule accepts these holders:

  • did:key with Ed25519, secp256k1 or P-256 keys, id 48–49 chars;
  • did:jwk, id ≤256 chars;
  • did:pkh accounts eip155:<digits>:0x<40 hex>, solana and bip122 (BTC, DOGE);
  • did:tinycloud:policy:<64 lowercase hex>.

A #fragment is stripped before the check (tinycloud-core/src/util.rs:217, :247).

Refs below are js-sdk origin/master cb3edeab4, openkey origin/main 05edebab, secret-manager origin/main c21daa9, and this PR.

Client Holder it produces Source Passes
web-sdk session keys (sign-in, incl. via OpenKey) Ed25519 did:key:z6Mk… (0xed 0x01 + 32 bytes, 48 chars), from the WASM session manager sdk-rs src/session/manager.rs:209 (JWK::generate_ed25519), :281 (DIDKey::generate); web-sdk src/adapters/BrowserWasmBindings.ts:105, :110 yes
CLI login key same session manager, createSessionKey("cli") cli src/auth/local-key.ts:23-27 yes
CLI --device approval OpenKey derives the delegate from the CLI's public JWK: Ed25519 only, 32 bytes, 0xed 0x01 openkey apps/api/src/services/device-authorization.ts:337-344; CLI sends publicJwk(...) at cli src/auth/browser-auth.ts:109 yes
Courier agent, relay and peer keys session manager createSessionKey('courier') / ('courier-relay'); peer did:key rebuilt as 0xed 0x01 + x; named recipients must be an exact Ed25519 Courier did:key courier src/commands.ts:59-62, src/invitation.ts:264-265, :316-317, src/state.ts:395, src/did-key.ts:17-18 yes
Hosted MCP session manager createSessionKey("hosted-mcp") mcp src/remote-store.ts:1367-1370 yes
OpenKey relays the SIWE URI the app supplies (any URI shape) for authorize-sign; device as above; renewal lease to the node's renewer openkey apps/api/src/services/signed-subset.ts:136, :332; renewal-lease.ts:211 yes for every SDK caller; a third-party app sending a non-did:key URI is now refused at /delegate (see the note after the table)
Renewer (lease aud) node renewer identity, Ed25519 did:key via public_key_to_did_key (0xed 0x01) node tinycloud-core/src/renewal.rs:438-444, tinycloud-core/src/keys.rs:19-27; served at /.well-known/tinycloud/node-keys, read by openkey renewal-lease.ts:168-176 and node-sdk src/TinyCloudNode.ts:2685 yes; owner_lease_registration exercises it through save_owner_renewal_lease
Policy holders (Share Policy/v3) did:tinycloud:policy:<sha256 hex>, lowercase (hex() of a sha256) share-sdk src/addressed-publish.ts:139-140, :196, :421 yes (exempt)
Policy enforcer (Share Policy/v3) the node's stable did:key (activeNode.nodeDid) share-sdk src/addressed-publish.ts:422; cli src/share/adapters.ts:942, :1017; courier src/email-invitation.ts:136 yes
Share link recipients a fresh per-share session key from the session manager; aud is the DID without its fragment sdk-core src/delegations/SharingService.ts:738-741, :778 yes
Share recipients named by DID / email / domain (Policy/v3) the recipient is a policy matcher, not a grant holder; the holders are the two rows above share-sdk src/addressed-publish.ts:114, :368, :421-422 yes
Secret Manager /request TinyCloudWeb.signIn(): the web-sdk session key secret-manager src/lib/request/session.ts:238, :249 yes

No client produces a holder that fails the rule.

One behaviour change for hand-typed holders:

  • These paths pass the typed DID through unchecked: tc delegation create --to <did> (cli src/commands/delegation.ts:142, :167), node-sdk createDelegation, and a third-party OpenKey caller.
  • A malformed or did:web holder used to be stored, and that grant was unusable: since TC-1080, no such DID can sign an invocation the node verifies. It is now refused at intake with did_holder_unverifiable.
  • A legacy did:pkh:eth / did:pkh:tezos holder is now refused the same way. In the replica census, the live holder classes are only Ed25519 did:key, did:pkh:eip155, policy, and the 247 z2D grants, so no live grant uses these forms.

Renewal end-to-end suites

renewal_scheduler_e2e and renewal_stop_all_e2e are gated by #![cfg(feature = "renewal-test-clock")], so a plain --test '*' run compiles them to 0 tests.

CI runs them in .github/workflows/renewal-scheduler.yml, on every pull request, with --features renewal-test-clock against SQLite and PostgreSQL 16.

On this head, with the feature, both pass locally on SQLite:

  • scheduler_renews_over_http_then_lease_expires ok;
  • stop_all_pauses_renewals_until_resumed ok.

Tests

  • tinycloud-core unit tests (did_resolution::tests):
    • accepts_every_offline_key_type_and_account_namespace
    • refuses_unverifiable_did_keys_with_lengths_checked_before_decoding (a decode counter proves the oversized, z2D, P-384 and base64 cases are refused with 0 decodes)
    • refuses_unverifiable_did_jwks_with_length_checked_before_decoding
    • refuses_unverifiable_did_pkh_accounts
    • refuses_network_methods_and_exempts_only_policy_holders
    • refuses_small_order_ed25519_keys: identity, order-2 and order-4 keys as did:key, did:jwk and solana, as issuers and holders (review N1)
  • models::delegation::tests::new_grant_holder_must_be_verifiable: accepted and refused holders through check_capability_rules and process; a stored z2D-holder grant resubmitted through process answers Existing (review N3); a malformed issuer keeps its issuer code. routes::tests::key_delete::an_owner_delete_credential_is_not_a_delegation (existing) still gets key-delete-not-delegable for a credential whose aud is a URN.
  • tests/did_resolution_policy.rs:
    • every_offline_key_type_verifies_and_forgery_is_refused: key Ed/k1/P-256, jwk Ed/k1/P-256, pkh eip155/solana/bip122; checks a forged control and a revocation.
    • unverifiable_offline_identifiers_are_refused: z2D, tezos, legacy eth.
  • tinycloud-node tests/did_resolution_routes.rs:
    • malformed did:key issuer refused on /invoke (401), /delegate (401), /revoke (403);
    • delegate_refuses_unverifiable_holder_with_401;
    • the existing did:web refusals.
  • tests/did_resolution_app_startup.rs: the app starts with the removed setting set, and still refuses network methods.
  • removed_settings_tests: true, false and ["web"].
  • share_email_evidence::did_key_public_key_refuses_wrong_lengths_without_decoding, share_email_evidence::did_key_public_key_refuses_small_order_keys, data_plane::did_key_signer_is_the_ed25519_multicodec_only, verifier::eip191_issuer_must_be_an_eip155_pkh_before_recovery.

Release

Merges only on Naomi's GO naming the head SHA. It ships in the next node release through Amos.

test-ruling: TC-1500 tinycloud-node removes the did_resolution.network_methods tests with the removed setting (tests/did_resolution_app_startup.rs, tests/did_resolution_policy.rs, main.rs/lib.rs/runtime.rs/control.rs config tests; replaced by removed_settings_tests and check_verifiable tests), changes tests/did_resolution_routes.rs from did_method_disabled: to did_unverifiable: on the same three routes and statuses, and replaces non-DID placeholder holders with real Ed25519 did:keys; no assertion loosened (2026-11-21)

- Accept did:key Ed25519/secp256k1/P-256 (48/49-char ids, length checked before decoding),
  did:jwk with the same key types (<=256-char ids) and did:pkh eip155/solana/bip122.
- Refuse malformed or unverifiable issuers (did_unverifiable:) and new grants to such
  holders (did_holder_unverifiable:); did:tinycloud:policy:<64 hex> holders stay exempt.
- Holder check runs last in check_capability_rules and in save_owner_renewal_lease.
- Remove did_resolution.network_methods via REMOVED_SETTINGS; /info keeps it as false.
- did:key parsers accept only the Ed25519 multicodec; eip191 needs an eip155 issuer.

Supersedes #392. Details: TC-1500
… (TC-1500)

- Review N1: did:key, did:jwk, did:pkh:solana and the shared did_key_public_key parser
  refuse Ed25519 keys that do not decompress or are of small order (VerifyingKey::is_weak);
  ssi verifies with dalek's non-strict verify, so anyone could sign for such a key.
- Review N3: process_with answers Existing for a stored grant whose only refusal is its
  holder, as the single /delegate path already does.
- Review N2: CHANGELOG wording; the encryption-network and share-email parsers accepted
  the one-byte 0xed form before this change.

Details: TC-1500
…ile (TC-1500)

The m1-realdata e2e workspace builds tinycloud-auth by path; its separate lockfile
needs the new direct ed25519-dalek dependency or `cargo --locked` refuses it.

Details: TC-1500
…lockfile (TC-1500)

The third separately locked workspace that builds tinycloud-auth by path.
All three CI-checked lockfiles now resolve with --locked.

Details: TC-1500
@samgbafa
samgbafa merged commit 4a93060 into main Nov 21, 2026
34 checks passed
samgbafa pushed a commit that referenced this pull request Nov 21, 2026
Conflicts resolved:
- delegation::process_with keeps both Existing arms: a stored delegation
  refused as SessionRetired (TC-3443) or UnverifiableHolder (TC-1500)
  answers Existing on resubmit.
- delegation::save_owner_renewal_lease runs check_holder, then the retire
  check.
- CHANGELOG/README keep both entries; tinycloud.toml drops the removed
  did_resolution block and keeps session_retire.

Details: TC-3443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant