Skip to content

fix(security): keep stored secrets and feed tokens out of the clear - #9944

Merged
rubenvdlinde merged 6 commits into
mainfrom
sec-b2/secrets-at-rest
Nov 12, 2026
Merged

rubenvdlinde merged 6 commits into
mainfrom
sec-b2/secrets-at-rest

Conversation

@rubenvdlinde

@rubenvdlinde rubenvdlinde commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Secrets that were stored in clear are now encrypted at rest with Nextcloud's ICrypto, and calendar feed tokens are stored as hashes.

Webhook and consumer secrets

  • New Db\Support\SecretAtRest seals a value as orenc:v1: followed by the ICrypto::encrypt() output, and opens it again. Sealing is idempotent. A value stored before this change still reads as it is. A value that cannot be decrypted is logged and never used as its ciphertext: a consumer secret reads as absent, so an api key or HMAC key built on it is refused, and a webhook secret reads as a sealed marker, so the delivery is refused.
  • WebhookMapper seals the signing secret on insert and update and opens it when it maps a row, so WebhookService and the signing code receive the plain secret as before. WebhookRequestOptions::headers() refuses to build a delivery when the secret is still sealed, instead of sending it unsigned. MapperWiring passes the helper in.
  • ConsumerMapper does the same for the secret keys of authorizationConfiguration: apiKey, publicKey (the shared secret for HS* algorithms), secret, client_secret, password, private_key and token. Lookups such as findByApiKey, JWT verification and grant binding see plain values. The consumers API now returns the sealed form of those keys instead of the plain one.

Calendar feed tokens

  • CalendarFeedTokenService stores sha256(token) and resolve() looks the token up by that hash. The token and its URL are handed out once, in the mint response. listForUser() now returns token: null and url: null, because only the hash is kept.
  • A token minted without a positive ttlSeconds takes the default lifetime from app config openregister/calendar_feed_token_ttl_seconds. The default is 365 days, and 0 means no expiry, which an administrator can choose.

Repair step ProtectStoredSecrets (post-migration, idempotent)

  • Seals webhook secrets and consumer secret values still stored in clear.
  • Replaces each stored feed token by its SHA-256. This is the value the feed now looks up, so a URL someone already subscribed to keeps working. A token that never expired gets the default lifetime from now, so it keeps working until then.
  • Already sealed values (by prefix) and already hashed tokens (64 hex characters; minted tokens are 43) are left alone.

docs/Features/webhooks.md says how the secret is stored and what happens when it cannot be decrypted.

Notes for the reviewer

  • Case tokens are not part of this change.
  • Changing the Nextcloud instance secret makes the sealed values unreadable. That is the same trade-off as every ICrypto value in Nextcloud. Deliveries for an affected webhook stop until its secret is set again.

Tests

  • SecretsAtRestTest covers:
    • sealing is idempotent, opens to the same value and leaves plain values readable;
    • a value that cannot be opened reads as absent, never as its ciphertext, and is logged;
    • a consumer secret that cannot be opened is absent from the loaded configuration;
    • only the secret keys of a consumer configuration are sealed;
    • the webhook and consumer mappers write sealed values and read them back open;
    • a webhook with an unreadable secret is not sent;
    • the repair step seals and hashes only what is still in clear, gives a never-expiring token the default lifetime, and changes nothing on a second run.
  • CalendarFeedTokenServiceGuardsTest and CalendarFeedTokenServiceTest: the mint stores the hash and returns the token, the lookup goes by the hash, the default lifetime applies and is configurable (0 means no expiry), and the listing no longer carries the token or URL.
  • MapperRegistrarTest golden: WebhookMapper now also asks for ICrypto.

The new cases fail on the base.

What ran

  • phpunit tests/Unit/Service/Calendar (119 OK), tests/Unit/Repair (328 OK), SecretsAtRestTest, MapperRegistrarTest, the webhook service tests (including WebhookServiceTest 143 OK), ConsumersControllerTest, the AuthorizationService* and JWT tests, ConsumerMapperSourceApiKeyGoldenTest, TokenGrantTest and TokenResolverTest: all OK
  • Architecture guards: F08ContractBindingsEntryTest, HubClassesAreReachedThroughInterfacesTest, FactoryTablesMatchConstructorsTest, TestMethodsCanFailTest: all OK
  • php -l, phpcs and phpstan on the touched files: no new findings. Two property.onlyWritten findings on WebhookMapper lines this change does not touch are inherited.

AI-assisted: prepared with Claude Code (claude-opus-5-5); reviewed by a maintainer before merge.

Webhook signing secrets and the secret values of a consumer's
authorization configuration are stored encrypted with Nextcloud's
ICrypto and opened when read from the store; a secret that cannot be
decrypted is never used to send an unsigned delivery. Calendar feed
tokens are stored as their SHA-256 and looked up by it, and a token
minted without a lifetime takes a configurable default (365 days). The
ProtectStoredSecrets repair step encrypts existing secrets and hashes
existing tokens in place, giving never-expiring tokens the default
lifetime, so subscribed URLs keep working until then.

Assisted-by: ClaudeCode:claude-opus-5-5
A sealed secret that cannot be decrypted now reads as absent (logged)
instead of as its ciphertext, so a consumer api key or HMAC secret cannot
be matched with the stored value. A webhook secret that cannot be opened
reads as a sealed marker, so the delivery is refused, not sent unsigned.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
@rubenvdlinde
rubenvdlinde merged commit 49d0d0a into main Nov 12, 2026
14 of 20 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/openregister @ a00c6dc

Check PHP Vue Security License Tests
lint ✅
phpcs ❌
phpmd ❌
psalm ❌
phpstan ❌
phpmetrics ✅
eslint ❌
stylelint ✅
build ✅
check-specs ✅
test-l10n ❌
test-l10n-parity ❌
format ❌
check-schema-l10n ✅
test-newman-route-ratchet ✅
composer ✅ ✅ 169/169
npm ✅ ✅ 639/639
app:check-code ⏭️
info.xml ✅
REUSE ✅
lockfile sync ✅
PHPUnit ❌ 56571/56779 · 27 skipped (worst of 4 legs: PHP 8.3, NC stable32, pgsql; counts from 4 of 8 legs)
Newman ❌
Playwright ❌ 237/324 · 5 skipped · 164 did not run
Hydra gates ❌

Quality workflow — 2026-11-13 19:04 UTC

Download the full PDF report from the workflow artifacts.

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