- Pass --ignore-inode for sources below /mnt/user and /mnt/user0. shfs hands out new inode numbers after every reboot, which made Restic re-read all data on the first run after a restart. - Add a per-job lowPriority option that starts Restic and Rsync through ionice (idle) and nice 19 via the new internal/procprio package. - Run restic forget with --group-by host,tags. Grouping by paths split a job into a new group whenever its sources changed, and keep-within never expired the old group's snapshots. - Verify the Unraid CSRF token in webgui/api.php for POST, PUT and DELETE and reject other methods; Unraid's own check only covers form posts. - Set $urbmVersion in URBM.page during the package build and fail the build if it does not match, so the page always loads the packaged JS asset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.7 KiB
Bash
Executable File
46 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Checks that webgui/api.php rejects state-changing requests without the
|
|
# Unraid CSRF token. Runs api.php through the PHP CLI, which fills $_SERVER
|
|
# from the environment. A request that passes the check reaches the daemon
|
|
# socket test and fails with "Daemon läuft nicht" instead.
|
|
set -euo pipefail
|
|
|
|
if ! command -v php >/dev/null 2>&1; then
|
|
echo "api_csrf_test: php not installed, skipped"
|
|
exit 0
|
|
fi
|
|
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
printf 'csrf_token="secret-token"\n' > "$WORK/var.ini"
|
|
|
|
call() {
|
|
env -i PATH="$PATH" URBM_VAR_INI="${VAR_INI:-$WORK/var.ini}" "$@" php "$ROOT/webgui/api.php" 2>/dev/null
|
|
}
|
|
|
|
fail=0
|
|
expect() {
|
|
local name=$1 want=$2 got=$3
|
|
if [[ "$got" != *"$want"* ]]; then
|
|
echo "FAIL: $name: expected '$want', got: $got"
|
|
fail=1
|
|
fi
|
|
}
|
|
|
|
expect "GET needs no token" "Daemon" "$(call REQUEST_METHOD=GET)"
|
|
expect "POST without token" "CSRF" "$(call REQUEST_METHOD=POST)"
|
|
expect "POST with wrong token" "CSRF" "$(call REQUEST_METHOD=POST HTTP_X_CSRF_TOKEN=wrong)"
|
|
expect "PUT without token" "CSRF" "$(call REQUEST_METHOD=PUT)"
|
|
expect "DELETE without token" "CSRF" "$(call REQUEST_METHOD=DELETE)"
|
|
expect "lowercase post is checked" "CSRF" "$(call REQUEST_METHOD=post)"
|
|
expect "POST with valid token" "Daemon" "$(call REQUEST_METHOD=POST HTTP_X_CSRF_TOKEN=secret-token)"
|
|
expect "PUT with valid token" "Daemon" "$(call REQUEST_METHOD=PUT HTTP_X_CSRF_TOKEN=secret-token)"
|
|
expect "unknown method" "method not allowed" "$(call REQUEST_METHOD=PATCH HTTP_X_CSRF_TOKEN=secret-token)"
|
|
expect "missing var.ini fails closed" "CSRF" "$(VAR_INI=$WORK/missing.ini call REQUEST_METHOD=POST HTTP_X_CSRF_TOKEN=)"
|
|
|
|
if [[ $fail -ne 0 ]]; then
|
|
exit 1
|
|
fi
|
|
echo "api_csrf_test: ok"
|