P0+P1 fixes: RCE sandbox, SQL injection, RLS tenant isolation, DB roles, test syntax, attachment, permission registry, membership check
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
+11
-2
@@ -99,10 +99,19 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
|
||||
|
||||
async def set_tenant_context(session: AsyncSession, tenant_id: uuid.UUID | str) -> None:
|
||||
"""Set PostgreSQL session variable for RLS tenant context."""
|
||||
"""Set PostgreSQL session variable for RLS tenant context.
|
||||
|
||||
Sets both app.current_tenant_id (new standard) and app.tenant_id
|
||||
(legacy, used by migration 0044 policies) for backward compatibility.
|
||||
"""
|
||||
tid = str(tenant_id)
|
||||
await session.execute(
|
||||
text("SELECT set_config('app.current_tenant_id', :tid, true)"),
|
||||
{"tid": str(tenant_id)},
|
||||
{"tid": tid},
|
||||
)
|
||||
await session.execute(
|
||||
text("SELECT set_config('app.tenant_id', :tid, true)"),
|
||||
{"tid": tid},
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -128,17 +128,31 @@ class PermissionRegistry:
|
||||
self._core_field_definitions: list[dict[str, str]] = list(CORE_FIELD_DEFINITIONS)
|
||||
|
||||
def initialize(self, active_plugin_names: set[str] | None = None) -> None:
|
||||
"""Build the registry from core permissions and active plugin manifests."""
|
||||
"""Build the registry from core permissions and active plugin manifests.
|
||||
|
||||
Preserves already-registered plugin permissions (fixes P1.3 bug where
|
||||
initialize() would wipe plugin permissions registered before startup).
|
||||
"""
|
||||
# Preserve existing plugin permissions
|
||||
existing_plugin_perms = self._plugin_permissions.copy()
|
||||
|
||||
# Reset only core permissions, keep plugin permissions
|
||||
self._permissions = {}
|
||||
self._plugin_permissions = {}
|
||||
self._active_plugins = active_plugin_names or set()
|
||||
|
||||
# Register core permissions
|
||||
for perm in CORE_PERMISSIONS:
|
||||
self._permissions[perm["key"]] = perm
|
||||
|
||||
# Re-apply plugin permissions that were registered before initialize()
|
||||
for plugin_name, perms in existing_plugin_perms.items():
|
||||
self._plugin_permissions[plugin_name] = perms
|
||||
for entry in perms:
|
||||
self._permissions[entry["key"]] = entry
|
||||
|
||||
self._initialized = True
|
||||
logger.info("Permission registry initialized with %d core permissions", len(CORE_PERMISSIONS))
|
||||
logger.info("Permission registry initialized with %d core permissions, %d plugin permissions",
|
||||
len(CORE_PERMISSIONS), len(existing_plugin_perms))
|
||||
|
||||
def register_plugin_permissions(self, plugin_name: str, permissions: list[str]) -> None:
|
||||
"""Register permissions from a plugin manifest."""
|
||||
|
||||
Reference in New Issue
Block a user