Goal Find as to whether PUBLIC (all current and future users) has TEMPORARY privilege in the database. PUBLIC gets the privilege by default.
Type Problem detection Each row in the result could represent a flaw in the design
Reliability High Few or no false-positive results
License MIT (opens in new tab)
Data Source system catalog only
SQL Query
SELECT 'TEMPORARY privilege to the database has been granted to PUBLIC' AS mistake
FROM pg_database
WHERE datname=current_database()
AND (array_to_string(datacl,',') IS NULL
OR array_to_string(datacl,',') ~ '^=.{0,1}[T].{0,1}/');

Fixing Suggestion

Revoke the privilege from PUBLIC.

Fixing Actions

SQL statements that help generate fixes for the identified problem.

Fix Action #1
SELECT format('REVOKE TEMP ON DATABASE %1$I FROM PUBLIC;', current_database()) AS statements
FROM pg_database
WHERE datname=current_database()
AND (array_to_string(datacl,',') IS NULL
OR array_to_string(datacl,',') ~ '^=.{0,1}[T].{0,1}/');

Revoke the TEMPORARY privilege from PUBLIC.

# SQL Query to Generate Fix Description
1
SELECT format('REVOKE TEMP ON DATABASE %1$I FROM PUBLIC;', current_database()) AS statements
FROM pg_database
WHERE datname=current_database()
AND (array_to_string(datacl,',') IS NULL
OR array_to_string(datacl,',') ~ '^=.{0,1}[T].{0,1}/');
Revoke the TEMPORARY privilege from PUBLIC.

Collections

This query belongs to the following collections:

Find problems automatically

Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .

NameDescription
Find problems automaticallyQueries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .

Categories

This query is classified under the following categories:

Security

Queries of this category provide information about the security measures.

NameDescription
SecurityQueries of this category provide information about the security measures.