NemoClaw icon indicating copy to clipboard operation
NemoClaw copied to clipboard

Credential availability is keyed by bare input id, so one channel's token marks another channel configured

Open udsy19 opened this issue 3 months ago • 0 comments

Investigation Summary

  • isCredentialAvailable() (src/lib/messaging/compiler/manifest-compiler.ts:396-406) accepts an unqualified input.inputId as an availability key, and botToken is the secret input id of telegram, discord, slack and wechat.
  • Four producers write that unqualified key while iterating more than one channel: src/lib/onboard/messaging-channel-setup.ts:439, src/lib/messaging/compiler/workflow-planner.ts:209,513,522, src/lib/messaging/persistence.ts:451,460, and src/lib/actions/sandbox/policy-channel.ts:1210.
  • With TELEGRAM_BOT_TOKEN set, WECHAT_ACCOUNT_ID resolvable and no WeChat token anywhere, MessagingWorkflowPlanner.buildPlan returns wechat as active: true, configured: true, includes wechat in agentRender, and never calls the wechat.ilinkLogin host-QR pairing hook.
  • Telegram, Discord and Slack use common.tokenPaste, which re-reads its own environment key, so their final state recovers. Their plan still records credentialAvailable: true for a channel with no credential, and credentialAvailabilityFromPlan() re-propagates that record into every later channels add.
  • No credential value crosses channels. Every read of a token value uses the channel's own providerEnvKey or sourceEnv, and the rendered artifacts carry only the placeholder openshell:resolve:env:WECHAT_BOT_TOKEN. The result is a channel that reports itself configured while it has no credential, not credential disclosure.

Description

What happened.

isCredentialAvailable() decides whether a channel's secret input is satisfied. It tries three lookup keys:

const keys = [input.inputId, `${manifest.id}.${input.inputId}`, input.sourceEnv].filter(
  (key): key is string => typeof key === "string" && key.length > 0,
);

return keys.some((key) => availability[key] === true);

The first key is the bare input id. Input ids are not unique across channels: botToken is declared by channels/telegram/manifest.ts:22, channels/discord/manifest.ts:17, channels/slack/manifest.ts:44 and channels/wechat/manifest.ts:19. Any producer that writes availability["botToken"] = true for one channel therefore satisfies the same input on the other three.

nemoclaw onboard is such a producer. buildCredentialAvailability() (src/lib/onboard/messaging-channel-setup.ts:427-446) iterates every selected channel and, for each secret input whose environment key holds a token, writes three keys:

availability[input.id] = true;                        // "botToken"
availability[`${manifest.id}.${input.id}`] = true;    // "telegram.botToken"
availability[input.envKey] = true;                    // "TELEGRAM_BOT_TOKEN"

Select Telegram and WeChat with only TELEGRAM_BOT_TOKEN present and the map contains botToken: true. When the compiler reaches the WeChat manifest, isCredentialAvailable(wechat, botToken) matches on that bare key.

WeChat shows the full effect because its enrollment hook is not a token-paste hook. shouldRunEnrollmentHook() (manifest-compiler.ts:443-459) returns true unconditionally only for a *.tokenPaste handler. For wechat-host-qr it checks the hook's required outputs, botToken and accountId. Once botToken looks available and accountId resolves from WECHAT_ACCOUNT_ID, both required outputs look satisfied and the hook is skipped. The host-QR scan is the channel's only enrollment path, so the operator never sees it.

What I expected.

Credential availability is a per-channel fact. A Telegram token must not satisfy a WeChat, Discord or Slack secret. WeChat with no token should stay active: false, configured: false, disabled: true, and its host-QR pairing hook should run.

Scope of the impact.

Channel pair Effect today
wechat alongside telegram, discord or slack wechat is planned active: true, configured: true, its render entries are emitted, and wechat.ilinkLogin never runs
telegram, discord, slack alongside each other the enroll hook re-reads its own environment key, so the final active state is correct, but the plan records credentialAvailable: true for a channel with no credential

