Skip to content

Pensar - auto fix for Path Traversal Vulnerability in Tweet Data File Operations#21

Open
pensarappstaging[bot] wants to merge 1 commit into
mainfrom
pensar-auto-fix-2A-k
Open

Pensar - auto fix for Path Traversal Vulnerability in Tweet Data File Operations#21
pensarappstaging[bot] wants to merge 1 commit into
mainfrom
pensar-auto-fix-2A-k

Conversation

@pensarappstaging

Copy link
Copy Markdown

Secured with Pensar

Security Issue Fixed:
There was a critical CWE-22 (Path Traversal) vulnerability in the way file paths were constructed throughout the Profile class, particularly in create_social_profile_tweepy() and create_social_profile_sns(). Attacker-controlled parameters (outdir and user) were used directly in file paths without sanitization, potentially allowing arbitrary file reads/writes.

How It Was Fixed:

  • Introduced safe_filename() to sanitize the user value, restricting it to [a-zA-Z0-9_.-] and replacing other characters with _ to prevent malicious input from altering file paths.
  • Introduced _safe_join(base, *paths) to ensure the constructed file path is always located within the intended (sanitized) output directory, blocking directory traversal attempts.
  • Explicitly normalized and created outdir at the start of each relevant method using absolute paths for additional protection.
  • Applied these sanitation and safe-joining practices in every location where file reading/writing with a user-derived or outdir-derived path occurs, including both reading tweets, writing tweets, and storing/loading cluster label files.
  • No changes were made outside the direct data flow related to the path traversal issue.

Result:
All reads/writes to tweet and cluster label files are now protected from path traversal attacks via both filename sanitization and path boundary enforcement. The remainder of the code and its formatting is unchanged.

More Details
Type Identifier Message Severity Link
Application
CWE-22
The file-system paths used for both reading and writing tweet data are built directly from the attacker-controlled parameters outdir and user (see also lines 74 – 85). No sanitisation or normalisation is performed. An attacker can supply traversal sequences such as outdir="../../" or user="../../etc/passwd", causing the code to read from or write to arbitrary locations on the host. This classic path-traversal issue (CWE-22) can lead to disclosure of sensitive files, overwriting of application files, or privilege-escalation through malicious file placement.
high
Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants