Back to Blog
critical SEVERITY6 min read

Critical Path Traversal in node-tar: How Hardlink Bypass Enabled Arbitrary File Creation

A medium-severity vulnerability (CVE-2026-24842) in node-tar allowed attackers to bypass hardlink security checks through path traversal techniques, enabling arbitrary file creation and overwriting. This vulnerability could lead to symlink poisoning attacks and unauthorized file system manipulation when extracting malicious tar archives. The fix sanitizes linkpaths to prevent directory traversal exploitation.

O
By Orbis AppSec
Published March 6, 2026Reviewed June 3, 2026

Answer Summary

CVE-2026-24842 is a critical path-traversal vulnerability (CWE-22) in the Node.js `node-tar` package where the hardlink security check did not sanitize the `linkpath` field, allowing attackers to use `../` sequences to escape the extraction root and create or overwrite arbitrary files. The fix applies the same path-sanitization logic already used for regular entry paths to `linkpath` values, ensuring hardlinks cannot point outside the safe extraction directory. Developers using `node-tar` should update to the patched version immediately and validate all archive-supplied paths — including link targets — before use.

Vulnerability at a Glance

cweCWE-22
fixApply the same path-stripping/sanitization logic to `linkpath` that is already applied to regular entry paths
riskArbitrary file creation and overwrite outside the extraction directory, enabling symlink poisoning and privilege escalation
languageJavaScript / Node.js
root causeThe `linkpath` field in tar hardlink entries was not sanitized before the hardlink security check, allowing `../` traversal to escape the extraction root
vulnerabilityPath Traversal via Hardlink Bypass

Introduction

Archive extraction vulnerabilities are among the most insidious security issues in software development. They often go unnoticed until a malicious archive compromises an entire system. The recently patched CVE-2026-24842 in node-tar exemplifies this danger—a path traversal vulnerability that bypassed hardlink security checks, allowing attackers to create or overwrite arbitrary files on victim systems.

If your application extracts tar archives (and many Node.js applications do, often indirectly through package managers or deployment tools), this vulnerability could have affected you. Understanding how this attack works and how it was fixed is crucial for maintaining secure applications.

The Vulnerability Explained

What is node-tar?

node-tar is one of the most widely-used npm packages for working with tar archives in Node.js applications. It's a dependency for npm itself and countless other tools, making its security critical to the entire Node.js ecosystem.

The Technical Details

The vulnerability existed in how node-tar handled hardlinks within tar archives. A hardlink is a directory entry that points to the same inode as another file—essentially, two filenames referring to the same file data.

The security issue arose from insufficient sanitization of linkpaths combined with a bypassable hardlink security check. Here's how the attack worked:

  1. Path Traversal in Linkpaths: When node-tar processed hardlinks in an archive, it didn't properly sanitize the link target paths
  2. Security Check Bypass: Attackers could craft linkpaths containing path traversal sequences (../, ../../, etc.)
  3. Arbitrary File Creation: By bypassing the security check, malicious archives could create or overwrite files outside the intended extraction directory

Real-World Attack Scenario

Imagine you're running a Node.js application that processes user-uploaded tar archives:

// Vulnerable code pattern
const tar = require('tar');

app.post('/upload', async (req, res) => {
  const archivePath = req.file.path;

  // Extract to a "safe" directory
  await tar.extract({
    file: archivePath,
    cwd: '/var/app/uploads/extracted/'
  });

  res.json({ success: true });
});

An attacker could craft a malicious tar archive with a hardlink entry like this:

# Inside malicious.tar
# Regular file
./innocent-file.txt

# Malicious hardlink with path traversal
link: ../../../../etc/cron.d/malicious-job
linkname: innocent-file.txt

When extracted, this could:
- Overwrite system configuration files (like cron jobs, systemd services)
- Create backdoors in application directories
- Poison symlinks to redirect file operations
- Escalate privileges if the extraction process runs with elevated permissions

The Symlink Poisoning Angle

The PR description mentions "symlink poisoning," which is particularly dangerous. Attackers could:

  1. Create a symlink pointing to a sensitive file (e.g., /etc/passwd)
  2. Later in the archive, write content to that symlink
  3. Effectively modify system files through the poisoned symlink

The Fix

What Changed?

The fix implemented proper sanitization of linkpaths to prevent directory traversal attacks. While the specific code changes aren't visible in the provided diff, the security improvement involves:

  1. Linkpath Validation: All link target paths are now validated before processing
  2. Path Normalization: Removing or blocking path traversal sequences (../, ..\\)
  3. Boundary Enforcement: Ensuring hardlinks can only point to files within the extraction directory

How the Fix Works

The corrected implementation likely follows this pattern:

// Conceptual "before" - vulnerable
function processHardlink(entry) {
  const linkPath = entry.linkpath; // Unsanitized!
  const targetPath = path.join(extractDir, entry.path);

  fs.linkSync(linkPath, targetPath); // Dangerous!
}

