Skip to content

fix(dsh): apply the shared prompt-privacy rule to explicit writes - #2643

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/dsh-explicit-write-privacy
Nov 16, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/dsh-explicit-write-privacy

Conversation

@Fengzdadi

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

Part of #2250. Follows #2625, which applied the shared prompt-privacy rule to DSH's automatic path and left explicit writes as a follow-up.

Rationale for this change

DSH rejects an explicit write whose content looks like a secret, with secret_rejected, before approval or dispatch. It decided this with three substring markers: sk-, api_key, and BEGIN PRIVATE. The markers fail in both directions:

  • Ordinary text is rejected. "risk-based", "task-specific", "disk-space", and "task-runner" all contain sk-. A Memory, Source, Handoff, task outcome, or Scope summary that uses one of these words cannot be written.
  • Common credentials pass. password= and access_token= assignments, Authorization and Cookie headers, bearer and GitHub tokens, and the configured Server token are sent and stored.

DSH's automatic path already follows the rule from "Automatic prompt privacy" in the integrations guide (tests/fixtures/automatic_prompt_privacy.json), so one DSH session applied two different definitions of a secret.

What changes are included in this PR?

Behavior

Explicit write content Before After
Ordinary words containing sk- or api_key (task-runner, risk-based) Rejected with secret_rejected Sent
Credentials the shared rule recognizes (assignments, Authorization/Cookie headers, bearer and provider tokens, private keys) Rejected only if they contained a marker Rejected with secret_rejected
The configured Server token Sent Rejected with secret_rejected
Prose shaped like an assignment, such as password: rotate it monthly Sent Rejected with secret_rejected

The operations and fields that are checked are unchanged: Memory, Source, and working-note writes; Work Contract, task outcome, candidate, and Scope fields; and Handoff content, including nested state and Drafts. A rejected write still sends nothing.

Code

  • src/secrets.ts: hasSecretContent uses containsSecret, the same function as automatic capture, and takes the configured Authorization value. The substring markers are removed; nothing else used them.
  • src/mcp.ts, src/index.ts: the MCP pre-execute policy receives the configured Authorization value.
  • src/invoke.ts, src/client.ts: slash-command writes read it from the client, whose authorization field becomes public read-only.
  • lib/index.js is rebuilt. The DSH pet bundle and the Cindy worker include client.ts and secrets.ts but not hasSecretContent; their builds do not change.

Tests

  • New tests/explicit-write-privacy.spec.ts reads automatic_prompt_privacy.json and adds ordinary prose with "risk-based", "task-specific", and "disk-space". It covers two paths:

    • MCP policy: every case through remember_memory, capture_content_source, handoff_current_work (nested state), finalize_handoff (nested Draft), record_task_outcome, and create_scope;
    • Slash-command path: every case through invokeOperation.

    Sensitive cases must be rejected with no request, no Scope resolution, and no synthetic credential in the result. Other cases must not be rejected.

  • With the old markers restored, 112 of the 175 new cases fail. Without passing the Authorization value, the Server-token cases fail.

  • tests/invoke.spec.ts uses a provider-shaped token instead of sk-secret, which is too short for the shared rule.

  • The existing rejection tables in tests/mcp.spec.ts and the runtime fixture already use api_key=… assignments and private-key headers, so they pass unchanged.

Docs

  • docs/{en,zh}/docs/integrations/dsh.md and the plugin README describe the rule, the Server token, and the trade-off below, and link to the policy section.

Trade-off

  • The shared rule treats password: … and similar assignments as credentials wherever they appear, including prose.
  • Automatic capture skips such a prompt silently. An explicit write rejects it with secret_rejected, and the user rephrases. A false rejection is visible and recoverable, while a stored credential is not.
  • Rejection, not redaction, is unchanged from before.

Not included

  • The Handoff delivery helpers under src/handoff/ call hasSecretContent without the Server token. No runtime path reaches them today; MCP Handoff tools are checked by the MCP policy, which has the token.

Overlap with the prompt-privacy refactor

  • The PR that generates the TypeScript prompt-privacy copies moves containsSecret out of DSH's src/secrets.ts into a generated src/prompt-privacy.ts. Whichever of the two merges second adds import { containsSecret } from './prompt-privacy.ts' to src/secrets.ts, rebuilds the DSH bundle, and reruns make js-test and make cindy-test.

