|
168 | 168 | BROWSER_POLICY_GROUP=omarchy-browser-policy |
169 | 169 | pass "a hardened directory must be root-owned" |
170 | 170 |
|
| 171 | +saved_parent_dirs=("${BROWSER_POLICY_PARENT_DIRS[@]}") |
| 172 | +parent_root=$test_tmp/parents |
| 173 | +mkdir -p "$parent_root/etc/chromium/policies/managed/keep" |
| 174 | +printf 'keep\n' >"$parent_root/etc/chromium/policies/managed/keep/x" |
| 175 | +chmod 0777 "$parent_root/etc/chromium" "$parent_root/etc/chromium/policies" |
| 176 | +chmod 2775 "$parent_root/etc/chromium/policies/managed" |
| 177 | +BROWSER_POLICY_PARENT_DIRS=( |
| 178 | + "$parent_root/etc/chromium" |
| 179 | + "$parent_root/etc/chromium/policies" |
| 180 | +) |
| 181 | +as_root() { unprivileged_as_root "$@"; } |
| 182 | +if browser_policy_parents_hardened "$parent_root/etc/chromium/policies/managed"; then |
| 183 | + fail "a world-writable policy parent is not treated as hardened" |
| 184 | +fi |
| 185 | +browser_policy_setup_parents_for "$parent_root/etc/chromium/policies/managed" |
| 186 | +mode=$(stat -c '%a' "$parent_root/etc/chromium") |
| 187 | +[[ $mode == "755" ]] || fail "setup tightens /etc/chromium" "mode=$mode" |
| 188 | +mode=$(stat -c '%a' "$parent_root/etc/chromium/policies") |
| 189 | +[[ $mode == "755" ]] || fail "setup tightens /etc/chromium/policies" "mode=$mode" |
| 190 | +[[ -d $parent_root/etc/chromium/policies/managed/keep ]] || |
| 191 | + fail "parent repair does not purge the managed directory" |
| 192 | +pass "policy parent directories are tightened to 0755 without purging the leaf" |
| 193 | + |
| 194 | +symlink_root=$test_tmp/symlink-parents |
| 195 | +mkdir -p "$symlink_root/etc" "$symlink_root/attacker/policies/managed" |
| 196 | +printf 'planted\n' >"$symlink_root/attacker/policies/managed/evil.json" |
| 197 | +ln -s "$symlink_root/attacker" "$symlink_root/etc/chromium" |
| 198 | +BROWSER_POLICY_PARENT_DIRS=( |
| 199 | + "$symlink_root/etc/chromium" |
| 200 | + "$symlink_root/etc/chromium/policies" |
| 201 | +) |
| 202 | +as_root() { unprivileged_as_root "$@"; } |
| 203 | +browser_policy_setup_dir "$symlink_root/etc/chromium/policies/managed" |
| 204 | +[[ ! -L $symlink_root/etc/chromium ]] || fail "setup replaces a planted /etc/chromium symlink" |
| 205 | +[[ -d $symlink_root/etc/chromium && ! -L $symlink_root/etc/chromium ]] || |
| 206 | + fail "setup recreates /etc/chromium as a real directory" |
| 207 | +[[ -d $symlink_root/etc/chromium/policies && ! -L $symlink_root/etc/chromium/policies ]] || |
| 208 | + fail "setup recreates /etc/chromium/policies as a real directory" |
| 209 | +[[ ! -e $symlink_root/etc/chromium/policies/managed/evil.json ]] || |
| 210 | + fail "setup does not keep policy that lived behind a planted parent symlink" |
| 211 | +grep -Fxq 'planted' "$symlink_root/attacker/policies/managed/evil.json" || |
| 212 | + fail "replacing a parent symlink does not delete the symlink target" |
| 213 | +BROWSER_POLICY_PARENT_DIRS=("${saved_parent_dirs[@]}") |
| 214 | +pass "policy setup does not follow a planted parent symlink" |
| 215 | + |
| 216 | +[[ $(browser_policy_theme_hex "242,240,229") == "#f2f0e5" ]] || |
| 217 | + fail "theme colour converts an RGB triple to hex" |
| 218 | +[[ $(browser_policy_theme_hex $'14,31,41\n') == "#0e1f29" ]] || |
| 219 | + fail "theme colour accepts a trailing newline" |
| 220 | +[[ $(browser_policy_theme_hex "0,0,0") == "#000000" ]] || |
| 221 | + fail "theme colour pads single-digit components" |
| 222 | +[[ $(browser_policy_theme_hex " 12 , 11 , 12 ") == "#0c0b0c" ]] || |
| 223 | + fail "theme colour tolerates surrounding whitespace" |
| 224 | +[[ $(browser_policy_theme_hex "08,09,10") == "#08090a" ]] || |
| 225 | + fail "theme colour treats leading zeros as decimal" |
| 226 | +for malformed in "" "not,a,color" "1,2" "1,2,3,4" "256,0,0" "999,999,999" "-1,0,0" \ |
| 227 | + "1,2,3;id" '1,2,$(id)' "0x10,0,0" "1,2,3 4,5,6"; do |
| 228 | + [[ $(browser_policy_theme_hex "$malformed") == "#1c2027" ]] || |
| 229 | + fail "theme colour falls back to the neutral grey for '$malformed'" |
| 230 | +done |
| 231 | +pass "theme colour is six hex digits or the stock grey" |
| 232 | + |
| 233 | +for theme in "$ROOT"/themes/*/chromium.theme; do |
| 234 | + [[ -f $theme ]] || continue |
| 235 | + rgb=$(<$theme) |
| 236 | + hex=$(browser_policy_theme_hex "$rgb") |
| 237 | + [[ $hex =~ ^#[0-9a-f]{6}$ ]] || |
| 238 | + fail "shipped $(basename "$(dirname "$theme")") chromium.theme parses as hex" "got: $hex from $(printf %q "$rgb")" |
| 239 | + if [[ $hex == "#1c2027" && ! $rgb =~ ^[[:space:]]*28[[:space:]]*,[[:space:]]*32[[:space:]]*,[[:space:]]*39[[:space:]]*$ ]]; then |
| 240 | + fail "shipped $(basename "$(dirname "$theme")") chromium.theme is a valid RGB triple" "got: $(printf %q "$rgb")" |
| 241 | + fi |
| 242 | +done |
| 243 | +pass "shipped chromium.theme files parse as RGB triples" |
| 244 | + |
| 245 | +grep -F 'browser_policy_theme_hex' "$ROOT/bin/omarchy-theme-set-browser" >/dev/null || |
| 246 | + fail "omarchy-theme-set-browser parses chromium.theme through browser_policy_theme_hex" |
| 247 | +if grep -E 'printf.*THEME_RGB_COLOR' "$ROOT/bin/omarchy-theme-set-browser" >/dev/null; then |
| 248 | + fail "omarchy-theme-set-browser does not hand unvetted theme words to printf" |
| 249 | +fi |
| 250 | +pass "omarchy-theme-set-browser validates the theme colour" |
| 251 | + |
171 | 252 | fx_policy=$test_tmp/policies.json |
172 | 253 | printf '%s\n' '{"policies":{}}' >"$fx_policy" |
173 | 254 | chmod 644 "$fx_policy" |
@@ -247,6 +328,8 @@ mapfile -t migrations < <(rg -l 'Stop world-writable Chromium and Firefox policy |
247 | 328 | (( ${#migrations[@]} == 1 )) || fail "exactly one migration locks existing policy directories" "${migrations[*]}" |
248 | 329 | grep -F 'browser_policy_dir_hardened' "${migrations[0]}" >/dev/null || |
249 | 330 | fail "the policy-directory migration no-ops a machine already repaired" |
| 331 | +grep -F 'browser_policy_parents_hardened' "${migrations[0]}" >/dev/null || |
| 332 | + fail "the policy-directory migration repairs a world-writable parent of a hardened leaf" |
250 | 333 | grep -F 'browser_policy_grant_user' "${migrations[0]}" >/dev/null || |
251 | 334 | fail "the policy-directory migration still grants the current user the group" |
252 | 335 | grep -F 'BROWSER_POLICY_FIREFOX_DIRS' "${migrations[0]}" >/dev/null || |
|
0 commit comments