mirror of
https://github.com/usnistgov/macos_security.git
synced 2026-02-03 05:53:24 +00:00
Using "heredoc" Breaks Commands #178
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @hackerman-jpeg on GitHub.
Summary
Any (or most) commands in the CIS and STIG that uses the heredoc will probably break the command. For example the AirDrop Disable CIS Check:
If executed as is, returns new line and no result, due to how this command is structured.
For MacOS 13, it is much more robust and concise to use:
Or if we must stick to the same syntax, I would structure:
Also, if the key has never been set, it will return the following error:
Therefore the boolean must be set first to even return status
0.Steps to reproduce
Run the command in MacOS 13 terminal as is written in Benchmark:
Operating System version
macOS: 22E261 Kernel: 22.4.0Intel or Apple Silicon
Apple Silicon
What is the current bug behavior?
Returns new line for infinite user input.
And also:
What is the expected correct behavior?
Runs the OS command in the script.
Relevant logs and/or screenshots
Output of checks
See above.
Possible fixes
It is important to note that if the boolean is not set, it will return the error `The domain/default pair of (com.apple.applicationaccess, allowAirDrop) does not exist'. Therefore the boolean must be set to disable AirDrop first:
Fix 1
Refactor to the below:
Fix 2
Use a better command for MacOS13:
Or put this same command into a script as was done before (for easier auditing):
@hackerman-jpeg commented on GitHub:
To summarise:
1. Use
defaults readwhen possible2. Use a more clean syntax for script format, and remove EOF/
heredoc, as it muddy and causes errors.@robertgendler commented on GitHub:
Defaults to read the domain in memory is not ideal as it requires a user to be logged in. It will not read from the preferences daemon unless a user session at loginwindow is established.
The spacing and heredoc was done to make it easier to read. When you remove it and put the command like in your osascript example the PDF wraps kind of nicely, but the HTML document makes the horizontal scrolling which we thought wasn't ideal.
The heredoc also makes it a lot easier when there's complex checks with multiple keys.