Skip to content

feat(server): accounts.resolve security presets (#1339) - #1352

Merged
bokelley merged 1 commit into
mainfrom
bokelley/resolve-presets
May 2, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/resolve-presets

Conversation

@bokelley

@bokelley bokelley commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1339. Standardizes the post-resolve authorization pattern multi-tenant adopters reach for — "the inner resolver found the account, but is the calling principal authorized for it?" — instead of every adopter rolling their own.

Three exports composing with composeMethod over accounts.resolve:

  • requireAccountMatch(predicate, options?) — general post-resolve guard
  • requireAdvertiserMatch(getRoster, options?) — gate on account.advertiser ∈ roster
  • requireOrgScope(getAccountOrg, getCtxOrg, options?) — gate on (account org === ctx org)
import { composeMethod, requireAdvertiserMatch } from '@adcp/sdk/server';

accounts: {
  resolve: composeMethod(
    baseResolve,
    requireAdvertiserMatch(async (ctx) => tenantRoster.for(ctx?.agent))
  ),
}

Deny semantics

Default onDeny: 'null' returns null from the wrapped resolver — buyer sees ACCOUNT_NOT_FOUND, indistinguishable from a genuinely unknown account. Avoids principal enumeration; matches the canonical accounts.resolve failure shape documented on AccountStore.resolve.

Opt-in onDeny: 'throw' surfaces PermissionDeniedError to the buyer. Use only when the principal is already known to be allowed to know the account exists.

The null-from-inner case short-circuits — predicates / roster getters do not run when the inner resolver couldn't find the account.

Test plan

  • 17 new unit tests in test/server-decisioning-resolve-presets.test.js covering: pass/deny semantics, null short-circuit, async predicates/rosters, ctx threading, throw mode with action label propagation, and a realistic composition fixture
  • Existing composeMethod tests still pass (test/server-decisioning-compose.test.js, 10 tests)
  • npm run build:lib clean
  • npm run format:check clean
  • Changeset added (minor — additive surface)

Source

Item 1 in the doha-v20 SDK asks drafted while migrating an adapter against current SDK HEAD. The companion docs/test-patterns issue (#1345) will reference these once they ship.

🤖 Generated with Claude Code

@gitguardian

gitguardian Bot commented May 2, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Standardize the post-resolve authorization pattern multi-tenant adopters
reach for — "the inner resolver found the account, but is the calling
principal authorized for it?" — instead of every adopter rolling their
own.

Three exports composing with composeMethod over accounts.resolve:
- requireAccountMatch — general post-resolve guard
- requireAdvertiserMatch — gate on account.advertiser ∈ roster
- requireOrgScope — gate on (account org === ctx org)

Default deny returns null (indistinguishable from "not found", avoids
principal enumeration); opt-in onDeny: 'throw' surfaces PermissionDenied.

Closes #1339.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley force-pushed the bokelley/resolve-presets branch from 535f557 to 13ba434 Compare May 2, 2026 20:45
@bokelley
bokelley merged commit a45bec6 into main May 2, 2026
10 checks passed
@bokelley
bokelley deleted the bokelley/resolve-presets branch May 2, 2026 21:14
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.

feat(server): composeMethod presets for accounts.resolve guards (requireAdvertiserMatch / requireOrgScope)

1 participant