CWE-22/CWE-73 in permutation cache path: APEX_ASP_CACHE_DIR controls write destination
Author: BeforeGodKnowsCreated Apr 27, 2026Updated Apr 27, 2026
Affected locations:
apex/apex/contrib/sparsity/permutation_search_kernels/exhaustive_search.py:77apex/apex/contrib/sparsity/permutation_search_kernels/exhaustive_search.py:91
Vulnerability Details:
- In
generate_all_unique_combinations(), the cache directory is read fromAPEX_ASP_CACHE_DIRand then used directly innp.save(cache_file_path, ...). - There is no base-directory constraint or canonical path validation before write, so externally controlled input can affect the write destination (CWE-22/CWE-73).
Repo-based reproduction steps:
First, modify the apex local path in the poc line 55, repo_apex = Path("apex"). Then, run the poc.
python poc_01_apex_cache_dir_write.pyExpected result:
- Output contains
[+] success: controlled write observed. permutations_4_4.npyis created under the printed attacker-controlled directory.
Security impact:
- In environment-variable-controllable scenarios (for example CI/job wrappers), an attacker can redirect cache writes to arbitrary writable locations, creating cache-poisoning or file-overwrite risk.
Remediation suggestions:
- Canonicalize and constrain
APEX_ASP_CACHE_DIRto an allowed base directory. - Validate the resolved path against an allowlisted base (for example
resolved_path.is_relative_to(allowed_base)or equivalent logic). - Fall back to a safe default directory when validation fails.
Attachments:
poc_01_apex_cache_dir_write.py
Credit BeforeGodKnows
Source: NVIDIA/apex