Repository navigation
fix(db): import JSON preserva estado das chaves e cifra credenciais (GHSA-p42h) - #16655
Merged
diegosouzapw merged 2 commits intoOct 15, 2026
Merged
Conversation
… plaintext credentials (GHSA-p42h)
…ngs import (GHSA-p42h) The JSON importer rewrote every API key from 8 columns, so revoked, expired and banned keys became valid again and their restrictions (scopes, allowlists, connection/combo access, rate and usage limits) were dropped. The key column list is now derived from the live api_keys schema, so every column present in the backup is restored and future columns are not silently lost. Connections were also written with plaintext credentials and lost group, max_concurrent, proxy_enabled, per_key_proxy_enabled, quota_visible and quota_window_thresholds. Credentials now go through encryptConnectionFields() and those columns are restored. Co-authored-by: xiaoyaner0201 <xiaoyaner0201@users.noreply.github.com>
Contributor
CI Coverage Report
Coverage artifact was not available for this run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema (GHSA-p42h-25v7-99v5)
Restaurar um backup JSON (
POST /api/settings/import-json->runJsonMigration()) regravava cada chave de API a partir de apenas 8 colunas. Todo o resto voltava ao default, então chaves revogadas, expiradas ou banidas voltavam a ser válidas e perdiam as restrições (scopes, ip_allowlist, conexões/combos permitidos, limites de taxa e de uso).As conexões também eram gravadas com credenciais em texto puro (sem
encryptConnectionFields(), mesmo comSTORAGE_ENCRYPTION_KEYdefinida) e perdiam colunas de migrations posteriores.Correção
api_keys(PRAGMA table_info, novosrc/lib/db/apiKeys/importRow.ts). Toda coluna presente no backup é restaurada (revoked_at, expires_at, is_active, is_banned, scopes, ip_allowlist, allowed_connections, allowed_combos, allowed_quotas, allowed_endpoints, max_requests_per_minute/day, max_sessions, throttle_delay_ms, rate_limits, access_schedule, usage_limit_enabled, daily/weekly_usage_limit_usd, key_hash, key_prefix, proxy_id etc.), inclusive colunas futuras. Campos ausentes em backups antigos mantêm o default da tabela;nullem colunaNOT NULLcai no default em vez de abortar.apiKey,accessToken,refreshTokeneidTokenpassam porencryptConnectionFields(); passam a ser preservadasgroup,max_concurrent,proxy_enabled,per_key_proxy_enabled,quota_visibleequota_window_thresholds_json.src/lib/db/.Evidência (TDD)
512acaf64c):tests/unit/settings-json-import-key-state-ghsa-p42h.test.ts-> 5 falhas, 1 passa (backup legado). Chaves revogada/expirada/banida validavam comotrueapós o round trip; credenciais gravadas semenc:v1:.b6f5332674): 6/6. Suítes relacionadas (json-migration-combos, rate-limit-overrides-reimport, settings-import-json-session-state, export-json-hide-paid-combos-6328, oidc-settings-reauth, credential-export-always-protected, api-manager-provider-permissions) todas verdes.typecheck:core, eslint e prettier limpos nos arquivos alterados.check:file-sizereporta 4 violações pré-existentes em arquivos não tocados (responseSanitizer, error.ts, dois testes).Fora de escopo
IMPORT_STRIPPED_SETTINGS_KEYS(#16491) não foi tocado.Co-authored-by: xiaoyaner0201 xiaoyaner0201@users.noreply.github.com