The channels add path has the same shape. buildChannelAddPlanFromSandboxEntry() (workflow-planner.ts:74-79) merges credentialAvailabilityFromPlan(existingPlan), which folds every already-configured channel's bare input ids into the map for the channel being added.

Why an operator reaches this.

Two or more channels selected in one nemoclaw onboard run, with at least one channel's token already in the environment, is an ordinary setup. Nothing warns the operator, and the failure is silent: the sandbox is built and rendered as if WeChat were paired.

This is a correctness and state-integrity defect, not a credential-disclosure defect. I traced every consumer of plan.credentialBindings (credential-binding-engine.ts:23-28, checkpoint-replay.ts:143-149, messaging-credentials.ts:65-69, onboard/machine/handlers/sandbox-messaging.ts:110-132,542-560) and each one reads the token value through the channel's own providerEnvKey. credentialHash for the falsely available channel resolves to undefined, not another channel's hash, and the WeChat render lines carry the placeholder string rather than a value.

Reproduction Steps

I reproduced this at MessagingWorkflowPlanner.buildPlan, which is the call nemoclaw onboard makes (src/lib/onboard/messaging-channel-setup.ts:362-386). The availability map below is exactly what buildCredentialAvailability() emits for a Telegram-only token.

  1. Check out 7d516f2ed and save the probe below as src/lib/messaging/compiler/availability-probe.test.ts.
import { describe, expect, it } from "vitest";
import {
  createBuiltInChannelManifestRegistry,
  createBuiltInRenderTemplateResolver,
} from "../channels";
import { createBuiltInMessagingHookRegistry } from "../hooks";
import { MessagingWorkflowPlanner } from "./workflow-planner";

describe("availability probe", () => {
  it("reports the WeChat plan for a Telegram-only token", async () => {
    const hostQr: string[] = [];
    const planner = new MessagingWorkflowPlanner(
      createBuiltInChannelManifestRegistry(),
      createBuiltInMessagingHookRegistry({
        common: {
          env: {},
          getCredential: (key) => (key === "TELEGRAM_BOT_TOKEN" ? "123456:telegram" : null),
          saveCredential: () => {},
          prompt: async () => "unused",
          log: () => {},
        },
        wechat: {
          ilinkLogin: {
            env: {},
            saveCredential: () => {},
            log: (message: string) => hostQr.push(message.trim()),
            runLogin: async () => {
              hostQr.push("runLogin() invoked");
              return {
                kind: "ok",
                credentials: { token: "from-qr", accountId: "acct-from-qr" },
              } as const;
            },
          },
          seedOpenClawAccount: { now: () => "2026-01-01T00:00:00.000Z" },
        },
      }),
      createBuiltInRenderTemplateResolver(),
    );

    process.env.WECHAT_ACCOUNT_ID = "acct-1";
    delete process.env.WECHAT_BOT_TOKEN;

    const plan = await planner.buildPlan({
      sandboxName: "demo",
      agent: "openclaw",
      workflow: "onboard",
      isInteractive: true,
      configuredChannels: ["telegram", "wechat"],
      // Exactly what buildCredentialAvailability() emits for a Telegram-only token.
      credentialAvailability: {
        botToken: true,
        "telegram.botToken": true,
        TELEGRAM_BOT_TOKEN: true,
      },
    });

    const wechat = plan.channels.find((channel) => channel.channelId === "wechat");
    console.log(
      JSON.stringify(
        {
          hostQrHookActivity: hostQr,
          wechatChannel: {
            active: wechat?.active,
            configured: wechat?.configured,
            disabled: wechat?.disabled,
          },
          wechatBinding: plan.credentialBindings.find((b) => b.channelId === "wechat"),
          renderChannels: [...new Set(plan.agentRender.map((entry) => entry.channelId))],
        },
        null,
        2,
      ),
    );
    expect(true).toBe(true);
  });
});
  1. Run it:
