Skip to content

Commit d58eacd

Browse files
committed
fix: harden script robustness, security, and CI lint gates
Security & injection hardening: - Add safeQuoteParam() and serializeParams() to safely quote all params file values, preventing shell injection when sourced - Add validateParamsFile() with ownership (root) and permission (600/400) checks before sourcing the params file - Validate CLIENT_NAME against ^[a-zA-Z0-9_-]+$ before sed interpolation in revokeClient() and regenerateClients() to prevent regex injection Input validation & defensive checks: - Reset all interactive variables in installQuestions() and manageMenu() to prevent pre-set environment variables from bypassing prompt loops - Guard /etc/os-release with existence/readability check in checkOS() - Guard VERSION_ID emptiness for all distro branches before comparison - Extract major version via cut before -lt to handle point-release formats - Add return-code check for serializeParams during install IPv6 improvements: - Add isValidIPv6() and normalizeIPv6() for robust IPv6 handling - Normalize IPv6 at storage and comparison points to prevent duplicates - Add semantic IPv6 duplicate detection for client creation Migration (pre-2.0 to 2.0): - Add migrateS3S4() and migrateH1H4() with validation and fallback - Add persistMigration() with backup/restore, atomic writes, user confirmation, and old client config renaming - Add quietIPv6Rewrite() for cosmetic IPv6 normalization without triggering migration warnings Off-by-one fixes: - Fix RANGE_SIZE arithmetic in generateH1AndH2AndH3AndH4Ranges() (use RANGE_SIZE - 1 for inclusive upper bounds) Global state cleanup: - Replace global HOME_DIR with local in getHomeDirForClient(), newClient(), revokeClient(), and regenerateClients() - Declare RELEASE_YEAR, DEBIAN_MAJOR, FEDORA_MAJOR as local in checkOS() UX consistency: - Accept [yY] for uninstall confirmation, matching migration prompt CI: - Add nounset-check job (bash -u -n) to lint.yml to catch undefined variable regressions
1 parent bd57f88 commit d58eacd

2 files changed

Lines changed: 1096 additions & 416 deletions

File tree

.github/workflows/lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Shell Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
syntax-check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Bash syntax check
16+
run: bash -n amneziawg-install.sh
17+
18+
shellcheck:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install ShellCheck
24+
run: sudo apt-get update && sudo apt-get install -y shellcheck
25+
26+
- name: Run ShellCheck
27+
run: shellcheck --severity=error amneziawg-install.sh
28+
29+
nounset-check:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Check for undefined variable regressions (set -u)
35+
run: bash -u -n amneziawg-install.sh

0 commit comments

Comments
 (0)