Summary
HanLP's TAR archive extraction handler may allow archive paths to escape the intended extraction directory. If an attacker can provide or influence an archive that the application processes, this could enable unauthorized file writes on the system.
Affected context
The issue is in the uncompress function in hanlp/utils/io_util.py, which handles TAR archive extraction. Deployments may be at risk when they process archives that an attacker can influence and extracted paths are not adequately restricted to the intended destination.
Exploit preconditions
- Attack surface: TAR archive processing through HanLP or an application that uses its extraction handler
- Required access: Ability to submit, replace, or otherwise influence an archive that will be processed; the description indicates remote exploitation may be possible
- Trigger point: Extraction of the attacker-influenced archive
- Why exploitation is possible: Archive paths may be resolved outside the intended extraction directory if path containment is not enforced
Why this happens
The underlying issue is path traversal during archive extraction, mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory. The insecure pattern is trusting archive member paths without ensuring that their resolved destinations remain within the designated extraction directory.
Potential impact
- An attacker may write files outside the intended extraction directory
- Existing files could be overwritten if the process has sufficient permissions
- Application behavior or configuration could be affected by unauthorized file changes
- The consequences could extend to other services or data accessible to the extraction process
General mitigation guidance
Defensive patterns focus on treating archive contents as untrusted and constraining all extraction paths.
- Resolve each destination path and verify it remains within the intended extraction directory before writing
- Reject absolute paths and path components that escape the extraction root
- Prefer archive APIs or wrappers that enforce safe extraction by default
- Limit archive-processing privileges and filesystem access
- Reduce exposure by accepting archives only from trusted sources and validating them before processing
How teams detect issues like this
- Use static analysis to identify archive extraction code that writes member paths without path-containment checks
- Review code for unsafe joins, normalization gaps, and reliance on archive-provided filenames
- Add tests and security policies that verify extraction cannot write outside a designated temporary directory
- Monitor archive-processing workflows for unexpected filesystem changes

