| Goal | This query acts as a global security alert. It triggers a warning if no roles in the entire database have explicitly revoked the default PUBLIC execute privileges for newly created routines. In PostgreSQL, new functions and procedures are executable by anyone (PUBLIC) by default. Leaving this unrestricted database-wide violates the principle of least privilege, potentially exposing sensitive business logic or data manipulation routines to unauthorized database users. |
|---|---|
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | Medium Medium number of false-positive results |
| License | MIT (opens in new tab) |
| Data Source | system catalog only |
| SQL Query |
|
Fixing Suggestion
To resolve this security vulnerability and enforce the principle of least privilege, the default public execution rights must be revoked. For the roles that create routines (or globally, if applicable), execute the following command: ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON ROUTINES FROM PUBLIC;. Once this baseline security is established, you must explicitly GRANT EXECUTE only to the specific roles or users that genuinely require access to those routines.
Fixing Actions
SQL statements that help generate fixes for the identified problem.
Fix Action #1
SELECT 'ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON ROUTINES FROM PUBLIC;' AS sql_statement;
Revoke the default privilege from the current role.
| # | SQL Query to Generate Fix | Description |
|---|---|---|
| 1 |
|
Revoke the default privilege from the current role. |
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 .
| Name | Description |
|---|---|
| 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 . |
Categories
This query is classified under the following categories:
Security
Queries of this category provide information about the security measures.
User-defined routines
Queries of this category provide information about the user-defined routines
| Name | Description |
|---|---|
| Security | Queries of this category provide information about the security measures. |
| User-defined routines | Queries of this category provide information about the user-defined routines |