Files
supabase/packages/pg-meta/test/sql/studio/lints.test.ts
Charis 592365408e fix(pg-meta): set pgrst.db_schemas to '' when the Data API is off (#52162)
## Problem

`enrichLintsQuery` in `packages/pg-meta/src/sql/studio/advisor/lints.ts`
only emitted `set local pgrst.db_schemas = ...` when `exposedSchemas`
was truthy. When the Data API is off (empty string), it emitted nothing.

The current lints rely on an unset `pgrst.db_schemas` yielding an empty
list. That only works with pg-meta's older copy of splinter. Newer
splinter falls back to `public` when the setting is unset, so once
pg-meta upgrades its splinter copy, projects with the Data API off would
get false exposure findings. Pooled backends that were reused after a
migration check can also read `''`, so relying on "unset" is unreliable.

Link:
https://linear.app/supabase/issue/FE-4708/pg-meta-lints-set-pgrstdb-schemas-when-the-data-api-is-off

## Solution

- An empty string now emits `set local pgrst.db_schemas = '';`.
- `undefined` is intentionally unchanged and still emits nothing.

This should land before the splinter copy upgrade.

## Review instructions

1. Run `pnpm vitest run test/sql/studio/lints.test.ts` in
`packages/pg-meta`. All 4 tests should pass.
2. Confirm that `enrichLintsQuery(query, '')` includes `set local
pgrst.db_schemas = '';` and that `enrichLintsQuery(query, undefined)`
includes no `pgrst.db_schemas` statement.

## Checklist

Check all before review:

- [ ] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-10-22 11:08:07 -04:00

28 lines
1007 B
TypeScript

import { describe, expect, it } from 'vitest'
import { enrichLintsQuery, safeSql } from '../../../src'
describe('enrichLintsQuery', () => {
const dummyQuery = safeSql`SELECT 1`
it('should include SET LOCAL pgrst.db_schemas when exposedSchemas is provided', () => {
const result = enrichLintsQuery(dummyQuery, 'public, storage')
expect(result).toContain("set local pgrst.db_schemas = 'public, storage';")
})
it('should NOT include SET LOCAL pgrst.db_schemas when exposedSchemas is undefined', () => {
const result = enrichLintsQuery(dummyQuery, undefined)
expect(result).not.toContain('pgrst.db_schemas')
})
it("should set pgrst.db_schemas to '' when exposedSchemas is empty string (Data API off)", () => {
const result = enrichLintsQuery(dummyQuery, '')
expect(result).toContain("set local pgrst.db_schemas = '';")
})
it('should always include the query', () => {
const result = enrichLintsQuery(dummyQuery)
expect(result).toContain(dummyQuery)
})
})