npx vitest run --project cli \
  src/lib/messaging/compiler/availability-probe.test.ts \
  --reporter=verbose --disable-console-intercept
  1. Repeat with the bare botToken: true entry removed from credentialAvailability to get the control.

Observed on 7d516f2ed with botToken: true present:

{
  "hostQrHookActivity": [],
  "wechatChannel": { "active": true, "configured": true, "disabled": false },
  "wechatBinding": {
    "channelId": "wechat",
    "credentialId": "wechatBotToken",
    "sourceInput": "botToken",
    "providerName": "demo-wechat-bridge",
    "providerEnvKey": "WECHAT_BOT_TOKEN",
    "placeholder": "openshell:resolve:env:WECHAT_BOT_TOKEN",
    "credentialAvailable": true
  },
  "renderChannels": ["telegram", "wechat"]
}

hostQrHookActivity is empty: wechat.ilinkLogin was never entered.

Control on the same commit, with only telegram.botToken and TELEGRAM_BOT_TOKEN:

{
  "hostQrHookActivity": ["runLogin() invoked", "✓ wechat token saved"],
  "wechatChannel": { "active": true, "configured": true, "disabled": false },
  "wechatBinding": { "credentialAvailable": true },
  "renderChannels": ["telegram", "wechat"]
}

The control runs the host-QR scan and gets its token from the scan. The leak case reaches the same active: true state with no WeChat token in existence.

Running both cases with isInteractive: false separates them further:

isInteractive: false botToken: true present control
host-QR hook activity none Skipped wechat (host QR login requires interactive mode)
wechat channel active: true, configured: true, disabled: false active: false, configured: false, disabled: true
wechat botToken input credentialAvailable: true credentialAvailable: false
wechat credential binding credentialAvailable: true credentialAvailable: false
plan.agentRender channels ["telegram", "wechat"] ["telegram"]

Substituting configuredChannels: ["telegram", "discord"] with no DISCORD_BOT_TOKEN gives the token-paste case. Non-interactive, discord ends active: false, configured: false, disabled: true, which is correct, but its recorded input and binding both carry credentialAvailable: true.

Environment

  • OS: macOS 26.5.1
  • Hardware: Apple silicon workstation
  • Node.js: v26.7.0
  • Docker: not required for this reproduction
  • NemoClaw: source checkout at 7d516f2ed (package.json version 0.1.0)

Debug Output

nemoclaw debug is not applicable. The defect is in the messaging manifest compiler and reproduces from a source checkout through the Vitest cli project, with no sandbox, gateway or agent runtime involved. The probe output above is the evidence.

Logs

$ npx vitest run --project cli src/lib/messaging/compiler/availability-probe.test.ts \
    --reporter=verbose --disable-console-intercept

 RUN  v4.1.9

LEAK interactive=false: {
  "hostQrHookActivity": [],
  "wechatChannel": { "active": true, "configured": true, "disabled": false },
  "wechatBotTokenInput": {
    "channelId": "wechat",
    "inputId": "botToken",
    "kind": "secret",
    "required": true,
    "sourceEnv": "WECHAT_BOT_TOKEN",
    "credentialAvailable": true
  },
  "renderChannels": ["telegram", "wechat"]
}
CONTROL interactive=false: {
  "hostQrHookActivity": ["log: Skipped wechat (host QR login requires interactive mode)"],
  "wechatChannel": { "active": false, "configured": false, "disabled": true },
  "wechatBotTokenInput": {
    "channelId": "wechat",
    "inputId": "botToken",
    "kind": "secret",
    "required": true,
    "sourceEnv": "WECHAT_BOT_TOKEN",
    "credentialAvailable": false
  },
  "renderChannels": ["telegram"]
}

Checklist

  • [x] I confirmed this bug is reproducible
  • [x] I searched existing issues and this is not a duplicate

udsy19 avatar Aug 18 '26 06:08 udsy19