Are there any user-facing changes?

Yes, for DSH explicit writes:

  • Writes with ordinary words such as "task-runner" or "risk-based" are no longer rejected.
  • Writes containing a recognized credential or the configured Server token are rejected.
  • Assignment-shaped prose such as password: rotate it monthly is rejected.

The error code and message are unchanged. No API or persisted format changes.

How was this change tested?

  • make js-test: 795 unit tests, the e2e tests, the DSH pet adapter tests, and freshness of the DSH and DSH pet bundles.

  • make cindy-test: 20 tests, worker.cjs freshness, and packaging.

  • make check, and git diff --check.

  • uv run pytest tests/test_automatic_prompt_privacy.py tests/test_integration_manifest.py tests/test_dsh*.py.

  • No real DSH host was run. make dsh-runtime-test downloads the pinned host and was not run locally. Its secret-write test uses api_key=…, which the shared rule rejects.

  • Self-review against REVIEW.md, plus an independent review pass, found nothing blocking. Fixed: an English docs sentence about the MCP catalog had lost its subject.

    Confirmed:

    • both explicit-write entry points pass the token;
    • making authorization public changes TypeScript visibility only; the emitted JavaScript is the same and nothing serializes the client;
    • payload walking matches the old code;
    • the committed lib/ matches a rebuild;
    • every existing rejection payload is still rejected.

    Left as design notes:

    • Keys are not inspected. As before, only string values are checked. A structured value such as metadata: {password: "x"} passes, while the same text inside one string is rejected.
    • Some old rejections now pass. Inputs the markers rejected but the shared rule does not recognize now pass: an sk- value with fewer than eight characters after the prefix, or my api_key is XYZ without an assignment.
    • Deny reason. The secret_rejected reason does not name the field or the matched shape. A more specific reason would help a model rephrase; that is a separate change.
    • Short Server token. The configured Server token is matched as a substring. A very short token, such as dev on a local development Server, makes every explicit write that contains it (development, device) fail with secret_rejected, where automatic capture would only skip the turn.
      • This is the same rule that automatic capture applies, and that Pi, OpenCode, and OpenClaw apply to their configured token.
      • The configuration wizard generates the token from 32 random bytes (secrets.token_urlsafe(32)); a short token comes only from manual configuration.
      • A minimum token length would change the shared fixture and every host together, so it is outside this PR.

AI usage statement

Claude Code (Claude Opus 5.5) wrote the change, the tests, and this description, and ran the checks above.

Explicit writes from the MCP tools and slash commands rejected content
with substring markers ('sk-', 'api_key', 'BEGIN PRIVATE'). Ordinary text
such as "risk-based", "task-specific" or "disk-space" was rejected with
secret_rejected, while password and token assignments, Authorization
headers, bearer and GitHub tokens, and the configured Server token passed.

Explicit writes now use the rule that automatic capture already follows,
from "Automatic prompt privacy" in the integrations guide
(tests/fixtures/automatic_prompt_privacy.json), including the configured
Server token. A write whose content contains a recognized credential is
still rejected, not redacted.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed ef1cd68. No blocking findings. Reusing the established prompt-privacy rule fixes ordinary-word false rejections and adds recognized-credential/configured-token checks before explicit write dispatch. No new database tables, endpoints, commands, configuration keys, persisted formats, or package exports. The internal client field and helper parameters do not expand the published package API.

The installed bundle was also exercised in real DSH with a local PowerContext Server and a scripted model: ordinary prose reached the existing approval gate, while password, configured-token, and nested Handoff token inputs produced secret_rejected with no MCP write dispatch. This does not claim live-provider acceptance.

Possible capability gap (non-blocking): Pi and OpenCode explicit-write guards still call containsSecret(value) without the configured authorization (integrations/pi/plugins/powercontext/src/invoke.ts and integrations/opencode/plugins/powercontext/src/invoke.ts). Consider a follow-up under #2250 for opaque configured-token matching there; this is pre-existing and does not block this DSH fix.

@hidb4ai
hidb4ai merged commit e25b68a into oceanbase:master Nov 16, 2026
42 checks passed
@hidb4ai hidb4ai added the 1.6.0 v1.6.0 release tracking label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants