mirror of
https://github.com/prowler-cloud/prowler.git
synced 2025-12-19 05:17:47 +00:00
fix: add filters for mongo providers and findings (#9311)
This commit is contained in:
@@ -4,6 +4,61 @@ import { redirect } from "next/navigation";
|
||||
|
||||
import { apiBaseUrl, getAuthHeaders } from "@/lib";
|
||||
import { handleApiResponse } from "@/lib/server-actions-helper";
|
||||
import { FindingsResponse } from "@/types";
|
||||
|
||||
interface IncludedItem {
|
||||
type: string;
|
||||
id: string;
|
||||
attributes?: { provider?: string };
|
||||
relationships?: { provider?: { data?: { id: string } } };
|
||||
}
|
||||
|
||||
type FindingsApiResponse = FindingsResponse & {
|
||||
included?: IncludedItem[];
|
||||
};
|
||||
|
||||
const filterMongoFindings = <T extends FindingsApiResponse | null | undefined>(
|
||||
result: T,
|
||||
): T => {
|
||||
if (!result?.data) return result;
|
||||
|
||||
const included = (result as FindingsApiResponse).included || [];
|
||||
|
||||
// Get IDs of providers containing "mongo" in included items
|
||||
const mongoProviderIds = new Set(
|
||||
included
|
||||
.filter(
|
||||
(item) =>
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo"),
|
||||
)
|
||||
.map((item) => item.id),
|
||||
);
|
||||
|
||||
// Filter out findings associated with mongo providers
|
||||
result.data = result.data.filter((finding) => {
|
||||
const scanId = finding.relationships?.scan?.data?.id;
|
||||
// Find the scan in included items
|
||||
const scan = included.find(
|
||||
(item) => item.type === "scans" && item.id === scanId,
|
||||
);
|
||||
const providerId = scan?.relationships?.provider?.data?.id;
|
||||
return !providerId || !mongoProviderIds.has(providerId);
|
||||
});
|
||||
|
||||
// Filter out mongo-related included items
|
||||
if ((result as FindingsApiResponse).included) {
|
||||
(result as FindingsApiResponse).included = included.filter(
|
||||
(item) =>
|
||||
!(
|
||||
item.type === "providers" &&
|
||||
item.attributes?.provider?.toLowerCase().includes("mongo")
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getFindings = async ({
|
||||
page = 1,
|
||||
@@ -33,7 +88,10 @@ export const getFindings = async ({
|
||||
const findings = await fetch(url.toString(), {
|
||||
headers,
|
||||
});
|
||||
return handleApiResponse(findings);
|
||||
|
||||
const result = await handleApiResponse(findings);
|
||||
|
||||
return filterMongoFindings(result);
|
||||
} catch (error) {
|
||||
console.error("Error fetching findings:", error);
|
||||
return undefined;
|
||||
@@ -70,7 +128,10 @@ export const getLatestFindings = async ({
|
||||
const findings = await fetch(url.toString(), {
|
||||
headers,
|
||||
});
|
||||
return handleApiResponse(findings);
|
||||
|
||||
const result = await handleApiResponse(findings);
|
||||
|
||||
return filterMongoFindings(result);
|
||||
} catch (error) {
|
||||
console.error("Error fetching findings:", error);
|
||||
return undefined;
|
||||
|
||||
@@ -39,7 +39,26 @@ export const getProviders = async ({
|
||||
headers,
|
||||
});
|
||||
|
||||
return handleApiResponse(response);
|
||||
const result = (await handleApiResponse(response)) as
|
||||
| ProvidersApiResponse
|
||||
| undefined;
|
||||
|
||||
if (result?.data) {
|
||||
// Filter out providers with provider type containing "mongo"
|
||||
result.data = result.data.filter(
|
||||
(provider) =>
|
||||
!provider.attributes?.provider?.toLowerCase().includes("mongo"),
|
||||
);
|
||||
|
||||
// Also filter out mongo-related included items if present
|
||||
if (result.included) {
|
||||
result.included = result.included.filter(
|
||||
(item) => !item.type.toLowerCase().includes("mongo"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error fetching providers:", error);
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user