COMMON WEAKNESS ENUMERATIONIncomplete

CWE-61

UNIX Symbolic Link (Symlink) Following

The product, when opening a file or directory, does not sufficiently account for when the file is a symbolic link that resolves to a target outside of the intended control sphere. This could allow an attacker to cause the product to operate on unauthorized files.

Abstraction

Compound

Structure

Composite

Likelihood of Exploit

High

Understand the problem

What is the problem?

The product, when opening a file or directory, does not sufficiently account for when the file is a symbolic link that resolves to a target outside of the intended control sphere. This could allow an attacker to cause the product to operate on unauthorized files.

Extended description

A product that allows UNIX symbolic links (symlink) as part of paths whether in internal code or through user input can allow an attacker to spoof the symbolic link and traverse the file system to unintended locations or access arbitrary files. The symbolic link can permit an attacker to read/write/corrupt a file that they originally did not have permissions to access.

Terminology

Alternate terms and usages

Symlink following

symlink vulnerability

Root cause

How and when does the problem arise?

Lifecycle phase

Implementation

These are typically reported for temporary files or privileged programs.

Risk

What does successful exploitation lead to?

Read Files or DirectoriesModify Files or Directories

Affected security scopes: Confidentiality, Integrity

Defence

How is it prevented and fixed?

Implementation

Implementation-phase defence

Detail
Symbolic link attacks often occur when a program creates a tmp directory that stores files/links. Access to the directory should be restricted to the program as to prevent attackers from manipulating the files.

Architecture and Design

Separation of Privilege

Detail
Follow the principle of least privilege when assigning access rights to entities in a software system. Denying access to a file can prevent an attacker from replacing that file with a link to a sensitive file. Ensure good compartmentalization in the system to provide protected areas that can be trusted.

Verification

How is it detected?

Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)