Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-json-arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ankhorage/supabase-vault': patch
---

Parse serialized configured-field arrays through PostgreSQL text before converting them to JSONB so Bun SQL does not expose them as JSON scalar strings during secret creation or replacement.
6 changes: 4 additions & 2 deletions src/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe('createSupabaseVaultAdapter', () => {
expect(JSON.stringify(result)).not.toContain('vault-id');

const [, , insertCall] = client.calls;
expect(insertCall?.sql).toContain('array(select jsonb_array_elements_text($7::jsonb))');
expect(insertCall?.sql).toContain('array(select jsonb_array_elements_text($7::text::jsonb))');
expect(insertCall?.sql).not.toContain('jsonb_array_elements_text($7::jsonb)');
expect(insertCall?.parameters[6]).toBe('["clientId","clientSecret"]');
expect(Array.isArray(insertCall?.parameters[6])).toBe(false);
});
Expand Down Expand Up @@ -104,7 +105,8 @@ describe('createSupabaseVaultAdapter', () => {
expect(JSON.stringify(result)).not.toContain('ROTATED_SECRET');

const [, , updateCall] = client.calls;
expect(updateCall?.sql).toContain('select jsonb_array_elements_text($4::jsonb)');
expect(updateCall?.sql).toContain('select jsonb_array_elements_text($4::text::jsonb)');
expect(updateCall?.sql).not.toContain('jsonb_array_elements_text($4::jsonb)');
expect(updateCall?.parameters[3]).toBe('["clientSecret"]');
expect(Array.isArray(updateCall?.parameters[3])).toBe(false);
});
Expand Down
4 changes: 2 additions & 2 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function createSupabaseVaultAdapter(
(project_id, environment, secret_ref, vault_secret_id, kind, provider, configured_fields)
values (
$1, $2, $3, $4::uuid, $5, $6,
array(select jsonb_array_elements_text($7::jsonb))
array(select jsonb_array_elements_text($7::text::jsonb))
)
returning project_id, environment, secret_ref, kind, provider, configured_fields,
created_at::text, updated_at::text`,
Expand Down Expand Up @@ -168,7 +168,7 @@ export function createSupabaseVaultAdapter(
const updated = await executor.query<MetadataRow>(
`update ${metadataTable}
set configured_fields = array(
select jsonb_array_elements_text($4::jsonb)
select jsonb_array_elements_text($4::text::jsonb)
),
updated_at = now()
where project_id = $1 and environment = $2 and secret_ref = $3
Expand Down
Loading