CWE-22/CWE-73 in permutation cache path: APEX_ASP_CACHE_DIR controls write destination
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9k
- Forks
- 1.5k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
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.py
Expected 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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apex/apex/contrib/sparsity/permutation_search_kernels/exhaustive_search.py at lines 77 and 91, especially generate_all_unique_combinations() and its np.save call. Run poc_01_apex_cache_dir_write.py after setting repo_apex to the local apex path. Done means APEX_ASP_CACHE_DIR is constrained to an allowed base or safely rejected, and the controlled-write reproduction no longer reaches an arbitrary writable location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100