Skip to content

Commit 347902c

Browse files
Copilothsluoyz
andcommitted
fix: escape regex special characters in pType for pattern matching
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
1 parent 46df84f commit 347902c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/coreEnforcer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ export class CoreEnforcer {
502502
// Check if the matcher references policy tokens (e.g., p.sub, p.obj, p2.sub)
503503
// Note: escapeAssertion transforms "p." to "p_", so we check for "p_" or "p<digit>_" in the escaped expression
504504
// If the matcher doesn't reference policy tokens, we can skip policy iteration (no-policy ABAC)
505-
const policyTokenPattern = new RegExp(`${enforceContext.pType}\\d*_`);
505+
const escapedPType = enforceContext.pType.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
506+
const policyTokenPattern = new RegExp(`${escapedPType}\\d*_`);
506507
const matcherUsesPolicyTokens = policyTokenPattern.test(expString);
507508

508509
if (policyLen && policyLen !== 0 && matcherUsesPolicyTokens) {

0 commit comments

Comments
 (0)