Pensar - auto fix for Unbounded Tweet Scraping Resource Exhaustion#7
Open
pensarappdev[bot] wants to merge 1 commit into
Open
Pensar - auto fix for Unbounded Tweet Scraping Resource Exhaustion#7pensarappdev[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.
Resource Consumption Vulnerability in
user_lookup_sns(and, for consistency,user_lookup_tweepy):quantityparameter, directly settable by an external caller, could be arbitrarily large and thus cause unbounded network requests and memory usage, possibly leading to denial of service.TWEET_MAX_LIMIT = 3200reflecting Twitter's reasonable limit._validate_quantity(self, quantity)to check thatquantityis an integer, at least 1, and not greater than 3200 (if it is, it is capped and a warning is logged).user_lookup_snsanduser_lookup_tweepynow use the validated quantity.user_lookup_snstoif idx >= quantity_validated:to be consistent and prevent off-by-one errors.user_lookup_snsto reflect the capped value.Backward Compatibility and Transparency:
quantityis passed (negative, zero, or non-integer), aValueErroris raised.No dependency changes were required.
More Details
quantityparameter is taken directly from external input and used as the upper bound for an un-throttled loop that fetches tweets and stores each result in memory. If an attacker supplies an extremely large value (e.g., millions), the loop will attempt to scrape and keep that many tweets, resulting in excessive network requests, high CPU usage, and unbounded memory growth. This creates a denial-of-service scenario for the host application and potentially violates Twitter rate limits. No validation or hard upper limit is applied toquantity, nor is any back-pressure or pagination safeguard implemented. This is Uncontrolled Resource Consumption (CWE-400).