security: CWE-732: Preserve file permissions in backup copies — VC-53765#658
Open
torresashjiancyber wants to merge 1 commit into
Open
security: CWE-732: Preserve file permissions in backup copies — VC-53765#658torresashjiancyber wants to merge 1 commit into
torresashjiancyber wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes CWE-732: Backup files created with world-readable permissions instead of preserving source file's restrictive permissions.
Finding
When
backupFiles: trueis set in playbook installations, theutil.CopyFile()function creates backup files (e.g.,<keyFile>.bak) with default permissions (0644), making private keys, PKCS#12 bundles, and JKS files world-readable to any local user.The root cause is in
pkg/playbook/util/filehelper.go:84whereos.Create(destination)uses mode 0666 &^ umask (typically 0644) instead of preserving the source file's 0600 permissions.Remediation
Changed
os.Create(destination)toos.OpenFile(destination, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, sourceFileStat.Mode().Perm())to preserve the source file's permissions when creating backup copies.This ensures backup files inherit the same restrictive permissions (0600) as the original private key files.
Verification
The fix modifies only the file creation mode in
CopyFile()to preserve source permissions. ThesourceFileStatvariable (obtained at line 65) is now used to extract and apply the source file's permission bits.Files affected:
pkg/playbook/util/filehelper.go: 1 line changed