From 9f95353074b476f832f94a3babb690470fa0326a Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 04:59:46 -0300 Subject: [PATCH 1/2] fix(profiles): keep preflight queries read-only and numeric --- lib/check.sh | 3 ++- lib/harden.sh | 2 +- tests/test_check.bats | 6 ++++++ tests/test_harden.bats | 8 ++++++++ unleash-standalone.sh | 5 +++-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/check.sh b/lib/check.sh index bbc0146..111b2b3 100644 --- a/lib/check.sh +++ b/lib/check.sh @@ -44,7 +44,8 @@ run_preformat_check() { step "Checking installed profiles..." if command -v profiles &>/dev/null; then local profile_count - profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0) + profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true) + profile_count="${profile_count:-0}" if [ "$profile_count" -gt 0 ]; then echo -e " ${YEL}$profile_count profile(s) installed${NC}" clean=false diff --git a/lib/harden.sh b/lib/harden.sh index 3cd7e17..ff9f68e 100644 --- a/lib/harden.sh +++ b/lib/harden.sh @@ -12,7 +12,7 @@ harden_live_os() { step "Removing residual MDM profiles..." if command -v profiles &>/dev/null; then local installed - installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true) + installed=$(profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true) if [ "$installed" -gt 0 ]; then if sudo profiles -D -F 2>/dev/null; then success "Forced profile removal" diff --git a/tests/test_check.bats b/tests/test_check.bats index 7141db4..f94d290 100644 --- a/tests/test_check.bats +++ b/tests/test_check.bats @@ -19,3 +19,9 @@ setup() { run run_preformat_check 2>/dev/null || true echo "$output" | grep -qiE "safe|mdm" } + +@test "pre-format checks handle zero profiles without arithmetic diagnostics" { + run run_preformat_check + [ "$status" -eq 0 ] + [[ "$output" != *"integer expression expected"* ]] +} diff --git a/tests/test_harden.bats b/tests/test_harden.bats index 14777d1..9a18b5b 100644 --- a/tests/test_harden.bats +++ b/tests/test_harden.bats @@ -20,3 +20,11 @@ setup() { run harden_status 2>/dev/null || true [ "$status" -eq 0 ] } + +@test "hardening keeps profile queries on stdout" { + local calls="$BATS_TEST_TMPDIR/profile-calls" + profiles() { printf '%s\n' "$*" > "$calls"; echo ''; } + run harden_live_os "$BATS_TEST_TMPDIR" + [ "$status" -eq 0 ] + [ "$(cat "$calls")" = '-C -output stdout-xml' ] +} diff --git a/unleash-standalone.sh b/unleash-standalone.sh index ba8ab49..2410512 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -1286,7 +1286,7 @@ harden_live_os() { step "Removing residual MDM profiles..." if command -v profiles &>/dev/null; then local installed - installed=$(profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || true) + installed=$(profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true) if [ "$installed" -gt 0 ]; then if sudo profiles -D -F 2>/dev/null; then success "Forced profile removal" @@ -1501,7 +1501,8 @@ run_preformat_check() { step "Checking installed profiles..." if command -v profiles &>/dev/null; then local profile_count - profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0) + profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true) + profile_count="${profile_count:-0}" if [ "$profile_count" -gt 0 ]; then echo -e " ${YEL}$profile_count profile(s) installed${NC}" clean=false From f1850912470a08f20342c6ad41f9627129c6672b Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 05:01:23 -0300 Subject: [PATCH 2/2] test(audit): reject arithmetic diagnostics across Bash versions --- tests/test_check.bats | 2 +- tests/test_status.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_check.bats b/tests/test_check.bats index f94d290..a73a8e3 100644 --- a/tests/test_check.bats +++ b/tests/test_check.bats @@ -23,5 +23,5 @@ setup() { @test "pre-format checks handle zero profiles without arithmetic diagnostics" { run run_preformat_check [ "$status" -eq 0 ] - [[ "$output" != *"integer expression expected"* ]] + [[ ! "$output" =~ integer.*expected ]] } diff --git a/tests/test_status.bats b/tests/test_status.bats index a0733e8..e605011 100644 --- a/tests/test_status.bats +++ b/tests/test_status.bats @@ -49,7 +49,7 @@ teardown() { ' bash "$BATS_TEST_DIRNAME/.." [ "$status" -eq 0 ] [[ "$output" == *"Risk:"* ]] - [[ "$output" != *"integer expression expected"* ]] + [[ ! "$output" =~ integer.*expected ]] } @test "audit and report JSON contain numeric zero counts under nounset" {