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.

## 2026-07-02 - Bash Native Substring Matching vs Regex Evaluation
**Learning:** Evaluating regular expressions using `=~` inside a tight Bash loop (e.g., thousands of iterations) introduces considerable overhead due to the repeated regex compilation/matching. Replacing it with exact substring checking (via native globbing: `[[ "|$LIST|" == *"|$state|"* ]]`) is significantly faster.
**Action:** When filtering a large list in Bash against a set of delimited options, pre-pad the list and the candidate with a delimiter (like `|`), and use native substring matching (`== *"$candidate"*`) instead of regex evaluation. This can reduce loop processing time by ~60%.
10 changes: 8 additions & 2 deletions vpn-auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,26 @@ if [ -n "$US_SERVERS" ]; then
# Optimization: Use native bash parameter expansion and regex to extract state
# and filter servers instead of spawning 'cut' and 'grep' subshells in the loop.
# This avoids thousands of subshell forks and speeds up processing significantly.
# Pre-pad our delimited lists with pipes to enable robust exact substring matching
# ⚡ Bolt: Native substring check `[[ "|$LIST|" == *"|$state|"* ]]` is ~60% faster
# than regex evaluation `[[ "$state" =~ ^($LIST)$ ]]` inside tight Bash loops.
ex_match="|$EXCLUDED_STATES|"
fav_match="|$FAVORED_STATES|"

for server in $US_SERVERS; do
# Extract state code (e.g., US-WA#10 -> WA)
state="${server#US-}"
state="${state%%#*}"

# Check against exclusions
if [[ "$state" =~ ^($EXCLUDED_STATES)$ ]]; then
if [[ "$ex_match" == *"|$state|"* ]]; then
continue
fi

FILTERED_SERVERS+=("$server")

# Check against favorites
if [[ "$state" =~ ^($FAVORED_STATES)$ ]]; then
if [[ "$fav_match" == *"|$state|"* ]]; then
FAVORED_SERVERS+=("$server")
fi
done
Expand Down