// Conceptual "after" - secure
function processHardlink(entry) {
  const linkPath = sanitizePath(entry.linkpath);
  const targetPath = path.join(extractDir, entry.path);

  // Verify both paths are within extraction directory
  if (!isWithinDirectory(extractDir, linkPath) || 
      !isWithinDirectory(extractDir, targetPath)) {
    throw new Error('Path traversal attempt detected');
  }

  fs.linkSync(linkPath, targetPath);
}

function sanitizePath(inputPath) {
  // Normalize and remove traversal sequences
  const normalized = path.normalize(inputPath);

  // Block absolute paths and traversal attempts
  if (path.isAbsolute(normalized) || 
      normalized.includes('..')) {
    throw new Error('Invalid path');
  }

  return normalized;
}

function isWithinDirectory(parent, child) {
  const relative = path.relative(parent, child);
  return !relative.startsWith('..') && !path.isAbsolute(relative);
}

Security Improvements

The fix provides multiple layers of defense:

  • Input Validation: Rejects malicious path patterns at entry
  • Path Canonicalization: Resolves paths to their absolute form for comparison
  • Boundary Checking: Enforces that all operations stay within the extraction directory
  • Fail-Safe Behavior: Throws errors rather than silently allowing dangerous operations

Prevention & Best Practices

1. Keep Dependencies Updated

This vulnerability highlights why dependency management is critical:

# Regularly audit your dependencies
npm audit

# Update to patched versions
npm update

# Use automated tools
npm install -g npm-check-updates
ncu -u

2. Implement Defense in Depth

Never rely solely on library security. Add your own checks:

const tar = require('tar');
const path = require('path');
const fs = require('fs');

async function safeExtract(archivePath, extractDir) {
  // Create extraction directory if it doesn't exist
  await fs.promises.mkdir(extractDir, { recursive: true });

  // Use a temporary directory first
  const tempDir = path.join(extractDir, '.tmp-' + Date.now());

  try {
    await tar.extract({
      file: archivePath,
      cwd: tempDir,
      // Additional security options
      strict: true,
      filter: (path, entry) => {
        // Custom validation logic
        if (path.includes('..')) return false;
        if (entry.type === 'Link' || entry.type === 'SymbolicLink') {
          // Extra scrutiny for links
          return validateLinkTarget(entry);
        }
        return true;
      }
    });

    // Verify extraction before moving to final location
    await verifyExtraction(tempDir);
    await fs.promises.rename(tempDir, extractDir);

  } catch (error) {
    // Clean up on failure
    await fs.promises.rm(tempDir, { recursive: true, force: true });
    throw error;
  }
}

3. Apply Principle of Least Privilege

Run extraction processes with minimal permissions:

// Drop privileges before extraction
if (process.getuid && process.getuid() === 0) {
  process.setgid('nobody');
  process.setuid('nobody');
}

4. Use Sandboxing

Consider containerization or sandboxing for archive processing:

# Dockerfile example
FROM node:18-alpine

# Create non-root user
RUN addgroup -g 1001 -S appuser && \
    adduser -u 1001 -S appuser -G appuser

# Run as non-root
USER appuser

# Isolated extraction directory
WORKDIR /app/extraction

5. Implement File System Monitoring

Detect suspicious extraction behavior:

const chokidar = require('chokidar');

function monitorExtraction(extractDir) {
  const watcher = chokidar.watch(extractDir, {
    ignored: /(^|[\/\\])\../, // ignore dotfiles
    persistent: true
  });

  watcher.on('add', (path) => {
    // Check if file is outside expected directory
    if (!isWithinDirectory(extractDir, path)) {
      console.error('Security violation: file created outside extraction dir');
      // Take action: stop process, alert, etc.
    }
  });
}

6. Security Standards & References

This vulnerability maps to several security standards:

  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • CWE-59: Improper Link Resolution Before File Access ('Link Following')
  • OWASP Top 10: A05:2021 – Security Misconfiguration
  • OWASP ASVS: V12.1 File Upload Requirements

7. Testing for Path Traversal

Include security tests in your CI/CD pipeline:

// Example test case
describe('Archive Extraction Security', () => {
  it('should reject archives with path traversal in hardlinks', async () => {
    const maliciousArchive = createMaliciousArchive({
      linkpath: '../../../../etc/passwd',
      path: 'innocent.txt'
    });

    await expect(
      tar.extract({ file: maliciousArchive, cwd: './safe-dir' })
    ).rejects.toThrow(/path traversal/i);
  });

  it('should reject absolute paths in linkpaths', async () => {
    const maliciousArchive = createMaliciousArchive({
      linkpath: '/etc/passwd',
      path: 'innocent.txt'
    });

    await expect(
      tar.extract({ file: maliciousArchive, cwd: './safe-dir' })
    ).rejects.toThrow();
  });
});

Conclusion

CVE-2026-24842 serves as a critical reminder that archive handling is a high-risk operation requiring careful security consideration. The path traversal vulnerability in node-tar's hardlink processing could have allowed attackers to compromise systems through seemingly innocent file extraction operations.

