Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useQuery, useMutation, UseMutationResult } from "@tanstack/react-query";
import { createQueryKeys } from "../common/queryKeysFactory";
import useAuthorized from "../useAuthorized";
import { isProxyAdminRole } from "@/utils/roles";
import { proxyBaseUrl, getGlobalLitellmHeaderName, deriveErrorMessage, handleError } from "@/components/networking";

/**
Expand Down Expand Up @@ -146,15 +147,15 @@ export const deleteProxyConfigFieldCall = async (
* @returns React Query result with the config list data
*/
export const useProxyConfig = (configType: ConfigType) => {
const { accessToken } = useAuthorized();
const { accessToken, userRole } = useAuthorized();
return useQuery<ProxyConfigResponse>({
queryKey: proxyConfigKeys.list({
filters: {
configType,
},
}),
queryFn: async () => await getProxyConfigCall(accessToken!, configType),
enabled: Boolean(accessToken),
enabled: Boolean(accessToken) && isProxyAdminRole(userRole ?? ""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Implicit coupling between formatted and raw role values

useAuthorized exposes userRole as the formatted display string (e.g., "Admin") via formatUserRole(decoded?.user_role), not the raw backend role (e.g., "proxy_admin"). This means isProxyAdminRole is being called with a formatted value here.

isProxyAdminRole is defined as:

export const isProxyAdminRole = (role: string): boolean => {
  return role === "proxy_admin" || role === "Admin";
};

The role === "proxy_admin" branch will never match in this call because userRole is always pre-formatted. The guard works only because the function also checks for "Admin" (the formatted form). This creates a silent dependency: if formatUserRole were updated to no longer map proxy_admin"Admin", or if isProxyAdminRole dropped the "Admin" branch, the guard would silently stop working for proxy_admin users.

Consider using useAuthorized's raw token instead, or explicitly documenting that isProxyAdminRole accepts formatted role strings:

Suggested change
enabled: Boolean(accessToken) && isProxyAdminRole(userRole ?? ""),
enabled: Boolean(accessToken) && isProxyAdminRole(userRole ?? ""),

Alternatively, expose a rawUserRole from useAuthorized (e.g., decoded?.user_role) so isProxyAdminRole can be called with the raw backend role it was designed for.

});
};

Expand Down
Loading