Skip to content
Open
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
1 change: 1 addition & 0 deletions lints/0011_function_search_path_mutable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ where
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'pgtle', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
)
and dep.objid is null -- exclude functions owned by extensions
and p.prokind not in ('a', 'w') -- exclude aggregates and window functions
-- Search path not set
and not exists (
select 1
Expand Down
1 change: 1 addition & 0 deletions splinter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ where
'_timescaledb_cache', '_timescaledb_catalog', '_timescaledb_config', '_timescaledb_internal', 'auth', 'cron', 'extensions', 'graphql', 'graphql_public', 'information_schema', 'net', 'pgmq', 'pgroonga', 'pgsodium', 'pgsodium_masks', 'pgtle', 'pgbouncer', 'pg_catalog', 'pgtle', 'realtime', 'repack', 'storage', 'supabase_functions', 'supabase_migrations', 'tiger', 'topology', 'vault'
)
and dep.objid is null -- exclude functions owned by extensions
and p.prokind not in ('a', 'w') -- exclude aggregates and window functions
-- Search path not set
and not exists (
select 1
Expand Down
19 changes: 19 additions & 0 deletions test/expected/0011_function_search_path_mutable.out
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ begin;
select * from lint."0011_function_search_path_mutable";
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+-------+--------+------------+-------------+--------+-------------+----------+-----------
(0 rows)

-- Create an aggregate function (should not be flagged)
create function public.mysum_state(state integer, val integer)
returns integer
language sql
set search_path = ''
as $$
select state + val;
$$;
create aggregate public.mysum(integer) (
sfunc = public.mysum_state,
stype = integer,
initcond = '0'
);
-- 0 issues: aggregate is excluded, state function has search_path set
select * from lint."0011_function_search_path_mutable";
name | title | level | facing | categories | description | detail | remediation | metadata | cache_key
------+-------+-------+--------+------------+-------------+--------+-------------+----------+-----------
(0 rows)

rollback;
16 changes: 16 additions & 0 deletions test/sql/0011_function_search_path_mutable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ begin;
-- 1 issue
select * from lint."0011_function_search_path_mutable";

-- Create an aggregate function (should not be flagged)
create function public.mysum_state(state integer, val integer)
returns integer
language sql
set search_path = ''
as $$
select state + val;
$$;

create aggregate public.mysum(integer) (
sfunc = public.mysum_state,
stype = integer,
initcond = '0'
);

-- 0 issues: aggregate is excluded, state function has search_path set
select * from lint."0011_function_search_path_mutable";

rollback;