mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2611] [Issue]: Profile restore clobbers live secrets (API keys, agent tokens, webhook URLs) by upserting redacted snapshot rows #1284
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1284
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Romuromylus on GitHub (Jun 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2611
Originally assigned to: @Romuromylus on GitHub.
Summary
Severity: High — data-loss. Restoring a profile export over an instance that still holds rows with matching primary keys silently wipes the live
api_connections.apiKeyEncrypted,agent_configssecret settings, andcustom_tools.webhookUrl— because the export redacts those columns and the restore upserts the redacted blanks onto existing rows. The secrets are absent from the archive, so the loss is unrecoverable from the backup.Expected behavior
Restoring a profile to recover deleted entities should not destroy secrets on entities that still exist. A redacted/blank secret in the snapshot must never overwrite a non-empty secret already stored in the DB.
Actual behavior
The export intentionally redacts secret columns into the snapshot (
sanitizeProfileTableRows):api_connections.apiKeyEncrypted -> "",agent_configssecret settings ->null(viaredactAgentSecrets,SECRET_KEY_REmatchingtoken/secret/password/api_key),custom_tools.webhookUrl -> "".On restore,
importProfileStorageSnapshotupserts each snapshot row withonConflictDoUpdate({ target: <pk>, set: cleanRow }), and forapi_connectionsit additionally force-blanks the key on the update path:Because the conflict UPDATE writes the whole redacted row, any pre-existing live row with the same primary-key id has its
apiKeyEncryptedset to"", its agent secret settings set tonull, and itscustom_tools.webhookUrlset to"". Reached viaPOST /api/backup/import-profile(requirePrivilegedAccessis the only gate;previewOnly/fingerprint checks do not protect the secret columns). No DB wipe precedes the upsert and there is no merge/skip-existing/COALESCE guard.SettingsPanel.tsxadvertises this exact "Restore full profiles … for recovery and migration" flow.Steps to reproduce
POST /api/backup/import-profile).apiKeyEncrypted/ agent secrets /webhookUrlfor the still-present rows are now blank/null, and are not present anywhere in the archive.Environment
staging @ 56f700cd(v2.0.0)Logs, screenshots, or video
Static source audit, cited to file:line above.
Additional context
Fix sketch. On the conflict UPDATE path, do not overwrite the redacted secret columns: drop
apiKeyEncrypted/webhookUrl/ the redacted agent-secret subfields from thesetobject soonConflictDoUpdatepreserves the existing DB value, or read the existing row and COALESCE-merge so a blank/null redacted value never overwrites a non-empty stored secret. Keep the blanks only on the fresh-insert path.Regression notes. Not a regression — the core mechanism is byte-identical on
main(backup.routes.tshas the samesanitizeProfileTableRows, the sameapiKeyEncrypted=""on the import update path, and the sameonConflictDoUpdate({ target: primaryKey, set: cleanRow })). The only staging-only delta is the addedcustom_tools.webhookUrlredaction branch, which extends the same already-broken upsert to one more column but is not the headline. Long-standing data-loss, found via static audit.Template check
@Romuromylus commented on GitHub (Jun 18, 2026):
Fixed in #2623, merged to
staging(e1132e5b). Closing manually since the PR targetedstagingrather than the default branch.