What it is: UNIX Hard Link (CWE-62) is a type of vulnerability that occurs when the product, when opening a file or directory, does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere.
Why it matters: This could allow an attacker to cause the product to operate on unauthorized files, leading to potential data breaches and system compromise.
How to fix it: Follow the principle of least privilege when assigning access rights, deny access to files, and ensure good compartmentalization in the system.
TL;DR: UNIX Hard Link (CWE-62) is a vulnerability that occurs when the product does not account for hard links outside of the intended control sphere, allowing attackers to operate on unauthorized files.
At-a-Glance
| Field | Value |
|---|---|
| CWE ID | CWE-62 |
| OWASP Category | No official mapping |
| CAPEC | None known |
| Typical Severity | Critical |
| Affected Technologies | Unix |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-27 |
What is UNIX Hard Link?
UNIX Hard Link (CWE-62) is a type of vulnerability that occurs when the product, when opening a file or directory, does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere. As defined by the MITRE Corporation under CWE-62, and classified by the OWASP Foundation as not directly mapped.
Quick Summary
UNIX Hard Link (CWE-62) is a critical vulnerability that can allow attackers to operate on unauthorized files. It occurs when the product does not account for hard links outside of the intended control sphere. This can lead to potential data breaches and system compromise. To prevent UNIX Hard Link, follow the principle of least privilege when assigning access rights, deny access to files, and ensure good compartmentalization in the system.
Jump to: What is UNIX Hard Link? · Quick Summary · UNIX Hard Link Overview · How UNIX Hard Link Works · Business Impact of UNIX Hard Link · UNIX Hard Link Attack Scenario · How to Detect UNIX Hard Link · How to Fix UNIX Hard Link · Framework-Specific Fixes for UNIX Hard Link · How to Ask AI to Check Your Code for UNIX Hard Link · UNIX Hard Link Best Practices Checklist · UNIX Hard Link FAQ · Vulnerabilities Related to UNIX Hard Link · References · Scan Your Own Site
UNIX Hard Link Overview
What: UNIX Hard Link (CWE-62) is a type of vulnerability that occurs when the product, when opening a file or directory, does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere.
Why it matters: This could allow an attacker to cause the product to operate on unauthorized files, leading to potential data breaches and system compromise.
Where it occurs: UNIX Hard Link can occur in any system or application that uses Unix-based file systems and does not properly account for hard links outside of the intended control sphere.
Who is affected: Any user who has access to the system or application can be affected by UNIX Hard Link.
Who is NOT affected: Users who do not have access to the system or application are not affected by UNIX Hard Link.
How UNIX Hard Link Works
Root Cause
The root cause of UNIX Hard Link (CWE-62) is that the product does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere.
Attack Flow
- The attacker creates a hard link to a target file or directory outside of the intended control sphere.
- The product opens the file or directory without checking if it is a hard link.
- The product operates on the unauthorized file or directory, allowing the attacker to access sensitive data.
Prerequisites to Exploit
- The product must be using Unix-based file systems.
- The product must not properly account for hard links outside of the intended control sphere.
- The attacker must have access to the system or application.
Vulnerable Code
import os
def reset_upload_permissions(filename):
path = os.path.join('/var/app/uploads', filename)
os.chmod(path, 0o644)
filename names a file inside a directory shared with less-trusted users. Because a hard link shares the same inode as its target, an attacker can pre-create a hard link at that filename pointing at a file they don’t own elsewhere on the same filesystem; this code changes permissions on whatever inode the name currently resolves to with no check that it’s still the upload the application expects, so the chmod lands on the attacker’s chosen target too.
Secure Code
import os
def reset_upload_permissions(filename):
path = os.path.join('/var/app/uploads', filename)
st = os.stat(path)
if st.st_nlink > 1:
raise ValueError('refusing to operate on a hard-linked file')
os.chmod(path, 0o644)
os.path.islink() only detects symlinks — a hard link is indistinguishable from a regular file except that its inode’s link count (st_nlink) is greater than 1. Checking st_nlink before the operation catches the case a symlink check would silently miss.
Business Impact of UNIX Hard Link
Confidentiality
UNIX Hard Link (CWE-62) can allow attackers to access sensitive data, leading to potential data breaches.
Integrity
UNIX Hard Link (CWE-62) can allow attackers to modify files and directories outside of the intended control sphere, leading to potential system compromise.
Availability
UNIX Hard Link (CWE-62) can disrupt system availability by allowing attackers to create hard links to target files or directories outside of the intended control sphere.
UNIX Hard Link Attack Scenario
- The attacker creates a hard link to a target file or directory outside of the intended control sphere.
- The product opens the file or directory without checking if it is a hard link.
- The product operates on the unauthorized file or directory, allowing the attacker to access sensitive data.
How to Detect UNIX Hard Link
Manual Testing
- Check for hard links outside of the intended control sphere in the system or application.
- Verify that the product properly accounts for hard links before operating on files or directories.
Automated Scanners (SAST / DAST)
Automated scanners can detect UNIX Hard Link by checking for hard links outside of the intended control sphere and verifying that the product properly accounts for them.
PenScan Detection
PenScan’s automated penetration testing platform actively tests for this issue.
False Positive Guidance
Be cautious when detecting UNIX Hard Link, as some false positives may occur. Verify that the detected issue is indeed a UNIX Hard Link vulnerability before taking action.
How to Fix UNIX Hard Link
- Follow the principle of least privilege when assigning access rights.
- Deny access to files and directories outside of the intended control sphere.
- Ensure good compartmentalization in the system.
Framework-Specific Fixes for UNIX Hard Link
Java
import java.io.File;
File path = new File('/home/user/hard_link');
if (path.isSymbolicLink()) {
throw new SecurityException('Hard link detected');
}
Node.js
const fs = require('fs');
const path = '/home/user/hard_link';
if (fs.lstatSync(path).isSymbolicLink()) {
throw new Error('Hard link detected');
}
Python/Django
import os
path = '/home/user/hard_link'
if os.path.islink(path):
raise ValueError('Hard link detected')
How to Ask AI to Check Your Code for UNIX Hard Link
You can use AI-powered coding assistants to review your code for potential UNIX Hard Link vulnerabilities and rewrite it using secure practices.
Review the following Python code block for potential CWE-62 UNIX Hard Link vulnerabilities and rewrite it using hard link checking:
```python import os path = '/home/user/hard_link' os.chdir(path) ```UNIX Hard Link Best Practices Checklist
✅ Follow the principle of least privilege when assigning access rights. ✅ Deny access to files and directories outside of the intended control sphere. ✅ Ensure good compartmentalization in the system.
UNIX Hard Link FAQ
How does UNIX Hard Link occur?
UNIX Hard Link occurs when the product, when opening a file or directory, does not sufficiently account for when the name is associated with a hard link to a target that is outside of the intended control sphere.
What are the consequences of UNIX Hard Link?
The consequences of UNIX Hard Link include unauthorized access and modification of files, leading to potential data breaches and system compromise.
How can I detect UNIX Hard Link in my application?
You can detect UNIX Hard Link by manually testing for hard links outside of the intended control sphere or using automated scanners that check for this vulnerability.
What are some best practices to prevent UNIX Hard Link?
Some best practices to prevent UNIX Hard Link include following the principle of least privilege when assigning access rights, denying access to files, and ensuring good compartmentalization in the system.
Can AI help me detect and fix UNIX Hard Link in my code?
Yes, you can use AI-powered coding assistants to review your code for potential UNIX Hard Link vulnerabilities and rewrite it using secure practices.
What are some common frameworks that can be affected by UNIX Hard Link?
UNIX Hard Link can affect any system or application that uses Unix-based file systems and does not properly account for hard links outside of the intended control sphere.
How do I know if my code is vulnerable to UNIX Hard Link?
You can use automated scanners, manual testing, and code reviews to identify potential vulnerabilities in your code.
Vulnerabilities Related to UNIX Hard Link
| CWE | Name | Relationship |
|---|---|---|
| CWE-59 | Improper Link Resolution Before File Access (‘Link Following’) | ChildOf |
References
- [MITRE] https://cwe.mitre.org/data/definitions/62.html
- [NVD] https://nvd.nist.gov/
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find UNIX Hard Link and other risks before an attacker does.