From 048339a6aacd09adc187f46484f1ceb90dfef371 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 8 Jun 2024 14:32:28 +0200 Subject: [PATCH] [bugfix] Use re2 syntax for regex validation (#2978) --- web/source/package.json | 1 + .../views/admin/http-header-permissions/create.tsx | 9 +++++---- .../views/admin/http-header-permissions/detail.tsx | 2 +- web/source/yarn.lock | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/source/package.json b/web/source/package.json index 230c248ad..e90176308 100644 --- a/web/source/package.json +++ b/web/source/package.json @@ -27,6 +27,7 @@ "photoswipe-dynamic-caption-plugin": "^1.2.7", "plyr": "^3.7.8", "psl": "^1.9.0", + "re2js": "^0.4.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-redux": "^8.1.3", diff --git a/web/source/settings/views/admin/http-header-permissions/create.tsx b/web/source/settings/views/admin/http-header-permissions/create.tsx index b791ae0a9..6613ac0f1 100644 --- a/web/source/settings/views/admin/http-header-permissions/create.tsx +++ b/web/source/settings/views/admin/http-header-permissions/create.tsx @@ -24,6 +24,7 @@ import useFormSubmit from "../../../lib/form/submit"; import { TextInput } from "../../../components/form/inputs"; import MutationButton from "../../../components/form/mutation-button"; import { PermType } from "../../../lib/types/perm"; +import { RE2JS } from "re2js"; export default function HeaderPermCreateForm({ permType }: { permType: PermType }) { const form = { @@ -56,7 +57,7 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType // Ensure regex compiles. try { - new RegExp(val); + RE2JS.compile(val); } catch (e) { return e; } @@ -116,14 +117,14 @@ export default function HeaderPermCreateForm({ permType }: { permType: PermType field={form.regex} label={ <> - HTTP Header Value Regex  + HTTP Header Value RE2 Regex  - Learn more about regular expressions (opens in a new tab) + Learn more about RE2 regular expressions (opens in a new tab) } diff --git a/web/source/settings/views/admin/http-header-permissions/detail.tsx b/web/source/settings/views/admin/http-header-permissions/detail.tsx index db92dd0eb..456f9a357 100644 --- a/web/source/settings/views/admin/http-header-permissions/detail.tsx +++ b/web/source/settings/views/admin/http-header-permissions/detail.tsx @@ -154,7 +154,7 @@ function PermDeets({ // with this regular expression prepopulated. const testParams = new URLSearchParams(); testParams.set("regex", perm.regex); - testParams.set("flags", "g"); + testParams.set("flags", "gm"); testParams.set("testString", testString); const regexLink = `https://regex101.com/?${testParams.toString()}`; diff --git a/web/source/yarn.lock b/web/source/yarn.lock index 71187718f..ce662205e 100644 --- a/web/source/yarn.lock +++ b/web/source/yarn.lock @@ -5513,6 +5513,11 @@ raw-body@~1.1.0: bytes "1" string_decoder "0.10" +re2js@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/re2js/-/re2js-0.4.1.tgz#74a87a90b79ab5dc1effed818151354c8faccb3d" + integrity sha512-Kxb+OKXrEPowP4bXAF07NDXtgYX07S8HeVGgadx5/D/R41LzWg1kgTD2szIv2iHJM3vrAPnDKaBzfUE/7QWX9w== + react-dom@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"