Pensar - auto fix for 2 issues (CWE-22, ML02)#30
Open
pensarappstaging[bot] wants to merge 1 commit into
Open
Conversation
1. Unsanitized File Path Construction Leading to Directory Traversal (CWE-22) 2. ML Model Data Poisoning via Unvalidated Tweet Content (ML02)
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.
Directory Traversal Vulnerability Fix:
_sanitize_filenamemethod to theProfileclass. This method removes directory traversal sequences (../), slashes, and any characters not in the safe set (a-zA-Z0-9._-). It also truncates overly long usernames.create_social_profile_tweepyandcreate_social_profile_sns) with calls to this sanitizer. Now, filenames for storing tweets cannot escape theoutdiror contain unsafe characters, mitigating directory traversal.ML Pipeline Data Poisoning Fix:
_is_valid_tweet_content, which applies a variety of structural and heuristic checks to each tweet before it is accepted for downstream ML processing:_is_valid_tweet_contentare appended toall_tweets; otherwise, they're logged and discarded.all_tweetsand to disk, content is cleaned and validated; only tweets passing the check are processed further.More Details
outdiranduserinto an f-string without any sanitisation or normalisation. If either of these variables can be influenced by an attacker (e.g., outdir="../../../../etc"), the code will happily write to arbitrary locations on disk, enabling directory-traversal attacks, overwriting of sensitive files, or creation of rogue files. No checks such asos.path.abspathcomparison, whitelist validation, or traversal filtering are performed.self.utils.user_lookup_sns) and immediately feeds that text into an embedding model (CohereEmbedder) and downstream clustering (KMeans) without any provenance, schema validation, or anomaly detection. An attacker controlling a Twitter account (or compromising one) can submit crafted tweets containing adversarial or back-door triggers that will poison the embedding space and skew clustering/topic generation. This is a textbook OWASP ML Top 10 ‘ML02 – Data Poisoning’ risk.