Pensar - auto fix for 2 issues (CWE-502, ML05, CWE-22)#28
Open
pensarappstaging[bot] wants to merge 1 commit into
Open
Pensar - auto fix for 2 issues (CWE-502, ML05, CWE-22)#28pensarappstaging[bot] wants to merge 1 commit into
pensarappstaging[bot] wants to merge 1 commit into
Conversation
1. Unsafe NumPy File Loading Enables Remote Code Execution (CWE-502, ML05) 2. Unsanitized Path Traversal in Social Profile Tweet Storage (CWE-22)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Path Traversal Mitigation:
outdir, input/output JSON/embedding/cluster files) in path validation logic._is_safe_filenameto check for directory traversal attempts, absolute paths, or unsafe characters in file names._safe_join, which ensures that constructed paths are strictly confined to specified base directories (data/,embeddings/, etc.), and explicitly raises an error if traversal outside is attempted.user-derived file names to prevent directory escape via usernames, replacing/with_.outdiris a subdirectory ofdata/.Unsafe NumPy Loading Mitigation:
.npyloading for embeddings, changednp.load(embedding_path)tonp.load(resolved_embedding_path, allow_pickle=False).No impact to application logic:
More Details
.npyfile whose path is fully controlled by the caller (embedding_path) usingnp.load. NumPy’s loader historically allows pickled object dtypes by default, which means a crafted.npycan deserialize arbitrary Python objects and execute code during loading. If an attacker can place or influence that file, this becomes an RCE vector. OWASP-ML highlights untrusted model/data artifact loading as a top risk (ML05). Mitigate by refusing pickle content (allow_pickle=False), validating the file’s provenance, or enforcing cryptographic integrity checks before loading.outdiranduserare incorporated directly into filesystem paths without sanitisation. An attacker supplying values such as../../etc/passwdcan leverage path-traversal to read or overwrite arbitrary files, leading to information disclosure or file corruption. Always canonicalise and validate user-controlled path segments, or restrict operations to a fixed, known-safe directory.