Fix drift SET LOCAL: use string interpolation with UUID validation (SET doesn't support params)
This commit is contained in:
@@ -15,7 +15,9 @@ export function createPool(connectionString: string): pg.Pool {
|
|||||||
* MUST be cleared when returning the connection to the pool.
|
* MUST be cleared when returning the connection to the pool.
|
||||||
*/
|
*/
|
||||||
export async function setTenantContext(client: pg.PoolClient, tenantId: string): Promise<void> {
|
export async function setTenantContext(client: pg.PoolClient, tenantId: string): Promise<void> {
|
||||||
await client.query('SET LOCAL app.tenant_id = $1', [tenantId]);
|
// SET doesn't support parameterized queries — validate UUID format then interpolate
|
||||||
|
if (!/^[0-9a-f-]{36}$/i.test(tenantId)) throw new Error('Invalid tenant ID');
|
||||||
|
await client.query(`SET LOCAL app.tenant_id = '${tenantId}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user