Fix #5: HTML injection in Telegram messages #20
Reference in New Issue
Block a user
Delete Branch "fix/issue-5-html-injection-telegram"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fix HIGH severity HTML injection in
send_to_telegram()when usingparse_mode=HTML. Event titles from Polymarket API were inserted directly into HTML without escaping, allowing malformed HTML to be sent via the Telegram bot.Changes
scripts/browse.py:import htmlescape_html(text)function usinghtml.escape()(handles&,<,>,")escape_html(title_clean)at line 648 (match event titles)escape_html(title)at line 676 (non-match event titles)tests/test_browse.py:TestHtmlInjectionclass with 2 tests:test_send_to_telegram_html_injection_in_match_title: verifies<script>tags are escaped as<script>test_send_to_telegram_ampersand_in_title: verifies&is escaped as&Test Results
All 10 tests pass (8 existing + 2 new).
Fixes
Ref: #5
I added some review, please check them. also run a deep analyze first before replying/responding to these feedback so you can have a better context. also if there is any other thing that I missed regarding this issue, please also address it as long as its still relevant
@@ -4,6 +4,7 @@ Polymarket Event BrowserBrowse tradeable Polymarket events by game category."""import htmlis this stdlib or user need to install this package before running this script?
@@ -577,6 +578,15 @@ def print_detail(e, detail):# TELEGRAM# ============================================================def escape_html(text):does escape_html remove the symbols when sending it to telegram? or is it keeping the symbol with different format? can you also make a test run by sending it to my telegram?
@@ -124,0 +141,4 @@"startTime": "2027-03-26T12:00:00Z","markets": [{"sportsMarketType": "moneyline","outcomes": '["Team A", "Team B"]',I think its also possible that the HTML injection come from either of outcomes or sportsMarketType, since we render both of these values to telegram, no? what do you think about it?
Thanks for the review! Responding to your feedback:
1.
import html— stdlib, no install needed.Python's
htmlmodule has been in the standard library since Python 3.2. No external dependencies required.2.
escape_htmlkeeps the text, just in encoded format.It doesn't remove characters — it encodes them so Telegram renders them as literal text instead of interpreting them as HTML:
The text content is preserved. Telegram displays
<as literal<, not as an HTML tag.Let me know your chat ID so I can send a test message to your Telegram to confirm the fix works end-to-end.
lgtm