diff --git a/.jules/bolt.md b/.jules/bolt.md index 8bff3f7..e6e0155 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -8,3 +8,7 @@ ## 2024-06-28 - Secure Native File Traversal Optimization **Learning:** Shelling out to `chown -R` via `os.system` incurs significant process spawning overhead and forces redundant directory traversals when modifying multiple permissions. However, directly replacing it with Python's native `os.chown` inside an `os.walk` loop introduces a critical Local Privilege Escalation (LPE) vulnerability, as `os.chown` follows symlinks by default whereas GNU `chown -R` does not. **Action:** When replacing `os.system("chown -R ...")` with native `os.walk` in Python scripts, always use `os.lchown` on files and directories to ensure symlinks are not maliciously followed, preserving the security guarantees of the original subprocess call while eliminating overhead. + +## 2024-05-16 - Regex Compilation Overhead in Tight Bash Loops +**Learning:** Using bash regular expression matching (`=~`) inside a loop introduces significant overhead due to regex compilation on every evaluation compared to glob substring matching. +**Action:** For optimal performance in tight Bash loops where simple substring matching is sufficient, prefer native glob matching (e.g., `[[ "|$LIST|" == *"|$item|"* ]]`) over regex evaluation (`=~`). diff --git a/vpn-auto.sh b/vpn-auto.sh index b8c1dc2..8dbf48b 100755 --- a/vpn-auto.sh +++ b/vpn-auto.sh @@ -84,14 +84,17 @@ if [ -n "$US_SERVERS" ]; then state="${state%%#*}" # Check against exclusions - if [[ "$state" =~ ^($EXCLUDED_STATES)$ ]]; then + # ⚡ Bolt: Using native glob substring matching instead of bash regex '=~' + # avoids regex compilation overhead, speeding up processing in tight loops. + if [[ "|$EXCLUDED_STATES|" == *"|$state|"* ]]; then continue fi FILTERED_SERVERS+=("$server") # Check against favorites - if [[ "$state" =~ ^($FAVORED_STATES)$ ]]; then + # ⚡ Bolt: Using native glob substring matching instead of bash regex '=~' + if [[ "|$FAVORED_STATES|" == *"|$state|"* ]]; then FAVORED_SERVERS+=("$server") fi done