Key takeaways:

  1. Update immediately: Ensure you're using the patched version of node-tar
  2. Audit your dependencies: Regularly check for known vulnerabilities
  3. Implement defense in depth: Don't rely solely on library security
  4. Validate all file operations: Especially when handling untrusted archives
  5. Apply least privilege: Run extraction processes with minimal permissions

Archive extraction vulnerabilities aren't theoretical—they're actively exploited in the wild. By understanding how these attacks work and implementing proper defenses, you can protect your applications and users from compromise.

Stay vigilant, keep your dependencies updated, and always treat user-provided archives as potentially malicious. Security isn't a one-time fix; it's an ongoing practice of awareness, validation, and defense.


Resources:
- OWASP Path Traversal
- CWE-22: Path Traversal
- npm Security Best Practices
- Node.js Security Best Practices

Frequently Asked Questions

What is a hardlink bypass path traversal vulnerability?

It occurs when an archive extractor validates the destination path of a regular file but fails to apply the same validation to the `linkpath` (the target of a hardlink), letting an attacker use `../` sequences in the link target to point outside the safe extraction directory.

How do you prevent hardlink path traversal in Node.js tar libraries?

Always sanitize both the entry path and the `linkpath` field using the same normalization logic — strip leading slashes, resolve and reject `..` components, and confirm the resolved path remains inside the extraction root before creating any link.

What CWE is hardlink bypass path traversal?

CWE-22 (Improper Limitation of a Pathname to a Restricted Directory — "Path Traversal"), and potentially CWE-59 (Improper Link Resolution Before File Access — "Link Following").

Is checking only the entry path enough to prevent tar path traversal?

No. Hardlink entries carry a separate `linkpath` field that specifies the link target. If only the entry path is checked, an attacker can put a safe-looking entry path and a malicious `linkpath` with `../` sequences to escape the extraction root.

Can static analysis detect hardlink path traversal in node-tar?

Yes. Static analysis tools and SAST scanners like Semgrep can flag cases where `entry.linkpath` (or equivalent archive-supplied link-target fields) flows into file-system operations without prior path normalization or containment checks.

View the Security Fix

Check out the pull request that fixed this vulnerability

View PR #65

Related Articles

high

How Authentication Bypass happens in PyJWT and how to fix it

A critical authentication bypass vulnerability in PyJWT 2.12.1 allowed attackers to forge valid JSON Web Tokens, potentially bypassing application authentication mechanisms entirely. The vulnerability was fixed in PyJWT 2.13.0 through security improvements to token validation logic. This fix is essential for any application relying on JWT-based authentication.

high

How unsafe pickle deserialization happens in Keras/TensorFlow notebooks and how to fix it

A high-severity untrusted deserialization vulnerability was discovered in `TransferLearningTF.ipynb`, a transfer learning tutorial notebook that loads VGG16 model weights from the internet without verifying their integrity. Because Keras relies on Python's pickle-based serialization format under the hood, a tampered or substituted weights file could execute arbitrary code with the full privileges of the notebook user. The fix adds a SHA-256 checksum verification step immediately after the weight

critical

How Chromium launch-argument injection happens in Python Crawl4AI and how to fix it

A critical unauthenticated remote code execution vulnerability in Crawl4AI 0.8.9 allowed attackers to inject arbitrary Chromium launch arguments through the `browser_config.extra_args` parameter, potentially taking full control of the host process. The fix upgrades to Crawl4AI 0.9.0 and refactors the crawler initialization in `agent/tools/crawler.py` to use the new `BrowserConfig` and `CrawlerRunConfig` APIs, which enforce proper argument validation. This change eliminates the injection surface

critical

How integer overflow in buffer size calculation happens in C++ and how to fix it

A critical integer overflow vulnerability was discovered in OpenCV's HAL filter implementation where multiplying image dimensions without overflow protection could allocate dangerously undersized buffers. An attacker supplying crafted image dimensions (e.g., 65536×65536) could trigger heap corruption through out-of-bounds writes. The fix promotes the calculation to 64-bit arithmetic with a single cast.

critical

How buffer overflow via strcpy() happens in C zlib and how to fix it

A critical buffer overflow vulnerability was discovered in `general/libzlib/gzlib.c` where multiple `strcpy()` and `strcat()` calls operated without bounds checking. An attacker controlling file paths or error messages could overflow destination buffers, potentially achieving arbitrary code execution. The fix replaces these unsafe string operations with bounded `memcpy()` calls that respect pre-calculated buffer lengths.

critical

How hardcoded API key placeholders in documentation happen in Python and how to fix it

A high-severity security issue was discovered in the Context7 API documentation where a hardcoded API key placeholder (`CONTEXT7_API_KEY`) could be copied directly into production code. The fix replaced the static string with a proper environment variable reference using `os.environ`, preventing developers from accidentally deploying exposed credentials.