diff --git a/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/pii.ts b/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/pii.ts index 9d5c6be649a..9a3acd5d557 100644 --- a/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/pii.ts +++ b/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/pii.ts @@ -7,7 +7,8 @@ * schema for entity selection, output/result structures, and the async guardrail * check_fn for runtime enforcement. */ -import { safeRegex } from 'n8n-workflow'; +import { safeInternalRegex, safeUserRegex } from 'n8n-workflow'; +import type { RegexEngine } from 'n8n-workflow'; import { parseRegex } from '../../helpers/common'; import type { CreateCheckFn, CustomRegex } from '../types'; @@ -223,10 +224,14 @@ function detectPii(text: string, config: PIIConfig): PiiDetectionResult { const grouped: Record = {}; const analyzerResults: PiiAnalyzerResult[] = []; - const matchAgainstPattern = (name: string, literal: { source: string; flags: string }) => { + const matchAgainstPattern = ( + name: string, + literal: { source: string; flags: string }, + engine: RegexEngine = safeInternalRegex, + ) => { // make sure to add the global flag to the regex, otherwise while() will never end const flags = literal.flags.includes('g') ? literal.flags : literal.flags + 'g'; - const matches = safeRegex.matchAll(literal.source, text, flags); + const matches = engine.matchAll(literal.source, text, flags); for (const match of matches) { if (match.index === undefined) continue; @@ -256,7 +261,7 @@ function detectPii(text: string, config: PIIConfig): PiiDetectionResult { } if (config.customRegex?.length) { for (const regex of config.customRegex) { - matchAgainstPattern(regex.name, parseRegex(regex.value)); + matchAgainstPattern(regex.name, parseRegex(regex.value), safeUserRegex); } } diff --git a/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/secretKeys.ts b/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/secretKeys.ts index 470df64d37a..df0142f7691 100644 --- a/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/secretKeys.ts +++ b/packages/@n8n/nodes-langchain/nodes/Guardrails/actions/checks/secretKeys.ts @@ -6,7 +6,7 @@ * recognition, and a guardrail check_fn for runtime enforcement. */ -import { safeInternalRegex } from 'n8n-workflow'; +import { safeUserRegex } from 'n8n-workflow'; import type { CreateCheckFn, GuardrailResult } from '../types'; @@ -187,7 +187,7 @@ function isSecretCandidate( if (customRegex) { for (const pattern of customRegex) { try { - if (safeInternalRegex.test(pattern, s)) { + if (safeUserRegex.test(pattern, s)) { return true; } } catch {