Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor(creds): remove getPlaintextCred tool to prevent plaintext credential exposure (#14998)

Arvin Xu71dd287001c6
diff --git a/packages/builtin-tool-creds/src/ExecutionRuntime/index.ts b/packages/builtin-tool-creds/src/ExecutionRuntime/index.ts
index 83766176792..63d5ff47296 100644
--- a/packages/builtin-tool-creds/src/ExecutionRuntime/index.ts
+++ b/packages/builtin-tool-creds/src/ExecutionRuntime/index.ts
@@ -3,7 +3,6 @@ import type { BuiltinServerRuntimeOutput } from '@lobechat/types';
import type {
ConnectKlavisServiceParams,
- GetPlaintextCredParams,
InitiateOAuthConnectParams,
InjectCredsToSandboxParams,
SaveCredsParams,
@@ -15,21 +14,6 @@ import { LOBEHUB_OAUTH_PROVIDER_LIST } from '../types';
* Abstracted to allow different implementations (e.g., MarketService-based)
*/
export interface ICredsService {
- /**
- * Get plaintext credential by key
- */
- getByKey: (
- key: string,
- options?: { decrypt?: boolean },
- ) => Promise<{
- fileName?: string;
- fileUrl?: string;
- name?: string;
- plaintext?: Record<string, string>;
- type: string;
- values?: Record<string, string>;
- }>;
-
/**
* Get OAuth authorization URL
*/
@@ -208,79 +192,6 @@ export class CredsExecutionRuntime {
}
}
- /**
- * Get plaintext credential value by key
- */
- async getPlaintextCred(args: GetPlaintextCredParams): Promise<BuiltinServerRuntimeOutput> {
- try {
- const result = await this.credsService.getByKey(args.key, { decrypt: true });
-
- const credType = result.type;
- const credName = result.name || args.key;
-
- // Handle file type credentials
- if (credType === 'file') {
- const fileUrl = result.fileUrl;
- const fileName = result.fileName;
-
- if (!fileUrl) {
- return {
- content: `File credential "${credName}" (key: ${args.key}) found but file URL is not available.`,
- error: {
- message: 'File URL not available',
- type: 'FileUrlNotAvailable',
- },
- success: false,
- };
- }
-
- return {
- content: `Successfully retrieved file credential "${credName}" (key: ${args.key}). File: ${fileName || 'unknown'}. The file download URL is available in the state.`,
- state: {
- fileName,
- fileUrl,
- key: args.key,
- name: credName,
- type: 'file',
- },
- success: true,
- };
- }
-
- // Handle KV types (kv-env, kv-header, oauth)
- const values = result.values || result.plaintext || {};
- const valueKeys = Object.keys(values);
-
- // Return content with masked values for security, but include actual values in state
- const maskedValues = valueKeys.map((k) => `${k}: ****`).join(', ');
-
- return {
- content: `Successfully retrieved credential "${credName}" (key: ${args.key}). Contains ${valueKeys.length} value(s): ${maskedValues}. The actual values are available in the state for use.`,
- state: {
- key: args.key,
- name: credName,
- type: credType,
- values,
- },
- success: true,
- };
- } catch (error) {
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
- const isNotFound = errorMessage.includes('not found') || errorMessage.includes('NOT_FOUND');
-
- return {
- content: isNotFound
- ? `Credential not found: ${args.key}. Please check if the credential exists in Settings > Credentials.`
- : `Failed to get credential: ${errorMessage}`,
- error: {
- message: errorMessage,
- type: isNotFound ? 'CredentialNotFound' : 'GetCredentialFailed',
- },
- success: false,
- };
- }
- }
-
/**
* Inject credentials to sandbox environment
*/
diff --git a/packages/builtin-tool-creds/src/executor/index.ts b/packages/builtin-tool-creds/src/executor/index.ts
index 83e33037497..aa2e8fe0ba1 100644
--- a/packages/builtin-tool-creds/src/executor/index.ts
+++ b/packages/builtin-tool-creds/src/executor/index.ts
@@ -13,7 +13,6 @@ import { userProfileSelectors } from '@/store/user/slices/auth/selectors';
import { CredsIdentifier } from '../manifest';
import type {
ConnectKlavisServiceParams,
- GetPlaintextCredParams,
InitiateOAuthConnectParams,
InjectCredsToSandboxParams,
SaveCredsParams,
@@ -395,98 +394,6 @@ class CredsExecutor extends BaseExecutor<typeof CredsApiName> {
});
};
- /**
- * Get plaintext credential value by key
- */
- getPlaintextCred = async (
- params: GetPlaintextCredParams,
- _ctx?: BuiltinToolContext,
- ): Promise<BuiltinToolResult> => {
- try {
- log('[CredsExecutor] getPlaintextCred - key:', params.key);
-
- // Get the decrypted credential directly by key
- const result = await lambdaClient.market.creds.getByKey.query({
- decrypt: true,
- key: params.key,
- });
-
- const credType = (result as any).type;
- const credName = (result as any).name || params.key;
-
- log('[CredsExecutor] getPlaintextCred - type:', credType);
-
- // Handle file type credentials
- if (credType === 'file') {
- const fileUrl = (result as any).fileUrl;
- const fileName = (result as any).fileName;
-
- log('[CredsExecutor] getPlaintextCred - fileUrl:', fileUrl ? 'present' : 'missing');
-
- if (!fileUrl) {
- return {
- content: `File credential "${credName}" (key: ${params.key}) found but file URL is not available.`,
- error: {
- message: 'File URL not available',
- type: 'FileUrlNotAvailable',
- },
- success: false,
- };
- }
-
- return {
- content: `Successfully retrieved file credential "${credName}" (key: ${params.key}). File: ${fileName || 'unknown'}. The file download URL is available in the state.`,
- state: {
- fileName,
- fileUrl,
- key: params.key,
- name: credName,
- type: 'file',
- },
- success: true,
- };
- }
-
- // Handle KV types (kv-env, kv-header, oauth)
- // Market API returns 'plaintext' field, SDK might transform to 'values'
- const values = (result as any).values || (result as any).plaintext || {};
- const valueKeys = Object.keys(values);
-
- log('[CredsExecutor] getPlaintextCred - result keys:', valueKeys);
-
- // Return content with masked values for security, but include actual values in state
- const maskedValues = valueKeys.map((k) => `${k}: ****`).join(', ');
-
- return {
- content: `Successfully retrieved credential "${credName}" (key: ${params.key}). Contains ${valueKeys.length} value(s): ${maskedValues}. The actual values are available in the state for use.`,
- state: {
- key: params.key,
- name: credName,
- type: credType,
- values,
- },
- success: true,
- };
- } catch (error) {
- log('[CredsExecutor] getPlaintextCred - error:', error);
-
- // Check if it's a NOT_FOUND error
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
- const isNotFound = errorMessage.includes('not found') || errorMessage.includes('NOT_FOUND');
-
- return {
- content: isNotFound
- ? `Credential not found: ${params.key}. Please check if the credential exists in Settings > Credentials.`
- : `Failed to get credential: ${errorMessage}`,
- error: {
- message: errorMessage,
- type: isNotFound ? 'CredentialNotFound' : 'GetCredentialFailed',
- },
- success: false,
- };
- }
- };
-
/**
* Inject credentials to sandbox environment
* Calls the SDK inject API to get decrypted credentials for sandbox injection.
diff --git a/packages/builtin-tool-creds/src/index.ts b/packages/builtin-tool-creds/src/index.ts
index 89db5af205d..863e8ca8171 100644
--- a/packages/builtin-tool-creds/src/index.ts
+++ b/packages/builtin-tool-creds/src/index.ts
@@ -18,8 +18,6 @@ export {
CredsApiName,
type CredsApiNameType,
type CredSummaryForContext,
- type GetPlaintextCredParams,
- type GetPlaintextCredState,
type InitiateOAuthConnectParams,
type InjectCredsToSandboxParams,
type InjectCredsToSandboxState,
diff --git a/packages/builtin-tool-creds/src/manifest.ts b/packages/builtin-tool-creds/src/manifest.ts
index 07c014c466d..0293c84cb06 100644
--- a/packages/builtin-tool-creds/src/manifest.ts
+++ b/packages/builtin-tool-creds/src/manifest.ts
@@ -44,27 +44,7 @@ export const CredsManifest: BuiltinToolManifest = {
},
{
description:
- 'Retrieve the plaintext value of a stored credential by its key. Use this when you need to access a credential for making API calls or other operations. Only call this when you actually need the credential value. On desktop/local (no sandbox), use this to retrieve credentials and pass them to runCommand as inline environment variables.',
- name: CredsApiName.getPlaintextCred,
- parameters: {
- additionalProperties: false,
- properties: {
- key: {
- description: 'The unique key of the credential to retrieve',
- type: 'string',
- },
- reason: {
- description: 'Brief explanation of why this credential is needed (for audit purposes)',
- type: 'string',
- },
- },
- required: ['key'],
- type: 'object',
- } satisfies JSONSchema7,
- },
- {
- description:
- 'Inject credentials into the sandbox environment as environment variables. Only available when sandbox mode is enabled β€” do NOT call this on desktop/local. Use this before running code that requires credentials. For desktop/local, use getPlaintextCred instead.',
+ 'Inject credentials into the sandbox environment as environment variables. Only available when sandbox mode is enabled β€” do NOT call this on desktop/local.',
name: CredsApiName.injectCredsToSandbox,
parameters: {
additionalProperties: false,
diff --git a/packages/builtin-tool-creds/src/systemRole.ts b/packages/builtin-tool-creds/src/systemRole.ts
index 0c4fca2ecc0..6c6d8255e43 100644
--- a/packages/builtin-tool-creds/src/systemRole.ts
+++ b/packages/builtin-tool-creds/src/systemRole.ts
@@ -1,9 +1,9 @@
export const systemPrompt = `You have access to a LobeHub Credentials Tool. This tool helps you securely manage and use credentials (API keys, tokens, secrets) for various services.
<session_context>
-Current user: {{username}}
-Session date: {{date}}
-Sandbox mode: {{sandbox_enabled}}
+Current user: Arvin Xu
+Session date: Wednesday, May 20, 2026
+Sandbox mode: false
</session_context>
<available_credentials>
@@ -20,13 +20,11 @@ Sandbox mode: {{sandbox_enabled}}
<core_responsibilities>
1. **Awareness**: Know what credentials the user has configured and suggest relevant ones when needed.
2. **Guidance**: When you detect sensitive information (API keys, tokens, passwords) in the conversation, guide the user to save them securely in LobeHub.
-3. **Secure Access**: Use \`getPlaintextCred\` only when you actually need the credential value for an operation.
-4. **Runtime Integration**: When sandbox mode is enabled, use \`injectCredsToSandbox\` to inject credentials. On desktop/local (sandbox disabled), use \`getPlaintextCred\` and pass values as inline env vars to \`runCommand\`.
+3. **Runtime Integration**: When sandbox mode is enabled, use \`injectCredsToSandbox\` to inject credentials into the sandbox environment.
</core_responsibilities>
<tooling>
- **initiateOAuthConnect**: Start OAuth authorization flow for third-party services. Returns an authorization URL for the user to click.
-- **getPlaintextCred**: Retrieve the plaintext value of a credential by key. Only use when you need to actually use the credential.
- **injectCredsToSandbox**: Inject credentials into the sandbox environment. Only available when sandbox mode is enabled.
- **saveCreds**: Save new credentials securely. Use when user wants to store sensitive information.
- Parameters: \`key\` (unique identifier, lowercase with hyphens), \`name\` (display name), \`type\` ("kv-env" or "kv-header"), \`values\` (object of key-value pairs, NOT a string), \`description\` (optional)
@@ -48,7 +46,6 @@ When a user mentions they want to use one of these services, use \`initiateOAuth
<security_guidelines>
- **Never display credential values** in your responses. Refer to credentials by their key or name only.
-- **Minimize credential access**: Only call \`getPlaintextCred\` when you genuinely need the value for an operation.
- **Prompt for saving**: When you see users share sensitive information like API keys or tokens, suggest:
"I noticed you shared a sensitive credential. Would you like me to save it securely in LobeHub? This way you can reuse it without sharing it again."
- **Explain the benefit**: Let users know that saved credentials are encrypted and can be easily reused across conversations.
@@ -70,7 +67,7 @@ When suggesting to save, always:
</credential_saving_triggers>
<sandbox_integration>
-**Only applies when sandbox mode is enabled (current value: {{sandbox_enabled}}).**
+**Only applies when sandbox mode is enabled (current value: false).**
When sandbox mode is enabled and you need to run code that requires credentials:
1. Check if the required credential is in the available credentials list
@@ -96,42 +93,6 @@ When sandbox mode is enabled and you need to run code that requires credentials:
- Use the file path directly in your code (e.g., \`GOOGLE_APPLICATION_CREDENTIALS=~/.creds/files/gcp-service-account/credentials.json\`)
</sandbox_integration>
-<local_integration>
-**Only applies when sandbox mode is NOT enabled (desktop/local environment).**
-
-When running on desktop or local (sandbox NOT enabled), use credentials with local tools:
-
-1. Call \`getPlaintextCred\` to retrieve the credential values
- - The credential values will be available in the response state as \`values\` (Record<string, string>)
-2. Use \`runCommand\` (lobe-local-system) with the \`env\` parameter:
- - Pass the credential values via the \`env\` parameter β€” it is merged into the child process environment
- - NEVER embed secret values in the \`command\` string β€” they'd be visible in the UI and logs
-3. Always prefer \`getPlaintextCred\` over asking the user for credentials
-
-**Difference from sandbox mode:**
-- Sandbox: \`injectCredsToSandbox\` writes to \`~/.creds/env\`, then \`source ~/.creds/env && cmd\`
-- Local: \`getPlaintextCred\` returns values in state β†’ pass via \`runCommand\`'s \`env\` parameter
-
-**Example for local execution:**
-\`\`\`
-// 1. Get credential first
-const cred = getPlaintextCred({ key: "github" })
-// cred.state.values = { GITHUB_TOKEN: "ghp_xxx" }
-
-// 2. Use env parameter (NOT inline in command string)
-runCommand({
- command: "gh repo list",
- env: cred.state.values,
- description: "List repos"
-})
-\`\`\`
-
-**Important:**
-- Never pass credential values in the \`command\` string β€” use the \`env\` parameter of \`runCommand\` instead
-- Never pass credential values to \`executeCode\` β€” it runs in an isolated process without env support
-- File credentials: \`getPlaintextCred\` returns a \`fileUrl\` (download URL) in state β€” use \`runCommand\` with \`curl\` or \`writeFile\` to save the file locally first, then reference the local path
-</local_integration>
-
<klavis_integrations>
{{KLAVIS_SERVICES_LIST}}
</klavis_integrations>
@@ -140,7 +101,7 @@ runCommand({
- **Klavis integrations** are OAuth connections managed by the Klavis platform for third-party services (e.g., Gmail, Google Calendar, Slack).
- For **connected** Klavis services: Use the corresponding tools directly. Do NOT ask users for API keys, tokens, or credentials β€” the authorization is already handled by Klavis.
- For **available but not connected** services: Use \`connectKlavisService\` to initiate the OAuth connection flow via Klavis.
-- Klavis credentials **CANNOT** be retrieved via \`getPlaintextCred\` or injected via \`injectCredsToSandbox\` β€” they are tool-only authorizations managed externally by Klavis.
+- Klavis credentials **CANNOT** be injected via \`injectCredsToSandbox\` β€” they are tool-only authorizations managed externally by Klavis.
- If a user asks about a service that matches a connected Klavis integration, always prefer using the Klavis tools over asking the user for manual credentials.
</klavis_guidelines>
diff --git a/packages/builtin-tool-creds/src/types.ts b/packages/builtin-tool-creds/src/types.ts
index 50a75753cd5..aa6bfeca3d3 100644
--- a/packages/builtin-tool-creds/src/types.ts
+++ b/packages/builtin-tool-creds/src/types.ts
@@ -7,12 +7,6 @@ export const CredsApiName = {
*/
connectKlavisService: 'connectKlavisService',
- /**
- * Get plaintext value of a credential
- * Use when AI needs to access credential value for API calls
- */
- getPlaintextCred: 'getPlaintextCred',
-
/**
* Initiate OAuth connection flow
* Returns authorization URL for user to click and authorize
@@ -48,17 +42,6 @@ export type LobehubOAuthProviderId = (typeof LOBEHUB_OAUTH_PROVIDER_IDS)[number]
// ==================== Tool Parameter Types ====================
-export interface GetPlaintextCredParams {
- /**
- * The unique key of the credential to retrieve
- */
- key: string;
- /**
- * Reason for accessing this credential (for audit purposes)
- */
- reason?: string;
-}
-
export interface InitiateOAuthConnectParams {
/**
* The OAuth provider ID (e.g., 'linear', 'microsoft', 'notion', 'twitter')
@@ -85,17 +68,6 @@ export interface InitiateOAuthConnectState {
providerName: string;
}
-export interface GetPlaintextCredState {
- /**
- * The credential key
- */
- key: string;
- /**
- * The plaintext values (key-value pairs)
- */
- values?: Record<string, string>;
-}
-
export interface InjectCredsToSandboxParams {
/**
* The credential keys to inject