Test the report receiver and redaction against attacks
shellcheck / shellcheck (push) Failing after 19s
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>
This commit is contained in:
@@ -159,3 +159,111 @@ field() {
|
||||
[ "$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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user