|
2 | 2 |
|
3 | 3 | #![doc = r" Generated file, do not edit by hand, see `xtask/codegen`"] |
4 | 4 | use pgls_analyse::RegistryVisitor; |
| 5 | +#[doc = r" Metadata for a splinter rule"] |
| 6 | +#[derive(Debug, Clone, Copy)] |
| 7 | +pub struct SplinterRuleMetadata { |
| 8 | + #[doc = r" Description of what the rule detects"] |
| 9 | + pub description: &'static str, |
| 10 | + #[doc = r" URL to documentation/remediation guide"] |
| 11 | + pub remediation: &'static str, |
| 12 | + #[doc = r" Whether this rule requires Supabase roles (anon, authenticated, service_role)"] |
| 13 | + pub requires_supabase: bool, |
| 14 | +} |
5 | 15 | #[doc = r" Visit all splinter rules using the visitor pattern"] |
6 | 16 | #[doc = r" This is called during registry building to collect enabled rules"] |
7 | 17 | pub fn visit_registry<V: RegistryVisitor>(registry: &mut V) { |
@@ -151,6 +161,120 @@ pub fn get_sql_content(rule_name: &str) -> Option<&'static str> { |
151 | 161 | _ => None, |
152 | 162 | } |
153 | 163 | } |
| 164 | +#[doc = r" Get metadata for a rule (camelCase name)"] |
| 165 | +#[doc = r" Returns None if rule not found"] |
| 166 | +#[doc = r""] |
| 167 | +#[doc = r" This provides structured access to rule metadata without requiring SQL parsing"] |
| 168 | +pub fn get_rule_metadata(rule_name: &str) -> Option<SplinterRuleMetadata> { |
| 169 | + match rule_name { |
| 170 | + "authRlsInitplan" => Some(SplinterRuleMetadata { |
| 171 | + description: "Detects if calls to \\`current_setting()\\` and \\`auth.<function>()\\` in RLS policies are being unnecessarily re-evaluated for each row", |
| 172 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0003_auth_rls_initplan", |
| 173 | + requires_supabase: true, |
| 174 | + }), |
| 175 | + "authUsersExposed" => Some(SplinterRuleMetadata { |
| 176 | + description: "Detects if auth.users is exposed to anon or authenticated roles via a view or materialized view in schemas exposed to PostgREST, potentially compromising user data security.", |
| 177 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0002_auth_users_exposed", |
| 178 | + requires_supabase: true, |
| 179 | + }), |
| 180 | + "duplicateIndex" => Some(SplinterRuleMetadata { |
| 181 | + description: "Detects cases where two ore more identical indexes exist.", |
| 182 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0009_duplicate_index", |
| 183 | + requires_supabase: false, |
| 184 | + }), |
| 185 | + "extensionInPublic" => Some(SplinterRuleMetadata { |
| 186 | + description: "Detects extensions installed in the \\`public\\` schema.", |
| 187 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0014_extension_in_public", |
| 188 | + requires_supabase: false, |
| 189 | + }), |
| 190 | + "extensionVersionsOutdated" => Some(SplinterRuleMetadata { |
| 191 | + description: "Detects extensions that are not using the default (recommended) version.", |
| 192 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0022_extension_versions_outdated", |
| 193 | + requires_supabase: false, |
| 194 | + }), |
| 195 | + "fkeyToAuthUnique" => Some(SplinterRuleMetadata { |
| 196 | + description: "Detects user defined foreign keys to unique constraints in the auth schema.", |
| 197 | + remediation: "Drop the foreign key constraint that references the auth schema.", |
| 198 | + requires_supabase: true, |
| 199 | + }), |
| 200 | + "foreignTableInApi" => Some(SplinterRuleMetadata { |
| 201 | + description: "Detects foreign tables that are accessible over APIs. Foreign tables do not respect row level security policies.", |
| 202 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0017_foreign_table_in_api", |
| 203 | + requires_supabase: true, |
| 204 | + }), |
| 205 | + "functionSearchPathMutable" => Some(SplinterRuleMetadata { |
| 206 | + description: "Detects functions where the search_path parameter is not set.", |
| 207 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0011_function_search_path_mutable", |
| 208 | + requires_supabase: false, |
| 209 | + }), |
| 210 | + "insecureQueueExposedInApi" => Some(SplinterRuleMetadata { |
| 211 | + description: "Detects cases where an insecure Queue is exposed over Data APIs", |
| 212 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0019_insecure_queue_exposed_in_api", |
| 213 | + requires_supabase: true, |
| 214 | + }), |
| 215 | + "materializedViewInApi" => Some(SplinterRuleMetadata { |
| 216 | + description: "Detects materialized views that are accessible over the Data APIs.", |
| 217 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0016_materialized_view_in_api", |
| 218 | + requires_supabase: true, |
| 219 | + }), |
| 220 | + "multiplePermissivePolicies" => Some(SplinterRuleMetadata { |
| 221 | + description: "Detects if multiple permissive row level security policies are present on a table for the same \\`role\\` and \\`action\\` (e.g. insert). Multiple permissive policies are suboptimal for performance as each policy must be executed for every relevant query.", |
| 222 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0006_multiple_permissive_policies", |
| 223 | + requires_supabase: false, |
| 224 | + }), |
| 225 | + "noPrimaryKey" => Some(SplinterRuleMetadata { |
| 226 | + description: "Detects if a table does not have a primary key. Tables without a primary key can be inefficient to interact with at scale.", |
| 227 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0004_no_primary_key", |
| 228 | + requires_supabase: false, |
| 229 | + }), |
| 230 | + "policyExistsRlsDisabled" => Some(SplinterRuleMetadata { |
| 231 | + description: "Detects cases where row level security (RLS) policies have been created, but RLS has not been enabled for the underlying table.", |
| 232 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0007_policy_exists_rls_disabled", |
| 233 | + requires_supabase: false, |
| 234 | + }), |
| 235 | + "rlsDisabledInPublic" => Some(SplinterRuleMetadata { |
| 236 | + description: "Detects cases where row level security (RLS) has not been enabled on tables in schemas exposed to PostgREST", |
| 237 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0013_rls_disabled_in_public", |
| 238 | + requires_supabase: true, |
| 239 | + }), |
| 240 | + "rlsEnabledNoPolicy" => Some(SplinterRuleMetadata { |
| 241 | + description: "Detects cases where row level security (RLS) has been enabled on a table but no RLS policies have been created.", |
| 242 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0008_rls_enabled_no_policy", |
| 243 | + requires_supabase: false, |
| 244 | + }), |
| 245 | + "rlsReferencesUserMetadata" => Some(SplinterRuleMetadata { |
| 246 | + description: "Detects when Supabase Auth user_metadata is referenced insecurely in a row level security (RLS) policy.", |
| 247 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0015_rls_references_user_metadata", |
| 248 | + requires_supabase: true, |
| 249 | + }), |
| 250 | + "securityDefinerView" => Some(SplinterRuleMetadata { |
| 251 | + description: "Detects views defined with the SECURITY DEFINER property. These views enforce Postgres permissions and row level security policies (RLS) of the view creator, rather than that of the querying user", |
| 252 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0010_security_definer_view", |
| 253 | + requires_supabase: true, |
| 254 | + }), |
| 255 | + "tableBloat" => Some(SplinterRuleMetadata { |
| 256 | + description: "Detects if a table has excess bloat and may benefit from maintenance operations like vacuum full or cluster.", |
| 257 | + remediation: "Consider running vacuum full (WARNING: incurs downtime) and tweaking autovacuum settings to reduce bloat.", |
| 258 | + requires_supabase: false, |
| 259 | + }), |
| 260 | + "unindexedForeignKeys" => Some(SplinterRuleMetadata { |
| 261 | + description: "Identifies foreign key constraints without a covering index, which can impact database performance.", |
| 262 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0001_unindexed_foreign_keys", |
| 263 | + requires_supabase: false, |
| 264 | + }), |
| 265 | + "unsupportedRegTypes" => Some(SplinterRuleMetadata { |
| 266 | + description: "Identifies columns using unsupported reg* types outside pg_catalog schema, which prevents database upgrades using pg_upgrade.", |
| 267 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=unsupported_reg_types", |
| 268 | + requires_supabase: false, |
| 269 | + }), |
| 270 | + "unusedIndex" => Some(SplinterRuleMetadata { |
| 271 | + description: "Detects if an index has never been used and may be a candidate for removal.", |
| 272 | + remediation: "https://supabase.com/docs/guides/database/database-linter?lint=0005_unused_index", |
| 273 | + requires_supabase: false, |
| 274 | + }), |
| 275 | + _ => None, |
| 276 | + } |
| 277 | +} |
154 | 278 | #[doc = r" Map rule name from SQL result (snake_case) to diagnostic category"] |
155 | 279 | #[doc = r" Returns None if rule not found"] |
156 | 280 | #[doc = r""] |
@@ -225,6 +349,7 @@ pub fn get_rule_category(rule_name: &str) -> Option<&'static ::pgls_diagnostics: |
225 | 349 | } |
226 | 350 | #[doc = r" Check if a rule requires Supabase roles (anon, authenticated, service_role)"] |
227 | 351 | #[doc = r" Rules that require Supabase should be filtered out if these roles don't exist"] |
| 352 | +#[deprecated(note = "Use get_rule_metadata() instead")] |
228 | 353 | pub fn rule_requires_supabase(rule_name: &str) -> bool { |
229 | 354 | match rule_name { |
230 | 355 | "authRlsInitplan" => true, |
|
0 commit comments