-
-
Notifications
You must be signed in to change notification settings - Fork 422
Add tweet source for Twikit.Tweet #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nennneko5787
wants to merge
1
commit into
d60:main
Choose a base branch
from
nennneko5787:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add documentation for the
source
property.The property is missing from the class docstring. Add documentation to describe its purpose and return type.
Add the following to the class docstring after line 93:
📝 Committable suggestion
💡 Verification agent
🧩 Analysis chain
Add HTML sanitization for the source property.
The property returns raw HTML which could be unsafe if used without sanitization. Consider adding HTML parsing/sanitization to extract just the client name or sanitize the HTML to prevent XSS attacks.
Let's check if there are any HTML sanitization libraries available for Python:
Consider using an HTML sanitization library like
bleach
to safely handle the HTML content. Add it as a dependency insetup.py
and implement sanitization in the property.🌐 Web query:
💡 Result:
Python offers several robust libraries for HTML sanitization, each with distinct features catering to different security and performance needs:
1. pybluemonday (GitHub)
A high-performance library leveraging Go's bluemonday via bindings:
UGCPolicy
,StrictPolicy
)2. nh3 (GitHub)
Rust-based bindings for Ammonia, optimized for speed:
pip install nh3
3. Bleach (Docs)
A deprecated but widely used library:
Cleaner
class[4][9]http
,https
)4. html-sanitizer (PyPI)
Opinionated library for strict cleanup:
<span style="bold">
→<strong>
)[8]Honorable Mentions: Custom Solutions
Recommendations: For critical applications requiring speed and security, pybluemonday or nh3 are optimal. For legacy systems or simpler needs, Bleach or html-sanitizer remain viable despite lower performance.
Citations:
Sanitize HTML output in the
source
property (twikit/tweet.py: 201-204)The
source
property currently returns raw HTML, which poses an XSS risk if rendered unprocessed. Given recent findings, consider integrating an HTML sanitization library. You have a few good options:Please add the chosen library as a dependency in
setup.py
and update thesource
property to sanitize the HTML—either by extracting and returning just the client name or by properly cleaning the HTML content.