fix(db): SQL CreateTemplate must return persisted vault IDs#3865
fix(db): SQL CreateTemplate must return persisted vault IDs#3865cursor[bot] wants to merge 1 commit into
Conversation
CreateTemplate called FillTemplate on a zero ID then discarded the result, so API responses kept vault_id 0 for rows inserted in UpdateTemplateVaults. Populate the template ID first and return FillTemplate output so clients get persisted vault and environment IDs. Co-authored-by: Denis Gukov <fiftin@outlook.com>
There was a problem hiding this comment.
Security review (PR #3865)
Outcome: No medium, high, or critical vulnerabilities were identified in the added or modified code.
What changed: CreateTemplate now assigns newTemplate from the input template, sets newTemplate.ID to the insert id, and only then calls db.FillTemplate. That matches how FillTemplate works: it loads vaults, environment links, and related state using template.ProjectID and template.ID. Previously FillTemplate ran against a zero-valued struct (including ID == 0), so hydration was wrong or ineffective; the fix restores correct server-side hydration after create. SQL remains parameterized; no new trust boundary or injection surface was introduced.
Prior automation threads: Stale threads from earlier runs are cleared via cleanup_previous. No open findings required re-posting with new evidence.
Slack summary: PR 3865 security review complete — clean. Change is a DB-layer correctness fix (hydrate template after assign persisted ID); no exploitable authz/authn bypass, injection, or secret exposure identified in the diff.
Sent by Cursor Automation: Find vulnerabilities


Bug and impact
For the SQL store,
CreateTemplatecalledFillTemplateon a zero-valued template (project/template ID 0), then discarded that result and returned the original request body withnewTemplate.IDset.UpdateTemplateVaultsinserts new vault rows with real primary keys, but those IDs were never reflected in the API response—clients receivedvault.id == 0for newly created vaults. That breaks any follow-up operations that rely on returned IDs and misleads UIs or automation.Root cause
After insert and
UpdateTemplateEnvironments, the code filled a throwaway struct, then overwrote it withnewTemplate = template, undoing any DB-backed fieldsFillTemplatewould have loaded if IDs had been set correctly.Fix
Set
newTemplatefrom the input template, assignnewTemplate.IDto the insert ID, then runFillTemplateonce so vaults and template–environment links are reloaded from the database (matching the BoltDB path, which already returns the stored object and fills it).Validation
go test ./db/sql/... ./db/... -shortNo new integration test was added: the repository does not ship an in-memory SQL
CreateTemplateharness; the change is a straightforward ordering fix aligned withFillTemplate’s contract.