fix(supabase): revoke PUBLIC EXECUTE on private helpers, audited visibility RPC, input caps, authz-first RPCs, +32 pgTAP checks
This commit is contained in:
1 parent
6966c54a2e
commit
d3fa65af29
15 files changed
+682
-221
No files matched your search
@@ -159,11 +159,17 @@ export const AnnotationSchema = z.discriminatedUnion('kind', [
|
||||
DetailTriggerAnnotationSchema,
|
||||
])
|
||||
|
||||
/** Documents are shared across users: only web links, never javascript: URLs. */
|
||||
const HttpUrlSchema = z
|
||||
.string()
|
||||
.url()
|
||||
.refine((url) => /^https?:\/\//i.test(url), 'http(s) URL expected')
|
||||
|
||||
export const SourceRefSchema = z
|
||||
.object({
|
||||
type: z.enum(['manual', 'journal', 'database', 'web']),
|
||||
citation: z.string().min(1),
|
||||
url: z.string().url().optional(),
|
||||
url: HttpUrlSchema.optional(),
|
||||
})
|
||||
.strict()
|
||||
|
||||
|
||||
@@ -6,14 +6,25 @@ import {
|
||||
} from '../src'
|
||||
import { horseSlice, horseSliceInput } from './fixtures/horse-slice'
|
||||
|
||||
// Mutations deliberately break the typed shape, so the draft is untyped.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type LooseDoc = any
|
||||
type Mutation = (doc: LooseDoc) => void
|
||||
type Tree = Record<string, unknown>
|
||||
type Mutation = (doc: Tree) => void
|
||||
|
||||
/** Walks `path` inside a JSON tree; mutations break the typed shape on purpose. */
|
||||
function at(doc: Tree, path: (string | number)[]): Tree {
|
||||
return path.reduce<Tree>((node, key) => node[key] as Tree, doc)
|
||||
}
|
||||
|
||||
function set(doc: Tree, path: (string | number)[], value: unknown): void {
|
||||
at(doc, path.slice(0, -1))[String(path.at(-1))] = value
|
||||
}
|
||||
|
||||
function unset(doc: Tree, path: (string | number)[]): void {
|
||||
delete at(doc, path.slice(0, -1))[String(path.at(-1))]
|
||||
}
|
||||
|
||||
/** Applies a mutation to the lean fixture and reports whether it parses. */
|
||||
function parsesAfter(mutate: Mutation): boolean {
|
||||
const doc: LooseDoc = horseSliceInput()
|
||||
const doc = horseSliceInput() as unknown as Tree
|
||||
mutate(doc)
|
||||
return AnatomicalSheetDocumentSchema.safeParse(doc).success
|
||||
}
|
||||
@@ -31,35 +42,70 @@ describe('AnatomicalSheetDocumentSchema', () => {
|
||||
})
|
||||
|
||||
const rejections: Array<[string, Mutation]> = [
|
||||
['an unknown top-level key', (d) => (d.extra = true)],
|
||||
['an unknown nested key', (d) => (d.views[0].zoom = 2)],
|
||||
['a stable id with spaces', (d) => (d.annotations[0].id = 'Hip Joint')],
|
||||
['a stable id with an accent', (d) => (d.categories[0].id = 'É')],
|
||||
['an empty stable id', (d) => (d.finding_zones[0].id = '')],
|
||||
['schema_version 2', (d) => (d.schema_version = 2)],
|
||||
['a non-uuid svg_asset_id', (d) => (d.views[0].svg_asset_id = 'horse')],
|
||||
['an unknown top-level key', (d) => set(d, ['extra'], true)],
|
||||
['an unknown nested key', (d) => set(d, ['views', 0, 'zoom'], 2)],
|
||||
[
|
||||
'a stable id with spaces',
|
||||
(d) => set(d, ['annotations', 0, 'id'], 'Hip Joint'),
|
||||
],
|
||||
['a stable id with an accent', (d) => set(d, ['categories', 0, 'id'], 'É')],
|
||||
['an empty stable id', (d) => set(d, ['finding_zones', 0, 'id'], '')],
|
||||
['schema_version 2', (d) => set(d, ['schema_version'], 2)],
|
||||
[
|
||||
'a non-uuid svg_asset_id',
|
||||
(d) => set(d, ['views', 0, 'svg_asset_id'], 'horse'),
|
||||
],
|
||||
[
|
||||
'a polygon with 2 points',
|
||||
(d) =>
|
||||
(d.annotations[1].geometry.points = [
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
]),
|
||||
set(
|
||||
d,
|
||||
['annotations', 1, 'geometry', 'points'],
|
||||
[
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
],
|
||||
),
|
||||
],
|
||||
['a circle with r 0', (d) => (d.annotations[0].geometry.r = 0)],
|
||||
['a region count of 0', (d) => (d.vertebral_config.regions[0].count = 0)],
|
||||
['a missing en label', (d) => delete d.name.en],
|
||||
[
|
||||
'a circle with r 0',
|
||||
(d) => set(d, ['annotations', 0, 'geometry', 'r'], 0),
|
||||
],
|
||||
[
|
||||
'a region count of 0',
|
||||
(d) => set(d, ['vertebral_config', 'regions', 0, 'count'], 0),
|
||||
],
|
||||
['a missing en label', (d) => unset(d, ['name', 'en'])],
|
||||
[
|
||||
'a detail view without parent_view_id',
|
||||
(d) => delete d.views[1].parent_view_id,
|
||||
(d) => unset(d, ['views', 1, 'parent_view_id']),
|
||||
],
|
||||
[
|
||||
'a detail_trigger with finding_zone_id',
|
||||
(d) => (d.annotations[3].finding_zone_id = 'hip'),
|
||||
(d) => set(d, ['annotations', 3, 'finding_zone_id'], 'hip'),
|
||||
],
|
||||
[
|
||||
'a javascript: source url',
|
||||
(d) =>
|
||||
set(
|
||||
d,
|
||||
[
|
||||
'finding_zones',
|
||||
0,
|
||||
'categories',
|
||||
2,
|
||||
'children',
|
||||
0,
|
||||
'sources',
|
||||
0,
|
||||
'url',
|
||||
],
|
||||
'javascript:alert(1)',
|
||||
),
|
||||
],
|
||||
[
|
||||
'a finding category kind foo',
|
||||
(d) => (d.finding_zones[0].categories[0].kind = 'foo'),
|
||||
(d) => set(d, ['finding_zones', 0, 'categories', 0, 'kind'], 'foo'),
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ export type Database = {
|
||||
description: string
|
||||
id: string
|
||||
is_official: boolean
|
||||
last_version_number: number
|
||||
name: string
|
||||
slug: string
|
||||
species_id: string
|
||||
@@ -170,6 +171,7 @@ export type Database = {
|
||||
description?: string
|
||||
id?: string
|
||||
is_official?: boolean
|
||||
last_version_number?: number
|
||||
name: string
|
||||
slug: string
|
||||
species_id: string
|
||||
@@ -188,6 +190,7 @@ export type Database = {
|
||||
description?: string
|
||||
id?: string
|
||||
is_official?: boolean
|
||||
last_version_number?: number
|
||||
name?: string
|
||||
slug?: string
|
||||
species_id?: string
|
||||
@@ -428,6 +431,13 @@ export type Database = {
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
set_sheet_visibility: {
|
||||
Args: {
|
||||
sheet_id: string
|
||||
visibility: Database['public']['Enums']['sheet_visibility']
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
}
|
||||
Enums: {
|
||||
platform_role: 'owner' | 'admin' | 'moderator' | 'support'
|
||||
|
||||
@@ -57,6 +57,7 @@ const expectedColumns = {
|
||||
'description',
|
||||
'id',
|
||||
'is_official',
|
||||
'last_version_number',
|
||||
'name',
|
||||
'slug',
|
||||
'species_id',
|
||||
@@ -125,6 +126,7 @@ const expectedFunctionArgs = {
|
||||
register_sheet_asset: ['byte_size', 'file_name', 'sha256', 'sheet_id'],
|
||||
restore_anatomical_sheet: ['sheet_id'],
|
||||
revoke_platform_role: ['reason', 'role', 'target_user_id'],
|
||||
set_sheet_visibility: ['sheet_id', 'visibility'],
|
||||
} as const satisfies FunctionArgs
|
||||
|
||||
type MissingArgs = {
|
||||
|
||||
Reference in new issue
Block a user