From f711f8a35c5b775c528d8196ccf6c0960d2d94b7 Mon Sep 17 00:00:00 2001 From: x032205 Date: Sat, 31 May 2025 01:14:37 -0400 Subject: [PATCH] Finishing touches + undo RE2 removal --- .github/workflows/check-non-re2-regex.yml | 9 ++------- .../secret-sync/hc-vault/hc-vault-sync-schemas.ts | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-non-re2-regex.yml b/.github/workflows/check-non-re2-regex.yml index b4bccb753..11d8ea037 100644 --- a/.github/workflows/check-non-re2-regex.yml +++ b/.github/workflows/check-non-re2-regex.yml @@ -15,29 +15,24 @@ jobs: - name: Get diff of backend/* run: | - echo "Fetching base ref: ${{ github.base_ref }}" - - echo "Generating diff for backend/ directory against origin/${{ github.base_ref }}" git diff --unified=0 "origin/${{ github.base_ref }}"...HEAD -- backend/ > diff.txt - name: Scan backend diff for non-RE2 regex run: | - echo "Scanning added/modified lines in backend/ for raw regex literals..." grep '^+' diff.txt | grep -v '^+++' | sed 's/^\+//' > added_lines.txt if [ ! -s added_lines.txt ]; then - echo "No relevant lines added or modified in backend/ found in the diff." echo "✅ No raw regex literals to check in backend." exit 0 fi raw_regex_pattern='(^|[^A-Za-z0-9_])\/[^\/]+\/[gimsuy]*' - # First, find all added lines that contain the raw_regex_pattern. + # Find all added lines that contain the raw_regex_pattern. grep -E "$raw_regex_pattern" added_lines.txt > potential_violations.txt if [ -s potential_violations.txt ]; then # If any lines match the raw regex pattern - # From these potential violations, filter out lines that also contain the string 'new RE2'. + # Filter out lines that also contain the string 'new RE2'. grep -v 'new RE2' potential_violations.txt > actual_violations.txt if [ -s actual_violations.txt ]; then # If there are lines left after filtering out 'new RE2' diff --git a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-schemas.ts b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-schemas.ts index 5a5af935d..f9096ac71 100644 --- a/backend/src/services/secret-sync/hc-vault/hc-vault-sync-schemas.ts +++ b/backend/src/services/secret-sync/hc-vault/hc-vault-sync-schemas.ts @@ -23,7 +23,7 @@ const HCVaultSyncDestinationConfigSchema = z.object({ .trim() .min(1, "Path required") .max(128) - .transform((val) => val.replace(/^\/+|\/+$/g, "")) // removes leading/trailing slashes + .transform((val) => new RE2("^/+|/+$", "g").replace(val, "")) // removes leading/trailing slashes .refine((val) => new RE2("^([a-zA-Z0-9._-]+/)*[a-zA-Z0-9._-]+$").test(val), { message: "Invalid Vault path format. Use alphanumerics, dots, dashes, underscores, and single slashes between segments."