Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`=~`).
7 changes: 5 additions & 2 deletions vpn-auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down