From 63d2f159890879285b42230266846f418ffb78ca Mon Sep 17 00:00:00 2001 From: alphaeusmote <41258468-alphaeusmote@users.noreply.replit.com> Date: Tue, 8 Apr 2025 20:48:07 +0000 Subject: [PATCH] Improve LDAP query builder page and enhance API security. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/1a0cae6d-1419-4e33-945a-4f87737719de.jpg --- client/src/pages/ldap-query-builder-page.tsx | 12 ++++++------ server/ldap-query-builder-routes.ts | 11 ++++++++--- server/storage.ts | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/client/src/pages/ldap-query-builder-page.tsx b/client/src/pages/ldap-query-builder-page.tsx index 251a976..e3f3442 100644 --- a/client/src/pages/ldap-query-builder-page.tsx +++ b/client/src/pages/ldap-query-builder-page.tsx @@ -226,15 +226,15 @@ export default function LdapQueryBuilderPage() { const queriesColumns = [ { header: "Name", - accessorKey: "name", + accessorKey: "name" as keyof LdapQuery, }, { header: "Description", - accessorKey: "description", + accessorKey: "description" as keyof LdapQuery, }, { header: "Target", - accessorKey: "targetObject", + accessorKey: "targetObject" as keyof LdapQuery, cell: (row: LdapQuery) => { const targets: Record = { users: "Users", @@ -247,13 +247,13 @@ export default function LdapQueryBuilderPage() { }, { header: "Last Updated", - accessorKey: "updatedAt", + accessorKey: "updatedAt" as keyof LdapQuery, cell: (row: LdapQuery) => row.updatedAt ? format(new Date(row.updatedAt), "MMM dd, yyyy HH:mm") : "", }, { header: "", - accessorKey: "id", + accessorKey: "id" as keyof LdapQuery, cell: (row: LdapQuery) => ( @@ -294,7 +294,7 @@ export default function LdapQueryBuilderPage() { const firstResult = testResults[0]; return Object.keys(firstResult).map(key => ({ header: key, - accessorKey: key, + accessorKey: key as keyof typeof firstResult, cell: (row: any) => { const value = row[key]; if (value === null || value === undefined) return "-"; diff --git a/server/ldap-query-builder-routes.ts b/server/ldap-query-builder-routes.ts index 8bc344b..e23fb8e 100644 --- a/server/ldap-query-builder-routes.ts +++ b/server/ldap-query-builder-routes.ts @@ -13,9 +13,14 @@ import { InsertLdapQuery, LdapQuery, InsertLdapQueryVersion } from "@shared/sche // Use middleware to check permissions function hasPermission(permission: string) { return (req: any, res: any, next: any) => { - // For now, we'll just allow all requests through - // In a real implementation, this would check the user's permissions - return next(); + // Check if the user is authenticated via passport session or has a valid API token + if (req.user || req.headers.authorization) { + // In a real implementation, this would check the user's permissions against the required permission + return next(); + } + + // If not authenticated, return 401 Unauthorized + return res.status(401).json({ error: "Unauthorized" }); }; } diff --git a/server/storage.ts b/server/storage.ts index 5e0736a..2c9379b 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -385,21 +385,21 @@ export class DatabaseStorage implements IStorage { // Apply where conditions if any if (whereClause) { - baseQuery = baseQuery.where(whereClause); + baseQuery = baseQuery.where(whereClause as any); } // Apply ordering if any if (orderClauses.length > 0) { - baseQuery = baseQuery.orderBy(...orderClauses); + baseQuery = baseQuery.orderBy(...orderClauses as any[]); } // Apply pagination if specified if (limit !== undefined) { - baseQuery = baseQuery.limit(limit); + baseQuery = baseQuery.limit(limit as any); } if (offset !== undefined) { - baseQuery = baseQuery.offset(offset); + baseQuery = baseQuery.offset(offset as any); } // Execute the query @@ -411,7 +411,7 @@ export class DatabaseStorage implements IStorage { const filtered: Partial = { id: user.id }; selectedFields.forEach(field => { if (field in user) { - filtered[field as keyof AdUser] = user[field as keyof AdUser]; + filtered[field as keyof AdUser] = user[field as keyof AdUser] as any; } }); return filtered as AdUser; @@ -474,21 +474,21 @@ export class DatabaseStorage implements IStorage { // Apply where conditions if any if (whereClause) { - baseQuery = baseQuery.where(whereClause); + baseQuery = baseQuery.where(whereClause as any); } // Apply ordering if any if (orderClauses.length > 0) { - baseQuery = baseQuery.orderBy(...orderClauses); + baseQuery = baseQuery.orderBy(...orderClauses as any[]); } // Apply pagination if specified if (limit !== undefined) { - baseQuery = baseQuery.limit(limit); + baseQuery = baseQuery.limit(limit as any); } if (offset !== undefined) { - baseQuery = baseQuery.offset(offset); + baseQuery = baseQuery.offset(offset as any); } // Execute the query @@ -500,7 +500,7 @@ export class DatabaseStorage implements IStorage { const filtered: Partial = { id: group.id }; selectedFields.forEach(field => { if (field in group) { - filtered[field as keyof AdGroup] = group[field as keyof AdGroup]; + filtered[field as keyof AdGroup] = group[field as keyof AdGroup] as any; } }); return filtered as AdGroup;