Skip to content

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

use re2

x0322050a554febf97f
diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.ts
index 2027e6c10e..f7083cc040 100644
--- a/backend/src/ee/services/pam-account/pam-account-dal.ts
+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts
@@ -1,4 +1,5 @@
import { Knex } from "knex";
+import RE2 from "re2";
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
@@ -53,7 +54,10 @@ export const pamAccountDALFactory = (db: TDbClient) => {
if (search) {
// escape special characters (`%`, `_`) and the escape character itself (`\`)
- const escapedSearch = search.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
+ const escapedSearch = search
+ .replace(new RE2(/\\/g), "\\\\")
+ .replace(new RE2(/%/g), "\\%")
+ .replace(new RE2(/_/g), "\\_");
const pattern = `%${escapedSearch}%`;
void query.where((q) => {
void q
diff --git a/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts b/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts
index 179069fcf0..b59cb4b40b 100644
--- a/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts
+++ b/backend/src/ee/services/pam-discovery/pam-discovery-source-dal.ts
@@ -1,4 +1,5 @@
import { Knex } from "knex";
+import RE2 from "re2";
import { TDbClient } from "@app/db";
import { TableName, TPamDiscoverySources } from "@app/db/schemas";
@@ -42,7 +43,10 @@ export const pamDiscoverySourceDALFactory = (db: TDbClient) => {
if (search) {
// escape special characters (`%`, `_`) and the escape character itself (`\`)
- const escapedSearch = search.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
+ const escapedSearch = search
+ .replace(new RE2(/\\/g), "\\\\")
+ .replace(new RE2(/%/g), "\\%")
+ .replace(new RE2(/_/g), "\\_");
const pattern = `%${escapedSearch}%`;
void query.where((q) => {
void q
diff --git a/backend/src/ee/services/pam-folder/pam-folder-dal.ts b/backend/src/ee/services/pam-folder/pam-folder-dal.ts
index a21c401ffb..2fbeb7cc4c 100644
--- a/backend/src/ee/services/pam-folder/pam-folder-dal.ts
+++ b/backend/src/ee/services/pam-folder/pam-folder-dal.ts
@@ -1,4 +1,5 @@
import { Knex } from "knex";
+import RE2 from "re2";
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
@@ -44,7 +45,10 @@ export const pamFolderDALFactory = (db: TDbClient) => {
if (search) {
// escape special characters (`%`, `_`) and the escape character itself (`\`)
- const escapedSearch = search.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
+ const escapedSearch = search
+ .replace(new RE2(/\\/g), "\\\\")
+ .replace(new RE2(/%/g), "\\%")
+ .replace(new RE2(/_/g), "\\_");
void query.whereRaw(`??.?? ILIKE ? ESCAPE '\\'`, [TableName.PamFolder, "name", `%${escapedSearch}%`]);
}
diff --git a/backend/src/ee/services/pam-resource/pam-resource-dal.ts b/backend/src/ee/services/pam-resource/pam-resource-dal.ts
index ae262adb4f..00a319f042 100644
--- a/backend/src/ee/services/pam-resource/pam-resource-dal.ts
+++ b/backend/src/ee/services/pam-resource/pam-resource-dal.ts
@@ -1,4 +1,5 @@
import { Knex } from "knex";
+import RE2 from "re2";
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
@@ -50,7 +51,10 @@ export const pamResourceDALFactory = (db: TDbClient) => {
if (search) {
// escape special characters (`%`, `_`) and the escape character itself (`\`)
- const escapedSearch = search.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
+ const escapedSearch = search
+ .replace(new RE2(/\\/g), "\\\\")
+ .replace(new RE2(/%/g), "\\%")
+ .replace(new RE2(/_/g), "\\_");
const pattern = `%${escapedSearch}%`;
void query.where((q) => {
void q