shellcheck / shellcheck (push) Failing after 19s
server/report-receiver/test_security.py sends the receiver what anyone on the internet could, and the Redaction tests in tests/report.bats feed report logs full of secrets. Each test was checked to fail before its fix. The receiver now refuses a negative Content-Length (read without limit), parts nested thousands deep (a RecursionError dropped the connection) and more than 20 parts (thousands took seconds of CPU to parse). It counts an IPv6 address's /64 for the rate limit, since a home has a whole /64 to send from. Report fields go into the Gitea issue as inline code, and titles keep only the characters of step names and versions, so a report can't @mention the team, link issues, or show a tracking image. It refuses reports while its disk has less than 2 GB free. report now also takes out passwords in URLs, Bearer and Basic tokens, password= and token: values, API keys by their prefixes, Nextcloud app passwords, private keys, IPv6 and MAC addresses, the Cores' domains and the user's name. It reads the Core settings rather than sourcing them, and escapes extended regex characters in names, which it didn't before. The plan for the checks still to do, in the smoketest VM (the agent sandbox, network exposure, what root runs, the install path), is a Claude Code skill: /coredesktop-security-checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
270 lines
10 KiB
Bash
270 lines
10 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
# report, with curl replaced by a stub that saves the fields it was given and
|
|
# answers with $CURL_REPLY
|
|
|
|
setup() {
|
|
common_setup
|
|
export USER=alice
|
|
stub uname '
|
|
case "$1" in
|
|
-n) echo lab ;;
|
|
-r) echo 6.99.1-arch1-1 ;;
|
|
*) /usr/bin/uname "$@" ;;
|
|
esac'
|
|
# Save each -F field: name=<file as name=contents, the log as log.gz
|
|
stub curl '
|
|
fields="$BATS_TEST_TMPDIR/fields"
|
|
mkdir -p "$fields"
|
|
while (( $# )); do
|
|
if [ "$1" = -F ]; then
|
|
case "$2" in
|
|
log=@*) path="${2#log=@}"; cp "${path%%;*}" "$fields/log.gz" ;;
|
|
*=\<*) cp "${2#*=<}" "$fields/${2%%=*}" ;;
|
|
esac
|
|
shift
|
|
fi
|
|
shift
|
|
done
|
|
printf "%b" "${CURL_REPLY:-CD-7Q2K\n200}"
|
|
exit "${CURL_STATUS:-0}"'
|
|
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/tty"
|
|
LOGS="$HOME/.local/state/coredesktop/logs"
|
|
mkdir -p "$LOGS"
|
|
LOG="$LOGS/update-2026-11-08-110307.log"
|
|
printf '%s\n' "Updating CoreDesktop..." "Cloning into '$HOME/.local/share/x'..." \
|
|
"Done, with errors in: 71-siblings.sh" > "$LOG"
|
|
}
|
|
|
|
# answers LINE...: what the user types at the terminal
|
|
answers() {
|
|
printf '%s\n' "$@" > "$COREDESKTOP_TTY"
|
|
}
|
|
|
|
field() {
|
|
cat "$BATS_TEST_TMPDIR/fields/$1"
|
|
}
|
|
|
|
@test "redaction replaces personal details and keeps version numbers" {
|
|
printf '%s\n' \
|
|
"Cloning into '$HOME/.local/share/nvim/lazy/LuaSnip'..." \
|
|
"[sudo] password for alice: " \
|
|
"ardop 1.0.4.1.3 is up to date. gridtracker2 2.261108.4-1, python 3.14" \
|
|
"ssh alice@lab from 192.168.1.20; mail david@federated.computer" \
|
|
"lab.tail1234.ts.net 100.101.102.103 127.0.0.1" \
|
|
"Updated not1mm v26.11.6 -> v26.11.10.1; + not1mm==26.11.10.1; V1.2.3.4" \
|
|
"addr=192.168.1.20 =10.0.0.1 [10.0.0.2] (10.0.0.3)" \
|
|
"alicesmith and labrador stay" > "$LOG"
|
|
|
|
run bash "$REPO/report" --view "$LOG"
|
|
[ "$status" -eq 0 ]
|
|
[ "$output" = "$(printf '%s\n' \
|
|
"Cloning into '~/.local/share/nvim/lazy/LuaSnip'..." \
|
|
"[sudo] password for <user>: " \
|
|
"ardop 1.0.4.1.3 is up to date. gridtracker2 2.261108.4-1, python 3.14" \
|
|
"ssh <user>@<host> from <ip>; mail <email>" \
|
|
"<tailscale-name> <ip> <ip>" \
|
|
"Updated not1mm v26.11.6 -> v26.11.10.1; + not1mm==26.11.10.1; V1.2.3.4" \
|
|
"addr=<ip> =<ip> [<ip>] (<ip>)" \
|
|
"alicesmith and labrador stay")" ]
|
|
! grep -q curl "$STUB_LOG"
|
|
}
|
|
|
|
@test "redaction also cleans a terminal session's log" {
|
|
printf 'Script started on 2026-11-08 [COMMAND="update"]\n\033[1;32mok\033[0m\r\n10%%\r100%%\r\nScript done on 2026-11-08 [COMMAND_EXIT_CODE="1"]\n' > "$LOG"
|
|
run bash "$REPO/report" --view "$LOG"
|
|
[ "$output" = "$(printf 'ok\n100%%')" ]
|
|
}
|
|
|
|
@test "after a failed update, report offers to send the log and sends it on yes" {
|
|
answers y
|
|
run bash "$REPO/report" --offer "$LOG" 71-siblings.sh 46-neovim.sh
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"Your report's ID is CD-7Q2K"* ]]
|
|
[ "$(field kind)" = update ]
|
|
[ "$(field failed)" = "71-siblings.sh, 46-neovim.sh" ]
|
|
[ "$(field kernel)" = 6.99.1-arch1-1 ]
|
|
# The log arrives cleaned and redacted
|
|
[ "$(gzip -dc "$BATS_TEST_TMPDIR/fields/log.gz")" = "$(printf '%s\n' "Updating CoreDesktop..." \
|
|
"Cloning into '~/.local/share/x'..." "Done, with errors in: 71-siblings.sh")" ]
|
|
}
|
|
|
|
@test "the offer can show the log first, and sends nothing on no" {
|
|
answers v n
|
|
run bash "$REPO/report" --offer "$LOG" 71-siblings.sh
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"Cloning into '~/.local/share/x'"* ]]
|
|
[[ "$output" == *"Not sent. To send it later, run: report $LOG"* ]]
|
|
! grep -q curl "$STUB_LOG"
|
|
}
|
|
|
|
@test "without a terminal, the offer sends nothing and says nothing" {
|
|
export COREDESKTOP_TTY=/nonexistent/tty
|
|
run bash "$REPO/report" --offer "$LOG" 71-siblings.sh
|
|
[ "$status" -eq 0 ]
|
|
[ -z "$output" ]
|
|
! grep -q curl "$STUB_LOG"
|
|
}
|
|
|
|
@test "report sends the newest log" {
|
|
touch -d '1 hour ago' "$LOG"
|
|
printf 'install output\n' > "$LOGS/install-2026-11-08-120000.log"
|
|
answers y
|
|
run bash "$REPO/report"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"install-2026-11-08-120000.log"* ]]
|
|
[ "$(field kind)" = install ]
|
|
[ -z "$(field failed)" ]
|
|
}
|
|
|
|
@test "a refused report says why and how to try again" {
|
|
answers y
|
|
export CURL_REPLY='Too many reports from this address; try again tomorrow.\n429'
|
|
run bash "$REPO/report" "$LOG"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"Couldn't send the report: Too many reports from this address"* ]]
|
|
[[ "$output" == *"To try again later, run: report $LOG"* ]]
|
|
}
|
|
|
|
@test "an unreachable server is reported too" {
|
|
answers y
|
|
export CURL_REPLY='curl: (6) Could not resolve host: federated.sh' CURL_STATUS=6
|
|
run bash "$REPO/report" "$LOG"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"Couldn't send the report: curl: (6) Could not resolve host"* ]]
|
|
}
|
|
|
|
@test "a value starting with @ or < is sent as text, not read as a file" {
|
|
answers y
|
|
run bash "$REPO/report" --offer "$LOG" "@/etc/passwd"
|
|
[ "$status" -eq 0 ]
|
|
[ "$(field failed)" = "@/etc/passwd" ]
|
|
}
|
|
|
|
@test "a page that isn't the receiver's answer isn't taken for a report ID" {
|
|
answers y
|
|
export CURL_REPLY='#!/bin/bash\necho installing\n200'
|
|
run bash "$REPO/report" "$LOG"
|
|
[ "$status" -eq 1 ]
|
|
[[ "$output" == *"Couldn't send the report"* ]]
|
|
[[ "$output" != *"Sent."* ]]
|
|
}
|
|
|
|
@test "a report ID ending with a newline, as replies usually do, is accepted" {
|
|
answers y
|
|
export CURL_REPLY='CD-7Q2K\n\n200'
|
|
run bash "$REPO/report" "$LOG"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"Your report's ID is CD-7Q2K;"* ]]
|
|
}
|
|
|
|
# --- Redaction: what mustn't leave this computer -------------------------------
|
|
|
|
# view LINE...: what report would send for a log of these lines
|
|
view() {
|
|
printf '%s\n' "$@" > "$LOG"
|
|
run bash "$REPO/report" --view "$LOG"
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
# sent_as LINE...: the output of the last view is exactly these lines
|
|
sent_as() {
|
|
[ "$output" = "$(printf '%s\n' "$@")" ] || { printf 'got:\n%s\n' "$output" >&2; return 1; }
|
|
}
|
|
|
|
@test "redaction takes passwords out of URLs" {
|
|
view "Cloning https://bob:s3cr3t!pw@gitea.example.com/x.git" \
|
|
"rclone: http://bob:hunter2@localhost:8080/dav/" \
|
|
"fetch ssh://git@github.com/x.git and https://github.com/x.git"
|
|
sent_as "Cloning https://<credentials>@gitea.example.com/x.git" \
|
|
"rclone: http://<credentials>@localhost:8080/dav/" \
|
|
"fetch ssh://<credentials>@github.com/x.git and https://github.com/x.git"
|
|
}
|
|
|
|
@test "redaction takes out tokens, passwords and API keys" {
|
|
view "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.c2lnbmF0dXJl" \
|
|
"curl -H 'Authorization: Basic Ym9iOmh1bnRlcjI='" \
|
|
"password=hunter2 PASSWORD: hunter3 passphrase='correct horse' api_key: abc123" \
|
|
"GET /callback?code=1&access_token=ya29.a0AfH6&state=2" \
|
|
'export ANTHROPIC_API_KEY="sk-ant-api03-AbCdEfGhIjKlMnOp-QrStUv"' \
|
|
"keys sk-proj-abcdefghijklmnopqrstuvwx ghp_abcdefghijklmnopqrstuvwxyz0123456789" \
|
|
"github_pat_11ABCDEFG0123456789_abcdefghijklmnop glpat-abcdefghijklmnopqrst" \
|
|
"xoxb-1234567890-abcdefghij tskey-auth-kAbCdEf1CNTRL-xyz AKIAIOSFODNN7EXAMPLE hf_abcdefghijklmnopqrstuvwx" \
|
|
"app password Ab3dE-fG4hI-jK5lM-nO6pQ-rS7tU in use"
|
|
sent_as "Authorization: Bearer <secret>" \
|
|
"curl -H 'Authorization: Basic <secret>'" \
|
|
"password=<secret> PASSWORD: <secret> passphrase='<secret> horse' api_key: <secret>" \
|
|
"GET /callback?code=1&access_token=<secret>&state=2" \
|
|
'export ANTHROPIC_API_KEY="<secret>"' \
|
|
"keys <secret> <secret>" \
|
|
"<secret> <secret>" \
|
|
"<secret> <secret> <secret> <secret>" \
|
|
"app password <secret> in use"
|
|
}
|
|
|
|
@test "redaction takes out private keys whole" {
|
|
view "Adding key:" "-----BEGIN OPENSSH PRIVATE KEY-----" "b3BlbnNzaC1rZXktdjEAAAAA" \
|
|
"AAAAC3NzaC1lZDI1NTE5AAAA" "-----END OPENSSH PRIVATE KEY-----" "done" \
|
|
"-----BEGIN RSA PRIVATE KEY-----" "MIIEpAIBAAKCAQEA" "-----END RSA PRIVATE KEY-----"
|
|
sent_as "Adding key:" "<private key>" "done" "<private key>"
|
|
}
|
|
|
|
@test "redaction takes out IPv6 and MAC addresses" {
|
|
view "inet6 2001:db8:85a3::8a2e:370:7334/64 scope global" \
|
|
"tailscale fd7a:115c:a1e0::1 and fd7a:115c:a1e0:ab12:4843:cd96:6258:b240" \
|
|
"link fe80::1ff:fe23:4567:890a%wlan0, loopback ::1" \
|
|
"full 2001:0db8:0000:0000:0000:ff00:0042:8329." \
|
|
"[2001:db8::7]:443 ether 3c:22:fb:12:34:56 brd ff:ff:ff:ff:ff:ff"
|
|
sent_as "inet6 <ip> scope global" \
|
|
"tailscale <ip> and <ip>" \
|
|
"link <ip>%wlan0, loopback <ip>" \
|
|
"full <ip>." \
|
|
"[<ip>]:443 ether <mac> brd <mac>"
|
|
}
|
|
|
|
@test "redaction keeps what only looks like an address or a secret" {
|
|
view ":: Synchronizing package databases..." \
|
|
"[2026-11-08T11:03:07-0500] [ALPM] upgraded foo (1:2.3-1 -> 1:2.4-1)" \
|
|
"std::string Foo::Bar::baz() at 12:34:56" \
|
|
"[sudo] password for alice: " "Password: " \
|
|
"sha256 e3b0c44298fc1c14 tokens: 5 secrets.toml" \
|
|
"Bearer token missing" "sk-1 risk-assessment hf_x"
|
|
sent_as ":: Synchronizing package databases..." \
|
|
"[2026-11-08T11:03:07-0500] [ALPM] upgraded foo (1:2.3-1 -> 1:2.4-1)" \
|
|
"std::string Foo::Bar::baz() at 12:34:56" \
|
|
"[sudo] password for <user>: " "Password: " \
|
|
"sha256 e3b0c44298fc1c14 tokens: 5 secrets.toml" \
|
|
"Bearer token missing" "sk-1 risk-assessment hf_x"
|
|
}
|
|
|
|
@test "redaction takes out your Cores' domains and your name, whatever their case" {
|
|
mkdir -p "$HOME/.config/coredesktop/cores"
|
|
printf 'CORE_DOMAIN=%q\nCORE_EMAIL=%q\nCORE_NAME=%q\n' acme.org alice@acme.org "Alice Smith (Acme)" \
|
|
> "$HOME/.config/coredesktop/cores/acme.org.conf"
|
|
cp "$HOME/.config/coredesktop/cores/acme.org.conf" "$HOME/.config/coredesktop/core.conf"
|
|
printf 'CORE_DOMAIN=%q\nCORE_NAME=%q\n' my-core.example "Al O'Neil" > "$HOME/.config/coredesktop/cores/my-core.example.conf"
|
|
view "Mounting https://nextcloud.acme.org/remote.php for Alice Smith (Acme)" \
|
|
"headscale.ACME.ORG and my-core.example, mail alice@acme.org, Al O'Neil" \
|
|
"notacme.org.uk and acme.organic stay"
|
|
sent_as "Mounting https://nextcloud.<core-domain>/remote.php for <name>" \
|
|
"headscale.<core-domain> and <core-domain>, mail <email>, <name>" \
|
|
"notacme.org.uk and acme.organic stay"
|
|
}
|
|
|
|
@test "a Core's settings can't run anything when report reads them" {
|
|
mkdir -p "$HOME/.config/coredesktop/cores"
|
|
printf 'CORE_DOMAIN=acme.org\ntouch "%s/ran"\n' "$BATS_TEST_TMPDIR" > "$HOME/.config/coredesktop/cores/acme.org.conf"
|
|
view "acme.org"
|
|
sent_as "<core-domain>"
|
|
[ ! -e "$BATS_TEST_TMPDIR/ran" ]
|
|
}
|
|
|
|
@test "a user or host name with regular expression characters is still replaced" {
|
|
export USER='a.b+c'
|
|
stub uname '[ "$1" = -n ] && echo "lab(1)" || /usr/bin/uname "$@"'
|
|
view "a.b+c on lab(1); axbbc on lab1"
|
|
sent_as "<user> on <host>; axbbc on lab1"
|
|
}
|