fix: redact sensitive fields and prevent credential loss on edit
Closes #988 Unify the "write-only secrets" pattern across MCP services, Models, WebSearch providers, and DataSources. Fix two related defects: 1. GET responses leaked plaintext credentials — GetMCPServiceByID while List masked, all Model / WebSearchProvider / DataSource GET responses unconditionally. 2. When the frontend echoed a masked placeholder back on save, the update path overwrote the stored secret with the mask — silently wiping the real credential. MCP surfaced this most visibly: ListMCPServices masked Token to "first4****last4" and McpServiceDialog round-tripped that masked string back into the DB. - internal/types/secret.go introduces the shared sentinel RedactedSecretPlaceholder = "***" and two helpers: - IsRedactedOrEmpty(s): true for "" or the sentinel - PreserveIfRedacted(incoming, existing): merge predicate - Each resource adds a RedactSensitiveData (mutates-in-place) or Redacted (returns-a-copy) method and a MergeUpdate contract: empty or placeholder preserves, any other value replaces, and a write-only Clear* bool flag (gorm:"-", json omitempty) wipes with precedence over preserve / replace. Clear* never persists. - Every GET / List / Create / Update response path now redacts. VectorStore's pre-existing "***" literal is refactored onto the shared constant for consistency. All four dialogs — McpServiceDialog, ModelEditorDialog, WebSearchSettings, DataSourceEditorDialog — never pre-fill secret inputs. The stored-state signal is collapsed into the input placeholder: "•••••••• (Enter new value to replace)" when the server reports a stored value, falling back to the connector-specific placeholder otherwise. The input itself carries the "something is there" cue, matching how password dots render. An opt-in "Remove this credential" checkbox appears in edit mode when a value is stored; checking it disables the input and triggers a danger-themed confirmation dialog before submit. DataSource rolls the clear up to a connector-level "Remove all credentials" flag since its credentials are per-connector atomic bundles (e.g. Feishu app_id + app_secret). i18n updates across en-US, zh-CN, ko-KR, ru-RU: secret.storedPlaceholder / clearHint / confirmClearTitle / confirmClearBody. - MCP update handler's manual map-to-struct projection was silently dropping clear_api_key / clear_token / custom_headers on partial updates. Pull them off the map explicitly. - MCP configChanged detection now snapshots URL / StdioConfig / TransportType before the merge so connection recycling still triggers on real transport changes (not just whenever AuthConfig is present). - MCP CustomHeaders: nil preserves existing, non-nil replaces. Was always overwriting, silently wiping headers on any auth-bearing update. - GetMCPServiceByID now redacts (was plaintext while List masked). - WebSearchProvider update preserves Name / Description when empty instead of clobbering them. - WebSearchProvider TestProviderRaw rejects the "***" placeholder up front with an actionable message rather than forwarding it to the upstream provider API as a literal key. - Model builtin hideSensitiveInfo now preserves non-secret metadata (SupportsVision, Provider, ExtraConfig, InterfaceType, ParameterSize, EmbeddingParameters) that were previously zeroed out for builtin model cards. - Replace local equalStringSlices / equalStringMaps helpers with stdlib slices.Equal / maps.Equal (Go 1.21+). - internal/types/{secret,mcp,model,web_search_provider,datasource}_test.go: table-driven coverage of merge, redact, clear, and write-only flag invariants for every resource. - internal/application/service/mcp_service_test.go: full service layer with a fake repo; covers ListMCPServices / GetMCPServiceByID redaction, UpdateMCPService partial-update honoring of Clear*, CustomHeaders preserve-on-nil / replace-on-non-nil, and clear-flag precedence over submitted values. Additive only. No changes to request or response JSON shape beyond the write-only Clear* flags (omitted by default via omitempty). No DB schema changes. No SDK struct field removals. Existing clients that don't know about the new flags continue to function unchanged. - DataSource.Config jsonb at-rest encryption. Pre-existing residual risk; tracked as a follow-up. - Renaming VectorStore.MaskSensitiveFields to match the new RedactSensitiveData / Redacted naming convention. Left alone to minimize diff; a follow-up rename PR can unify.
This commit is contained in:
@@ -34,8 +34,8 @@
|
||||
</t-form-item>
|
||||
|
||||
<!-- URL for SSE/HTTP Streamable -->
|
||||
<t-form-item
|
||||
:label="t('mcpServiceDialog.serviceUrl')"
|
||||
<t-form-item
|
||||
:label="t('mcpServiceDialog.serviceUrl')"
|
||||
name="url"
|
||||
>
|
||||
<t-input v-model="formData.url" :placeholder="t('mcpServiceDialog.serviceUrlPlaceholder')" />
|
||||
@@ -50,20 +50,47 @@
|
||||
<!-- Authentication Config -->
|
||||
<t-collapse :default-value="[]">
|
||||
<t-collapse-panel :header="t('mcpServiceDialog.authConfig')" value="auth">
|
||||
<t-form-item :label="t('mcpServiceDialog.apiKey')">
|
||||
<!--
|
||||
Credential fields follow the "write-only secrets" pattern.
|
||||
When a value is currently stored on the server the placeholder
|
||||
is swapped for a bullet run + "Enter new value to replace"
|
||||
hint, so the visual "something is there" signal is carried by
|
||||
the input itself rather than by a separate Set/Not-set badge.
|
||||
The Remove checkbox still offers an explicit clear path.
|
||||
-->
|
||||
<div class="credential-field">
|
||||
<label class="credential-label">{{ t('mcpServiceDialog.apiKey') }}</label>
|
||||
<t-input
|
||||
v-model="formData.auth_config.api_key"
|
||||
type="password"
|
||||
:placeholder="t('mcpServiceDialog.optional')"
|
||||
:disabled="clearApiKey"
|
||||
:placeholder="apiKeyPlaceholder"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item :label="t('mcpServiceDialog.bearerToken')">
|
||||
<t-checkbox
|
||||
v-if="mode === 'edit' && hasExistingApiKey"
|
||||
v-model="clearApiKey"
|
||||
class="clear-credential"
|
||||
>
|
||||
{{ t('secret.clearHint') }}
|
||||
</t-checkbox>
|
||||
</div>
|
||||
|
||||
<div class="credential-field">
|
||||
<label class="credential-label">{{ t('mcpServiceDialog.bearerToken') }}</label>
|
||||
<t-input
|
||||
v-model="formData.auth_config.token"
|
||||
type="password"
|
||||
:placeholder="t('mcpServiceDialog.optional')"
|
||||
:disabled="clearToken"
|
||||
:placeholder="tokenPlaceholder"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-checkbox
|
||||
v-if="mode === 'edit' && hasExistingToken"
|
||||
v-model="clearToken"
|
||||
class="clear-credential"
|
||||
>
|
||||
{{ t('secret.clearHint') }}
|
||||
</t-checkbox>
|
||||
</div>
|
||||
</t-collapse-panel>
|
||||
|
||||
<!-- Advanced Config -->
|
||||
@@ -100,7 +127,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, computed } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
|
||||
import type { FormInstanceFunctions, FormRule } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import {
|
||||
@@ -128,6 +155,10 @@ const formRef = ref<FormInstanceFunctions>()
|
||||
const submitting = ref(false)
|
||||
const { t } = useI18n()
|
||||
|
||||
// Fixed placeholder returned by the server for sensitive fields whose values
|
||||
// are withheld. Must match internal/types/secret.go → RedactedSecretPlaceholder.
|
||||
const REDACTED_PLACEHOLDER = '***'
|
||||
|
||||
const formData = ref({
|
||||
name: '',
|
||||
description: '',
|
||||
@@ -145,11 +176,40 @@ const formData = ref({
|
||||
}
|
||||
})
|
||||
|
||||
// Explicit "remove stored credential" flags. Reset to false on every open/reset.
|
||||
const clearApiKey = ref(false)
|
||||
const clearToken = ref(false)
|
||||
|
||||
// "Is a credential currently stored?" is signaled by the server returning the
|
||||
// fixed REDACTED_PLACEHOLDER instead of an empty string. Drive the label
|
||||
// badge and placeholder hint from this signal.
|
||||
const hasExistingApiKey = computed(
|
||||
() => props.service?.auth_config?.api_key === REDACTED_PLACEHOLDER
|
||||
)
|
||||
const hasExistingToken = computed(
|
||||
() => props.service?.auth_config?.token === REDACTED_PLACEHOLDER
|
||||
)
|
||||
|
||||
// Placeholders swap to the shared "stored credential" hint when the server
|
||||
// signals a value is present (parameters come back as '***'). Otherwise
|
||||
// the field is genuinely empty and we fall through to the normal
|
||||
// "Optional" placeholder that appears in add mode too.
|
||||
const apiKeyPlaceholder = computed(() =>
|
||||
hasExistingApiKey.value
|
||||
? t('secret.storedPlaceholder')
|
||||
: t('mcpServiceDialog.optional')
|
||||
)
|
||||
const tokenPlaceholder = computed(() =>
|
||||
hasExistingToken.value
|
||||
? t('secret.storedPlaceholder')
|
||||
: t('mcpServiceDialog.optional')
|
||||
)
|
||||
|
||||
const rules: Record<string, FormRule[]> = {
|
||||
name: [{ required: true, message: t('mcpServiceDialog.rules.nameRequired') as string, type: 'error' }],
|
||||
transport_type: [{ required: true, message: t('mcpServiceDialog.rules.transportRequired') as string, type: 'error' }],
|
||||
url: [
|
||||
{
|
||||
{
|
||||
validator: (val: string) => {
|
||||
if (!val || val.trim() === '') {
|
||||
return { result: false, message: t('mcpServiceDialog.rules.urlRequired') as string, type: 'error' }
|
||||
@@ -171,7 +231,10 @@ const dialogVisible = computed({
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
|
||||
// Reset form function - defined before watch to avoid hoisting issues
|
||||
// Reset form function — defined before watch to avoid hoisting issues.
|
||||
// Sensitive fields are always blank: the watch below does not copy the
|
||||
// server-provided redacted placeholder into formData, and clear flags are
|
||||
// reset so a reopen does not carry over an aborted deletion intent.
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
name: '',
|
||||
@@ -189,10 +252,16 @@ const resetForm = () => {
|
||||
retry_delay: 1
|
||||
}
|
||||
}
|
||||
clearApiKey.value = false
|
||||
clearToken.value = false
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
// Watch service prop to initialize form
|
||||
// Watch service prop to initialize form.
|
||||
// Sensitive fields (api_key, token) are NEVER pre-filled from the server
|
||||
// response — even when the server returns '***' indicating a stored value.
|
||||
// This keeps the "non-empty means user typed it" invariant that the submit
|
||||
// logic relies on to decide between preserve and replace.
|
||||
watch(
|
||||
() => props.service,
|
||||
(service) => {
|
||||
@@ -206,8 +275,8 @@ watch(
|
||||
transport_type: transportType as 'sse' | 'http-streamable',
|
||||
url: service.url || '',
|
||||
auth_config: {
|
||||
api_key: service.auth_config?.api_key || '',
|
||||
token: service.auth_config?.token || ''
|
||||
api_key: '',
|
||||
token: ''
|
||||
},
|
||||
advanced_config: {
|
||||
timeout: service.advanced_config?.timeout || 30,
|
||||
@@ -215,6 +284,8 @@ watch(
|
||||
retry_delay: service.advanced_config?.retry_delay || 1
|
||||
}
|
||||
}
|
||||
clearApiKey.value = false
|
||||
clearToken.value = false
|
||||
} else {
|
||||
resetForm()
|
||||
}
|
||||
@@ -222,24 +293,67 @@ watch(
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// Handle submit
|
||||
// Prompt the user before irrevocable credential removal.
|
||||
const confirmClearIfNeeded = (): Promise<boolean> => {
|
||||
if (!clearApiKey.value && !clearToken.value) return Promise.resolve(true)
|
||||
return new Promise((resolve) => {
|
||||
const d = DialogPlugin.confirm({
|
||||
header: t('secret.confirmClearTitle'),
|
||||
body: t('secret.confirmClearBody'),
|
||||
confirmBtn: { content: t('common.confirm'), theme: 'danger' },
|
||||
cancelBtn: t('common.cancel'),
|
||||
onConfirm: () => {
|
||||
d.hide()
|
||||
resolve(true)
|
||||
},
|
||||
onCancel: () => {
|
||||
d.hide()
|
||||
resolve(false)
|
||||
},
|
||||
onClose: () => {
|
||||
d.hide()
|
||||
resolve(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Handle submit — three-state auth_config payload:
|
||||
// - clear flag set → send { clear_api_key: true } / { clear_token: true }
|
||||
// - user typed a value → send the value
|
||||
// - otherwise → omit the field, server preserves the stored value
|
||||
// If auth_config would be empty, omit the key entirely.
|
||||
const handleSubmit = async () => {
|
||||
const valid = await formRef.value?.validate()
|
||||
if (!valid) return
|
||||
|
||||
const proceed = await confirmClearIfNeeded()
|
||||
if (!proceed) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
const authPayload: Record<string, unknown> = {}
|
||||
if (clearApiKey.value) {
|
||||
authPayload.clear_api_key = true
|
||||
} else if (formData.value.auth_config.api_key) {
|
||||
authPayload.api_key = formData.value.auth_config.api_key
|
||||
}
|
||||
if (clearToken.value) {
|
||||
authPayload.clear_token = true
|
||||
} else if (formData.value.auth_config.token) {
|
||||
authPayload.token = formData.value.auth_config.token
|
||||
}
|
||||
|
||||
const data: Partial<MCPService> = {
|
||||
name: formData.value.name,
|
||||
description: formData.value.description,
|
||||
enabled: formData.value.enabled,
|
||||
transport_type: formData.value.transport_type,
|
||||
auth_config: {
|
||||
api_key: formData.value.auth_config.api_key || undefined,
|
||||
token: formData.value.auth_config.token || undefined
|
||||
},
|
||||
advanced_config: formData.value.advanced_config,
|
||||
url: formData.value.url || undefined
|
||||
url: formData.value.url || undefined,
|
||||
}
|
||||
if (Object.keys(authPayload).length > 0) {
|
||||
data.auth_config = authPayload as MCPService['auth_config']
|
||||
}
|
||||
|
||||
if (props.mode === 'add') {
|
||||
@@ -269,5 +383,37 @@ const handleClose = () => {
|
||||
|
||||
<style scoped lang="less">
|
||||
/* Stdio-related styles removed as stdio transport is disabled for security reasons */
|
||||
|
||||
/**
|
||||
* Credential field: stacks the label row, the password input, and the
|
||||
* optional "Remove this credential" checkbox vertically. Replaces the
|
||||
* t-form-item-based layout for the auth-config fields so the inline badge
|
||||
* doesn't get clipped by the form's 120px label-width and the clear
|
||||
* checkbox doesn't sit alongside the input.
|
||||
*/
|
||||
.credential-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 20px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.credential-label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.clear-credential {
|
||||
:deep(.t-checkbox__label) {
|
||||
color: var(--td-error-color);
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user