Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: minimal pii filtering

Sheen Capadngancfb5b9aa6bb6
diff --git a/backend/src/db/migrations/20251204160117_add-ai-mcp-product.ts b/backend/src/db/migrations/20251204160117_add-ai-mcp-product.ts
index dbd1923562..09152eddbb 100644
--- a/backend/src/db/migrations/20251204160117_add-ai-mcp-product.ts
+++ b/backend/src/db/migrations/20251204160117_add-ai-mcp-product.ts
@@ -40,6 +40,7 @@ export async function up(knex: Knex): Promise<void> {
t.string("name").notNullable();
t.string("description");
t.string("status");
+ t.boolean("piiFiltering").defaultTo(false).notNullable();
t.string("projectId").notNullable();
t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");
t.timestamps(true, true, true);
diff --git a/backend/src/db/schemas/ai-mcp-endpoints.ts b/backend/src/db/schemas/ai-mcp-endpoints.ts
index b2c66987fb..9b4e73f0ad 100644
--- a/backend/src/db/schemas/ai-mcp-endpoints.ts
+++ b/backend/src/db/schemas/ai-mcp-endpoints.ts
@@ -12,6 +12,7 @@ export const AiMcpEndpointsSchema = z.object({
name: z.string(),
description: z.string().nullable().optional(),
status: z.string().nullable().optional(),
+ piiFiltering: z.boolean().default(false),
projectId: z.string(),
createdAt: z.date(),
updatedAt: z.date()
diff --git a/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts b/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
index 2841b0aa89..969193b7ad 100644
--- a/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
+++ b/backend/src/ee/routes/v1/ai-mcp-endpoint-router.ts
@@ -163,7 +163,8 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
endpoints: z.array(
AiMcpEndpointsSchema.extend({
connectedServers: z.number(),
- activeTools: z.number()
+ activeTools: z.number(),
+ piiFiltering: z.boolean().optional()
})
),
totalCount: z.number()
@@ -198,7 +199,8 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
endpoint: AiMcpEndpointsSchema.extend({
connectedServers: z.number(),
activeTools: z.number(),
- serverIds: z.array(z.string())
+ serverIds: z.array(z.string()),
+ piiFiltering: z.boolean().optional()
})
})
}
@@ -226,7 +228,8 @@ export const registerAiMcpEndpointRouter = async (server: FastifyZodProvider) =>
body: z.object({
name: z.string().trim().min(1).max(64).optional(),
description: z.string().trim().max(256).optional(),
- serverIds: z.array(z.string().uuid()).optional()
+ serverIds: z.array(z.string().uuid()).optional(),
+ piiFiltering: z.boolean().optional()
}),
response: {
200: z.object({
diff --git a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
index 2df81e2dfd..1877db0b61 100644
--- a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
+++ b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-service.ts
@@ -124,6 +124,39 @@ export const aiMcpEndpointServiceFactory = ({
authTokenService,
userDAL
}: TAiMcpEndpointServiceFactoryDep) => {
+ // PII filtering utility - redacts sensitive information
+ const applyPiiFiltering = (data: unknown): unknown => {
+ if (typeof data === "string") {
+ let filtered = data;
+
+ // Redact SSN (matches formats: 123-45-6789, 123456789)
+ filtered = filtered.replace(/\b\d{3}-?\d{2}-?\d{4}\b/g, "<REDACTED>");
+
+ // Redact Phone Numbers (matches various formats)
+ // Matches: (123) 456-7890, 123-456-7890, 123.456.7890, 1234567890, +1 123 456 7890
+ filtered = filtered.replace(/(\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g, "<REDACTED>");
+
+ // Redact Email Addresses
+ filtered = filtered.replace(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, "<REDACTED>");
+
+ return filtered;
+ }
+
+ if (Array.isArray(data)) {
+ return data.map((item) => applyPiiFiltering(item));
+ }
+
+ if (data && typeof data === "object") {
+ const filtered: Record<string, unknown> = {};
+ for (const [key, value] of Object.entries(data)) {
+ filtered[key] = applyPiiFiltering(value);
+ }
+ return filtered;
+ }
+
+ return data;
+ };
+
const interactWithMcp = async ({ endpointId, userId }: TInteractWithMcpDTO) => {
const appCfg = getConfig();
@@ -273,22 +306,28 @@ export const aiMcpEndpointServiceFactory = ({
}
try {
+ // Apply PII filtering to arguments if enabled
+ const filteredArgs = endpoint.piiFiltering ? applyPiiFiltering(args) : args;
+
const result = await selectedMcpClient.client.callTool({
name,
- arguments: args
+ arguments: filteredArgs
});
+ // Apply PII filtering to result if enabled
+ const filteredResult = endpoint.piiFiltering ? applyPiiFiltering(result) : result;
+
await aiMcpActivityLogService.createActivityLog({
endpointName: endpoint.name,
serverName: selectedMcpClient.server.name,
toolName: name,
actor: user.email || "",
- request: args,
- response: result,
+ request: filteredArgs, // Log filtered args
+ response: filteredResult, // Log filtered response
projectId: endpoint.projectId
});
- return result;
+ return filteredResult as Record<string, unknown>;
} catch (error) {
return {
content: [
@@ -368,15 +407,22 @@ export const aiMcpEndpointServiceFactory = ({
};
};
- const updateMcpEndpoint = async ({ endpointId, name, description, serverIds }: TUpdateAiMcpEndpointDTO) => {
+ const updateMcpEndpoint = async ({
+ endpointId,
+ name,
+ description,
+ serverIds,
+ piiFiltering
+ }: TUpdateAiMcpEndpointDTO) => {
const endpoint = await aiMcpEndpointDAL.findById(endpointId);
if (!endpoint) {
throw new NotFoundError({ message: `MCP endpoint with ID '${endpointId}' not found` });
}
- const updateData: { name?: string; description?: string } = {};
+ const updateData: { name?: string; description?: string; piiFiltering?: boolean } = {};
if (name !== undefined) updateData.name = name;
if (description !== undefined) updateData.description = description;
+ if (piiFiltering !== undefined) updateData.piiFiltering = piiFiltering;
let updatedEndpoint = endpoint;
if (Object.keys(updateData).length > 0) {
diff --git a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
index 341716305e..c97e3adb44 100644
--- a/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
+++ b/backend/src/ee/services/ai-mcp-endpoint/ai-mcp-endpoint-types.ts
@@ -10,6 +10,7 @@ export type TUpdateAiMcpEndpointDTO = {
name?: string;
description?: string;
serverIds?: string[];
+ piiFiltering?: boolean;
};
export type TDeleteAiMcpEndpointDTO = {
@@ -34,6 +35,7 @@ export type TAiMcpEndpointWithServers = {
name: string;
description?: string | null;
status?: string | null;
+ piiFiltering?: boolean;
projectId: string;
createdAt: Date;
updatedAt: Date;
diff --git a/frontend/src/hooks/api/aiMcpEndpoints/types.ts b/frontend/src/hooks/api/aiMcpEndpoints/types.ts
index 34dbef6b3e..13be5040f2 100644
--- a/frontend/src/hooks/api/aiMcpEndpoints/types.ts
+++ b/frontend/src/hooks/api/aiMcpEndpoints/types.ts
@@ -3,6 +3,7 @@ export type TAiMcpEndpoint = {
name: string;
description: string | null;
status: string | null;
+ piiFiltering?: boolean;
projectId: string;
createdAt: string;
updatedAt: string;
@@ -26,6 +27,7 @@ export type TUpdateAiMcpEndpointDTO = {
name?: string;
description?: string;
serverIds?: string[];
+ piiFiltering?: boolean;
};
export type TDeleteAiMcpEndpointDTO = {
diff --git a/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
index cff735b56a..e8faea10d7 100644
--- a/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
+++ b/frontend/src/pages/ai/MCPEndpointDetailPage/components/MCPEndpointDetailsSection.tsx
@@ -1,9 +1,10 @@
-import { faEdit } from "@fortawesome/free-solid-svg-icons";
+import { faEdit, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { format } from "date-fns";
-import { GenericFieldLabel, IconButton } from "@app/components/v2";
-import { TAiMcpEndpointWithServerIds } from "@app/hooks/api";
+import { createNotification } from "@app/components/notifications";
+import { GenericFieldLabel, IconButton, Switch, Tooltip } from "@app/components/v2";
+import { TAiMcpEndpointWithServerIds, useUpdateAiMcpEndpoint } from "@app/hooks/api";
type Props = {
endpoint: TAiMcpEndpointWithServerIds;
@@ -27,6 +28,27 @@ const getStatusColor = (status: string | null) => {
};
export const MCPEndpointDetailsSection = ({ endpoint, onEdit }: Props) => {
+ const updateEndpoint = useUpdateAiMcpEndpoint();
+
+ const handlePiiFilteringToggle = async (checked: boolean) => {
+ try {
+ await updateEndpoint.mutateAsync({
+ endpointId: endpoint.id,
+ piiFiltering: checked
+ });
+ createNotification({
+ text: `PII filtering ${checked ? "enabled" : "disabled"} successfully`,
+ type: "success"
+ });
+ } catch (error) {
+ console.error("Failed to update PII filtering:", error);
+ createNotification({
+ text: "Failed to update PII filtering setting",
+ type: "error"
+ });
+ }
+ };
+
return (
<div className="flex w-full flex-col gap-3 rounded-lg border border-mineshaft-600 bg-mineshaft-900 px-4 py-3">
<div className="flex items-center justify-between border-b border-mineshaft-400 pb-2">
@@ -54,6 +76,31 @@ export const MCPEndpointDetailsSection = ({ endpoint, onEdit }: Props) => {
<GenericFieldLabel label="Created">
{format(new Date(endpoint.createdAt), "yyyy-MM-dd, hh:mm aaa")}
</GenericFieldLabel>
+ <div className="border-t border-mineshaft-500 pt-3">
+ <div className="flex items-start justify-between">
+ <div className="flex flex-col gap-0.5">
+ <div className="flex items-center gap-2">
+ <span className="text-sm font-medium text-mineshaft-200">PII Filtering</span>
+ <Tooltip
+ content="When enabled, personally identifiable information (credit cards, addresses, phone numbers, etc.) will be redacted in requests and responses"
+ className="max-w-xs"
+ >
+ <FontAwesomeIcon
+ icon={faInfoCircle}
+ className="cursor-default text-bunker-400 hover:text-bunker-300"
+ />
+ </Tooltip>
+ </div>
+ <span className="text-xs text-bunker-400">Redact sensitive data</span>
+ </div>
+ <Switch
+ id={`pii-filtering-${endpoint.id}`}
+ isChecked={endpoint.piiFiltering ?? false}
+ onCheckedChange={handlePiiFilteringToggle}
+ isDisabled={updateEndpoint.isPending}
+ />
+ </div>
+ </div>
</div>
</div>
);