Skip to content

Secure /Users/Shared too in SecureUsersHomeFolders.zsh (#203)#256

Open
theneiljohnson wants to merge 1 commit intomicrosoft:masterfrom
theneiljohnson:fix-secureusershomefolders
Open

Secure /Users/Shared too in SecureUsersHomeFolders.zsh (#203)#256
theneiljohnson wants to merge 1 commit intomicrosoft:masterfrom
theneiljohnson:fix-secureusershomefolders

Conversation

@theneiljohnson
Copy link
Copy Markdown
Collaborator

Resolves #203.

Thanks @paulh-NC for raising and @DJITS-NL for the Tech Community link in the comments — that pointed straight at the cause.

Why devices stayed non-compliant

The previous script only chmod'd individual user home folders and silently exited 0. Two problems:

  1. /Users/Shared was completely ignored. Defender / Secure Score expects it to be mode 1777 (sticky bit, world-writable) owned by root:wheel. If it drifted from that — for example someone chmod'd it to 777 — the device kept being flagged even though every user folder was perfectly fine.
  2. No verification. If a chmod quietly failed (locked file, immutable flag, SIP-protected path) the script still exited 0, so Intune saw success while the device was still non-compliant.

Fix

  • New SecureSharedFolder() resets /Users/Shared to 1777 root:wheel.
  • SecureUsersHomeFolders() rewritten with -name filters instead of grep, and now stats each folder after the chmod and checks the result against the CIS-acceptable set {700, 711, 750}.
  • Failures are counted and the script exits 1 if anything couldn't be remediated, so Intune surfaces the failure.
  • Explicit root check at the top.
  • Switched from /System/Volumes/Data/Users to /Users (firmlinked, same inodes) — /Users is the path the Defender posture check evaluates.
  • README documents the new behaviour and the /Users/Shared requirement.

Resolves microsoft#203.

The script previously only chmod'd individual user home folders and
silently exited 0. Devices kept being flagged by Defender / Secure
Score because:

  1. /Users/Shared was completely ignored. The expected state is mode
     1777 (sticky bit, world-writable) owned by root:wheel - if it
     drifted (e.g. someone chmod 777'd it), the device stayed
     non-compliant.
  2. The script never verified the resulting permissions or surfaced
     failures. Anything that didn't take (locked file, immutable flag,
     SIP-protected path, etc.) was logged but exit 0 was still
     returned.

Changes:
- Add an explicit handler for /Users/Shared that resets it to
  1777 root:wheel.
- Replace the old find-pipe-grep loop with a clearer loop that uses
  -name filters and verifies each folder's mode after chmod against
  the CIS-acceptable set {700, 711, 750}.
- Track failures and exit 1 if any home folder or /Users/Shared could
  not be remediated.
- Require root.
- Switch from /System/Volumes/Data/Users to /Users (firmlinked, same
  inodes) since /Users is the path the Defender posture check
  evaluates.
- README documents the new behaviour and links to the Tech Community
  thread that prompted the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SecureUsersHomeFolders.zsh does not remediate Secure Score

1 participant