Pensar - auto fix for Unrestricted Path Traversal in Twitter Profile Data Storage#26
Open
pensarappstaging[bot] wants to merge 1 commit into
Open
Pensar - auto fix for Unrestricted Path Traversal in Twitter Profile Data Storage#26pensarappstaging[bot] wants to merge 1 commit into
pensarappstaging[bot] wants to merge 1 commit into
Conversation
…ta 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 Vulnerability Fix (CWE-22) in
create_social_profile_sns&create_social_profile_tweepy:userandoutdirto build file paths allowed malicious users to traverse directories and access or overwrite arbitrary files.reto sanitize usernames. Only alphanumeric characters, underscores, and hyphens are allowed in filenames, replacing everything else with underscores.outdir) is normalized to an absolute path withos.path.abspathand created safely usingos.makedirs.os.path.normpath(os.path.join(outdir_abs, filename)).os.path.commonpathensures the resultant file path is within the intended parent directory (outdir_abs). If not, aValueErroris raised indicating path traversal detection.Other Notes:
More Details
outdiranduserare received as function arguments with no validation or normalisation. They are directly concatenated into file-system paths that are opened for read and write operations. An attacker who controls either parameter could supply values such as../../../../etc/passwd(absolute or relative paths, path separators, etc.) and trigger path traversal, allowing arbitrary file creation, overwriting, or disclosure outside the intended directory. This matches CWE-22 (Path Traversal) and can lead to full compromise of the host file system in environments where the script is exposed to untrusted input.