Pensar - auto fix for Path Traversal in Twitter Profile Data Storage#22
Open
pensarappdev[bot] wants to merge 1 commit into
Open
Pensar - auto fix for Path Traversal in Twitter Profile Data Storage#22pensarappdev[bot] wants to merge 1 commit into
pensarappdev[bot] wants to merge 1 commit into
Conversation
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.
Security issue fixed: Path traversal in the use of the
userparameter as a filename for reading/writing tweet data.Details of the fix:
sanitize_handle(user: str), ensures that Twitter handles only contain allowed (alphanumeric and underscore) characters. Any disallowed characters, path separators, or suspicious substrings such as..raise aValueError.safe_user_tweet_path(outdir, user)uses the sanitized handle to build a filename, joins it with the intended output directory, and checks that the resulting absolute path resides within the expected directory (outdir). If not, aValueErroris raised.create_social_profile_tweepyandcreate_social_profile_sns) have been updated to usesafe_user_tweet_path(). No direct string interpolation ofuserinto file paths remains, closing the path traversal vulnerability.reimport was added to support regular expression checking in the sanitization function.No changes were made unrelated to the explicit issue described.
More Details
user(a Twitter handle supplied by whoever invokes the API). Ifusercontains path separators such as "../" or an absolute path (e.g. "../../etc/passwd"), the resulting path escapes the intendedoutdirdirectory. Because the code then opens these paths for both reading and writing, an attacker could:• Read arbitrary files on the host (information disclosure)
• Overwrite or create files elsewhere on the filesystem (potential denial-of-service or further compromise)
No validation or sanitisation is performed to restrict
userto safe characters, nor isos.path.abspathcompared against an allowed base directory. This is a classic Path Traversal vulnerability.