fix(permissions): exempt owners and admins from accessedServices filter in service search (#5361) - #5441
Open
fliptrigga13 wants to merge 1 commit into
Conversation
…er in service search (Dokploy#5361)
Comment on lines
+11
to
+45
| const resolveSearchFilters = async ( | ||
| ctx: { | ||
| user: { id: string; role: "owner" | "admin" | "member" }; | ||
| session: { activeOrganizationId: string }; | ||
| }, | ||
| memberRecord: { | ||
| role: "owner" | "admin" | "member"; | ||
| accessedServices: string[]; | ||
| }, | ||
| ) => { | ||
| const isPrivileged = | ||
| ctx.user.role === "owner" || | ||
| ctx.user.role === "admin" || | ||
| memberRecord.role === "owner" || | ||
| memberRecord.role === "admin"; | ||
|
|
||
| // Always scope to the active organization | ||
| const orgScopedServices = mockServices.filter( | ||
| (s) => s.organizationId === ctx.session.activeOrganizationId, | ||
| ); | ||
|
|
||
| if (!isPrivileged) { | ||
| const { accessedServices } = memberRecord; | ||
| if (accessedServices.length === 0) { | ||
| return { items: [], total: 0 }; | ||
| } | ||
| const items = orgScopedServices.filter((s) => | ||
| accessedServices.includes(s.id), | ||
| ); | ||
| return { items, total: items.length }; | ||
| } | ||
|
|
||
| // Privileged users (owner/admin) receive all services in the active organization | ||
| return { items: orgScopedServices, total: orgScopedServices.length }; | ||
| }; |
Contributor
There was a problem hiding this comment.
These tests exercise a local copy of the permission logic over hardcoded data instead of importing a changed router or production helper. An incorrect or missing exemption in any of the seven search procedures would therefore leave all five tests passing, so the authorization fix lacks effective regression coverage. Please exercise the production procedures or extract and directly test a shared production helper.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
Fixes #5361
Problem
compose.search(as well asapplication.search,postgres.search,mysql.search,mariadb.search,mongo.search, andredis.search) returned an incomplete list of services or 0 services for organization owners, administrators, and API key holders:project.search,environment.search,overview.services, andcheckServiceAccess(which exemptownerandadminroles), these service search procedures unconditionally filtered by the caller'saccessedServiceslist:accessedServicesat creation time viaaddNewService()for the specific user who created them.searchfor everyone else—including organization owners and admins—even though those services are fully accessible inproject.oneandcompose.one.Solution
Aligned all service search procedures with
project.search,environment.search, andoverview.servicesby checking whether the caller has anowneroradminrole:All queries remain strictly scoped to the active organization (
projects.organizationId = ctx.session.activeOrganizationId).Updated procedures:
apps/dokploy/server/api/routers/compose.ts(compose.search)apps/dokploy/server/api/routers/application.ts(application.search)apps/dokploy/server/api/routers/postgres.ts(postgres.search)apps/dokploy/server/api/routers/mysql.ts(mysql.search)apps/dokploy/server/api/routers/mariadb.ts(mariadb.search)apps/dokploy/server/api/routers/mongo.ts(mongo.search)apps/dokploy/server/api/routers/redis.ts(redis.search)Checklist
canarybranch.apps/dokploy/__test__/permissions/service-search-permissions.test.ts(5/5 passing tests).Issues related
Fixes #5361
The production authorization changes appear safe to merge, with a non-blocking test-quality issue that should be addressed to provide meaningful regression protection.
Summary
Reviews (1) · Last reviewed commit: "fix(permissions): exempt owners and admi..."