Safeguard
Application Security•

CWE-281 Improper Preservation of Permissions in Copies and Backups

CWE-281 covers copy, restore, and share operations that loosen permissions. Learn how backups and clones expose files and how to preserve modes safely.

Safeguard Security Team
2 min read

CWE-281, Improper Preservation of Permissions, is a product that does not preserve permissions, or preserves them incorrectly, when copying, restoring, or sharing objects. The copy ends up with less restrictive permissions than the original.

Backup tools, file synchronizers, cloning features, and migration scripts are the usual places.

How it happens

Permissions are metadata, and metadata is easy to lose. A copy command that creates a new file uses default modes. A restore routine applies the wrong access list. A filesystem mount remaps permissions automatically.

MITRE's examples:

  • CVE-2002-2323 (Gold): incorrect ACLs used when restoring backups from directories that use symbolic links.
  • CVE-2001-1515 (Gold): automatic modification of permissions inherited from another file system.
  • CVE-2005-1920 (Gold): permissions on a backup file are created with defaults, possibly less secure than the original.
  • CVE-2001-0195 (Gold): a file is made world-readable when being cloned.
# Vulnerable: copy creates a new file with default permissions
shutil.copyfile("secrets.conf", "backup/secrets.conf")

What an attacker gains

MITRE lists confidentiality and integrity impact: reading and modifying application data. A private file that becomes readable in a backup directory is as exposed as if the original were public.

How to find it

  • After any backup, restore, or clone, compare modes and ACLs of source and destination.
  • Test with files that have restrictive modes and with symbolic links.
  • Check whether your tooling treats permissions as data worth copying.
stat -c '%a %U %n' secrets.conf backup/secrets.conf

How to fix it

Use copy functions that preserve metadata, then verify the result, and create backup locations with restrictive permissions of their own.

shutil.copy2("secrets.conf", "backup/secrets.conf")
os.chmod("backup/secrets.conf", 0o600)

Treat the permission comparison as a test case for your backup and restore process.

Quick check

Why check a backup's permissions separately from the original's?

The backup is a new object. If the copy process does not preserve permissions, the backup can be more exposed than the file it protects.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.