Skip to content

fix(registry,integrations): instance-owned API base, owner-only webhook URL, admin-only moltbot routes - #2187

Merged
lilyshen0722 merged 3 commits into
mainfrom
fix/integration-config-write-authz
Oct 15, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
fix/integration-config-write-authz

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Three writes now require the authority they imply. Each one decides where the backend sends requests or who can act as an agent.

1. X / Instagram config.apiBase is instance-owned

  • apiBase joins SERVER_OWNED_CONFIG_KEYS (backend/utils/serverOwnedConfigKeys.ts), so POST/PATCH /api/integrations strip it from the body. This is the same mechanism and comment style as signingSecret / secretToken, which are also instance-owned.

  • xProvider and instagramProvider read only X_API_BASE_URL / INSTAGRAM_GRAPH_API_BASE, or the official default (https://api.x.com/2, https://graph.facebook.com/v19.0). A value already stored on a row is no longer read.

  • Legitimate setters, checked: only two code paths ever wrote apiBase, and both are server-side.

    • The admin global-integrations route (routes/admin/globalIntegrations.ts, admin-only).
    • scripts/setup-global-social-feeds.js.

    Both wrote exactly the env-or-default value the providers now compute themselves, so they stop storing a copy nothing reads. No test, frontend code or manifest sets it. Self-hosters keep the env vars. The schema field stays, as it did for the other instance-owned keys.

2. Setting config.runtime.webhookUrl takes the #2165 sole-installer rule

A push webhook's replies (outcome: 'posted') are posted as the agent identity, so the URL is a credential for that identity. This reuses services/runtimeIdentityOwnership.ts and does not re-derive the rule. Admins are exempt.

  • PATCH /api/registry/pods/:podId/agents/:name: this route already refused non-installer members (fix(registry): changing an installed agent requires its installer or an instance admin (TASK-055) #1746). Now, when the body sets or changes the webhook URL, the caller must also pass ownsRuntimeIdentity. Resending the stored value or clearing it is not gated.
  • POST /api/registry/install: supplying a webhook URL requires that no other user holds an active installation of the identity. That is the rule's negative clause, the only part that can be checked before the caller's installation exists. It goes through a new willSolelyInstallRuntimeIdentity, which shares one query with ownsRuntimeIdentity; ownsRuntimeIdentity's behaviour is unchanged. The check runs before any write. Installing without a webhook URL is unaffected.
  • A refusal is a 403 with the rule's failure code (another_installer, owner_installation_missing, unknown_installer) and a webhook-specific message.

I enumerated the other writers of an installation's config: reprovision and provision write runtime server-side, and the native-routing sibling inheritance in agentEventService is in-memory only. None takes a body's webhook URL.

3. /api/providers/moltbot is admin-only

Every route on this router acts through the instance's single moltbot provider. The first /connect fixes that provider's gateway, and the API token it uses to call Commonly. Operating it is now admin-only: router.use(moltbotProviderLimit, auth, adminAuth) replaces the per-route auth. Nothing in the frontend, CLI, MCP package or gateway extension calls these routes.

The limiter runs first because adminAuth reads the caller's User row on every request. It uses platformIpRateLimit with 60 calls per 15 minutes per IP, the same budget as the admin global-integrations writes. CodeQL flagged the router-level gate without it (js/missing-rate-limiting). The seven moltbot rows leave routeRateLimitGuard.baseline.json, which only shrinks. Removing the limiter turns the guard's "new route carries a limiter" test red.

The branch merges origin/main to pick up #2185. Its only conflict was that same baseline file: main's version is kept, minus the seven moltbot rows.

Tests

Run on Node 22.

  • registry.webhookUrl-ownership.test.js, new, 10 tests. The real ownership rule runs against an in-memory installation set.
    • PATCH: sole installer allowed; this row's installer refused on a shared identity with nothing saved; a non-installer member refused (installer_only); admin allowed; resending the stored URL not gated.
    • Install: first installer allowed; a caller who is already the sole installer allowed; a member refused while another user holds the identity, with nothing written; the same member allowed without a webhook URL (control); admin allowed.
  • providers.moltbot.adminOnly.test.js, new, 9 tests. Uses the real adminAuth.
    • Each of the 7 routes returns 403 for a non-admin and never reaches the provider.
    • An admin can connect, with the provider configured from the request, and can reach a pod-scoped route.
  • socialProviderApiBase.test.js, new, 3 tests. A row carrying apiBase still requests the official API; the env var still applies.
  • integrations.serverOwnedConfig.test.js gains an apiBase arm, with a non-server-owned control key in the same write.
  • Regression: every unit suite that loads a changed module (55 suites, 460 tests) and the install-related service suites (12 suites, 216 tests) pass, including the fix(registry): only an identity's sole installer, or an admin, can mint, rotate or revoke its runtime token #2165 ownership suite and the daemon adoption suites.

Mutation check. Ten arms, each landing once at a named line. All go red, and the suite count (6) and test total (44) stay constant in every arm:

Mutation Tests failing
apiBase dropped from the server-owned list 1
X provider reads the row apiBase 2
Instagram provider reads the row apiBase 1
Install webhook check removed 1
Install admin exemption removed 1
PATCH webhook check removed 1
PATCH gates an unchanged URL 1
PATCH admin exemption removed 1
Ownership negative clause always passes (also reddens the #2165 and daemon adoption arms) 7
Moltbot admin gate removed 7

Lint: 0 errors on the 8 changed .ts files. Every warning is on an unchanged line. tsc --noEmit -p tsconfig.build.json is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

…ok URL, admin-only moltbot routes

Three writes that decide where the backend sends requests, or who can act
as an agent, now require the right authority.

- X / Instagram `config.apiBase` is server-owned. It joins
  SERVER_OWNED_CONFIG_KEYS, so POST/PATCH /api/integrations strip it, and the
  providers read only X_API_BASE_URL / INSTAGRAM_GRAPH_API_BASE or the
  official default. The two server-side writers (the admin global-integrations
  route and setup-global-social-feeds) stop storing a copy nothing reads.
- `config.runtime.webhookUrl` takes the sole-installer rule from #2165,
  admins exempt. A webhook's replies are posted as the agent identity.
  - PATCH /pods/:podId/agents/:name applies ownsRuntimeIdentity when the
    body sets or changes the URL. Resending the stored value or clearing it
    does not.
  - POST /install applies the rule's negative clause, which is all that can
    be checked before the caller's installation exists. It does this through
    a new willSolelyInstallRuntimeIdentity in the same module, sharing the
    query with ownsRuntimeIdentity.
- /api/providers/moltbot is admin-only. Every route on it acts through the
  instance's single provider, which the first /connect configures.

Tests: registry.webhookUrl-ownership (10), providers.moltbot.adminOnly (9),
socialProviderApiBase (3), and a server-owned apiBase arm. Each covers
owner/admin allowed, other caller refused, nothing written on refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
lilyshen0722 and others added 2 commits October 14, 2026 16:30
adminAuth reads the caller's User row on every request, so the router-level
gate now runs a limiter first: platformIpRateLimit, 60 calls per 15 minutes
per IP, the same budget as the admin global-integrations writes. The seven
moltbot rows leave routeRateLimitGuard.baseline.json, which only shrinks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
Picks up #2185. The only conflict was routeRateLimitGuard.baseline.json:
main's version is kept, minus the seven moltbot rows this branch retires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 4f8d2ec (eng lead, code and security gate).

Checked:

  • apiBase is server-owned: apiBase is in SERVER_OWNED_CONFIG_KEYS. The X and Instagram providers read only X_API_BASE_URL / INSTAGRAM_GRAPH_API_BASE or the official default, never the row. The admin global-integrations route and setup-global-social-feeds.js no longer write it.
  • webhookUrl on PATCH (registry/agent-config.ts): setting or changing config.runtime.webhookUrl requires ownsRuntimeIdentity (the #2165 sole-installer rule), admins exempt. Clearing it or resending the stored value is unaffected.
  • webhookUrl on install (registry/install.ts): willSolelyInstallRuntimeIdentity checks the negative clause only, since the caller's installation doesn't exist yet. It runs before any write, admins exempt. Both use the shared otherInstallerFailure, so the ownership rule keeps one source.
  • No other writer: I searched every backend route, controller and service for writers of webhookUrl. provision.ts and reprovision.ts keep the stored runtime config and add server values, never a request-supplied URL. App.webhookUrl delivery is #2188's scope.
  • Moltbot router: the whole /api/providers/moltbot router is platformIpRateLimit → auth → adminAuth, so /context, /search and /write no longer take an arbitrary podId from any user. Nothing in frontend, CLI, MCP or the gateway source calls this router.
  • CI: all checks are green (the cancelled version-guard run was superseded by a passing one), and no CodeQL alerts are open on the PR's merge ref.
  • Tests at this head: 40 backend suites touching ownership, install, agent-config, the providers, server-owned keys, global integrations and the rate-limit guard pass (405 tests), including the PR's 4 new suites. Lint shows 0 errors on the 8 changed source files.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 50383bf Oct 15, 2026
23 of 24 checks passed
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.

2 participants