Summary
NLTK ZIP extraction can write through an in-root hardlink whose other link points outside the intended NLTK data directory. A local attacker who can prepare the extraction target may cause a package member to overwrite an out-of-root file, potentially affecting its integrity or availability.
Affected context
The issue affects NLTK ZIP package extraction in versions 3.9.4 through 3.10.3 when an extraction target contains an in-root hardlink to a file outside the NLTK data root. In that situation, writing a package member through the link can cross the intended path containment boundary.
Exploit preconditions
- Attack surface: Local access to an environment where NLTK performs ZIP extraction
- Required access: Ability to prepare or influence the extraction target, including the relevant hardlink
- Trigger point: Extraction of a ZIP package member to a path matching the in-root hardlink
- Why exploitation is possible: The filesystem follows the hardlink to its outside target, allowing a write to escape the intended data root
Why this happens
The extraction process does not sufficiently account for hardlinks when enforcing path containment. A pathname may appear to remain inside the NLTK data root while resolving through an in-root hardlink to an out-of-root file. This is an improper link resolution issue mapped primarily to CWE-59: Improper Link Resolution Before File Access; the associated CWE-73 relates to external control of file names or paths.
Potential impact
- An attacker may overwrite files outside the intended NLTK data root.
- Modified files could affect application or system integrity.
- Overwriting or damaging important files could disrupt availability.
General mitigation guidance
Defensive approaches focus on keeping extraction writes within a trusted directory boundary and reducing control over extraction targets.
- Use extraction logic that safely handles symbolic links and hardlinks, and rejects paths that resolve outside the intended root.
- Create extraction targets in newly created, access-controlled directories rather than attacker-prepared locations.
- Validate paths and filesystem objects at the point of use, accounting for link resolution and race conditions.
- Limit the privileges of processes that perform extraction and restrict write access to sensitive files.
- Prefer secure-by-default archive handling APIs and minimize reliance on attacker-controlled archive paths or target state.
How teams detect issues like this
- Use static analysis and code review to identify archive extraction code that writes files without resolving and checking link targets.
- Review whether path containment checks account for hardlinks, symbolic links, and filesystem changes between validation and writing.
- Apply policy checks to flag extraction into shared or attacker-writable directories, as well as processes with broad filesystem write permissions.
- Test extraction behavior with linked targets in controlled security tests.

