mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 08:06:50 +00:00
feat(payment): hide secret config fields in admin GET and preserve on empty PUT
- Strip sensitive provider config keys (privateKey/publicKey/apiV3Key/ secretKey/webhookSecret/pkey/password/etc.) from admin list/detail API - mergeConfig: empty value for a sensitive key preserves the stored secret - Admin dialog: sensitive inputs add autocomplete="new-password" + data-*ignore + spellcheck="false" to block browser password managers; edit-mode placeholder shows "leave empty to keep"; skip required validation for sensitive fields when editing Bump version to 0.1.114.6
This commit is contained in:
1 parent
dcf56340be
commit
2599b9f278
3 files changed
+44
-8
No files matched your search
@@ -1 +1 @@
|
||||
0.1.114.5
|
||||
0.1.114.6
|
||||
@@ -60,8 +60,26 @@ func (s *PaymentConfigService) ListProviderInstancesWithConfig(ctx context.Conte
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// decryptAndMaskConfig returns the stored config with sensitive fields omitted.
|
||||
// Admin UIs display masked placeholders for these; the raw values never leave
|
||||
// the server. Callers that need the full config (e.g. payment runtime) must
|
||||
// use decryptConfig directly.
|
||||
func (s *PaymentConfigService) decryptAndMaskConfig(encrypted string) (map[string]string, error) {
|
||||
return s.decryptConfig(encrypted)
|
||||
cfg, err := s.decryptConfig(encrypted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cfg == nil {
|
||||
return nil, nil
|
||||
}
|
||||
masked := make(map[string]string, len(cfg))
|
||||
for k, v := range cfg {
|
||||
if isSensitiveConfigField(k) {
|
||||
continue
|
||||
}
|
||||
masked[k] = v
|
||||
}
|
||||
return masked, nil
|
||||
}
|
||||
|
||||
// pendingOrderStatuses are order statuses considered "in progress".
|
||||
@@ -282,9 +300,14 @@ func (s *PaymentConfigService) mergeConfig(ctx context.Context, id int64, newCon
|
||||
return nil, fmt.Errorf("decrypt existing config for instance %d: %w", id, err)
|
||||
}
|
||||
if existing == nil {
|
||||
return newConfig, nil
|
||||
existing = map[string]string{}
|
||||
}
|
||||
for k, v := range newConfig {
|
||||
// Preserve existing secrets when the client submits an empty value
|
||||
// (admin UI omits the value to indicate "leave unchanged").
|
||||
if v == "" && isSensitiveConfigField(k) {
|
||||
continue
|
||||
}
|
||||
existing[k] = v
|
||||
}
|
||||
return existing, nil
|
||||
|
||||
@@ -88,13 +88,24 @@
|
||||
v-model="config[field.key]"
|
||||
rows="3"
|
||||
class="input font-mono text-xs"
|
||||
autocomplete="new-password"
|
||||
data-1p-ignore
|
||||
data-lpignore="true"
|
||||
data-bwignore="true"
|
||||
spellcheck="false"
|
||||
:placeholder="editing ? t('admin.accounts.leaveEmptyToKeep') : ''"
|
||||
/>
|
||||
<div v-else-if="field.sensitive" class="relative">
|
||||
<input
|
||||
:type="visibleFields[field.key] ? 'text' : 'password'"
|
||||
v-model="config[field.key]"
|
||||
class="input pr-10"
|
||||
:placeholder="field.defaultValue || ''"
|
||||
autocomplete="new-password"
|
||||
data-1p-ignore
|
||||
data-lpignore="true"
|
||||
data-bwignore="true"
|
||||
spellcheck="false"
|
||||
:placeholder="editing ? t('admin.accounts.leaveEmptyToKeep') : (field.defaultValue || '')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
@@ -398,9 +409,12 @@ function handleSave() {
|
||||
emitValidationError(t('admin.settings.payment.validationNameRequired'))
|
||||
return
|
||||
}
|
||||
// Validate required config fields — all non-optional fields must be filled
|
||||
// Validate required config fields — all non-optional fields must be filled.
|
||||
// In edit mode, sensitive fields may be left blank to preserve the stored
|
||||
// value (backend merges blanks by preserving the existing secret).
|
||||
for (const f of PROVIDER_CONFIG_FIELDS[form.provider_key] || []) {
|
||||
if (f.optional) continue
|
||||
if (props.editing && f.sensitive) continue
|
||||
const val = (config[f.key] || '').trim()
|
||||
if (!val) {
|
||||
const label = f.label || t(`admin.settings.payment.field_${f.key}`)
|
||||
@@ -412,8 +426,6 @@ function handleSave() {
|
||||
const filteredConfig: Record<string, string> = {}
|
||||
for (const [k, v] of Object.entries(config)) {
|
||||
if (!v || !v.trim()) continue
|
||||
// Skip masked values — backend keeps existing credentials
|
||||
if (v === '••••••••') continue
|
||||
filteredConfig[k] = v
|
||||
}
|
||||
|
||||
@@ -470,7 +482,8 @@ function loadProvider(provider: ProviderInstance) {
|
||||
form.refund_enabled = provider.refund_enabled
|
||||
form.allow_user_refund = provider.allow_user_refund
|
||||
clearConfig()
|
||||
// Pre-fill config from API response (non-sensitive in cleartext, sensitive masked as ••••••••)
|
||||
// Pre-fill config from API response. Backend omits sensitive fields entirely,
|
||||
// so those inputs stay blank — submitting blank preserves the stored secret.
|
||||
if (provider.config) {
|
||||
for (const [k, v] of Object.entries(provider.config)) {
|
||||
// Skip notifyUrl/returnUrl — they are derived from callbackBaseUrl
|
||||
|
||||
Reference in new issue
Block a user