Skip to content

Commit e098f6e

Browse files
sunny-seclaude
andcommitted
Preserve self-update with SHA-256 integrity verification
Instead of removing script_self_update() entirely, restore it with hardening: HTTPS-only fetch (pairs with PR #13) + SHA-256 checksum verification against a .sha256 sidecar file. Silently skips update if checksum fetch fails or hash mismatch — never overwrites with unverified content. Requires publishing .sha256 sidecar files alongside each script. DEVA11Y-475 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ecd1c1a commit e098f6e

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

scripts/bash/cli.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,29 @@ a11y_scan() {
7878
$BINARY_PATH a11y $EXTRA_ARGS
7979
}
8080

81+
script_self_update() {
82+
local remote_url="https://raw.githubusercontent.com/browserstack/AccessibilityDevTools/refs/heads/main/scripts/bash/cli.sh"
83+
local checksum_url="${remote_url}.sha256"
84+
85+
local updated_script
86+
updated_script=$(curl -sfSL "$remote_url") || return 0
87+
local expected_hash
88+
expected_hash=$(curl -sfSL "$checksum_url" | awk '{print $1}') || return 0
89+
90+
local actual_hash
91+
actual_hash=$(printf '%s' "$updated_script" | shasum -a 256 | awk '{print $1}')
92+
93+
if [[ -n "$expected_hash" ]] && [[ "$actual_hash" == "$expected_hash" ]] && [[ $updated_script =~ ^#! ]]; then
94+
echo "$updated_script" > "$SCRIPT_PATH"
95+
fi
96+
}
97+
8198
download_binary() {
8299
curl -R -z "$BINARY_ZIP_PATH" -L "http://api.browserstack.com/sdk/v1/download_cli?os=${OS}&os_arch=${ARCH}" -o "$BINARY_ZIP_PATH"
83100
bsdtar -xvf "$BINARY_ZIP_PATH" -O > "$BINARY_PATH" && chmod 0775 "$BINARY_PATH"
84101
}
85102

103+
script_self_update
86104
if [[ $SUBCOMMAND == "register-pre-commit-hook" ]]; then
87105
register_git_hook
88106
exit 0

scripts/fish/cli.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,29 @@ a11y_scan() {
9090
$BINARY_PATH a11y $EXTRA_ARGS
9191
}
9292

93+
script_self_update() {
94+
local remote_url="https://raw.githubusercontent.com/browserstack/AccessibilityDevTools/refs/heads/main/scripts/fish/cli.sh"
95+
local checksum_url="${remote_url}.sha256"
96+
97+
local updated_script
98+
updated_script=$(curl -sfSL "$remote_url") || return 0
99+
local expected_hash
100+
expected_hash=$(curl -sfSL "$checksum_url" | awk '{print $1}') || return 0
101+
102+
local actual_hash
103+
actual_hash=$(printf '%s' "$updated_script" | shasum -a 256 | awk '{print $1}')
104+
105+
if [[ -n "$expected_hash" ]] && [[ "$actual_hash" == "$expected_hash" ]] && [[ $updated_script =~ ^#! ]]; then
106+
echo "$updated_script" > "$SCRIPT_PATH"
107+
fi
108+
}
109+
93110
download_binary() {
94111
curl -R -z "$BINARY_ZIP_PATH" -L "http://api.browserstack.com/sdk/v1/download_cli?os=${OS}&os_arch=${ARCH}" -o "$BINARY_ZIP_PATH"
95112
bsdtar -xvf "$BINARY_ZIP_PATH" -O > "$BINARY_PATH" && chmod 0775 "$BINARY_PATH"
96113
}
97114

115+
script_self_update
98116
if [[ $SUBCOMMAND == "register-pre-commit-hook" ]]; then
99117
register_git_hook
100118
exit 0

scripts/zsh/cli.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,29 @@ a11y_scan() {
8989
$BINARY_PATH a11y $EXTRA_ARGS
9090
}
9191

92+
script_self_update() {
93+
local remote_url="https://raw.githubusercontent.com/browserstack/AccessibilityDevTools/refs/heads/main/scripts/zsh/cli.sh"
94+
local checksum_url="${remote_url}.sha256"
95+
96+
local updated_script
97+
updated_script=$(curl -sfSL "$remote_url") || return 0
98+
local expected_hash
99+
expected_hash=$(curl -sfSL "$checksum_url" | awk '{print $1}') || return 0
100+
101+
local actual_hash
102+
actual_hash=$(printf '%s' "$updated_script" | shasum -a 256 | awk '{print $1}')
103+
104+
if [[ -n "$expected_hash" ]] && [[ "$actual_hash" == "$expected_hash" ]] && [[ $updated_script =~ ^#! ]]; then
105+
echo "$updated_script" > "$SCRIPT_PATH"
106+
fi
107+
}
108+
92109
download_binary() {
93110
curl -R -z "$BINARY_ZIP_PATH" -L "http://api.browserstack.com/sdk/v1/download_cli?os=${OS}&os_arch=${ARCH}" -o "$BINARY_ZIP_PATH"
94111
bsdtar -xvf "$BINARY_ZIP_PATH" -O > "$BINARY_PATH" && chmod 0775 "$BINARY_PATH"
95112
}
96113

114+
script_self_update
97115
if [[ $SUBCOMMAND == "register-pre-commit-hook" ]]; then
98116
register_git_hook
99117
exit 0

0 commit comments

Comments
 (0)