From bb7eebf502f0aa4c3045508def949c9c2124cdf1 Mon Sep 17 00:00:00 2001 From: shoko <270575765+shokollm@users.noreply.github.com> Date: Thu, 26 Mar 2026 19:11:59 +0000 Subject: [PATCH 1/2] security(polymarket-browse): use proper URL encoding for --search parameter - Import quote from urllib.parse - Replace q.replace(' ', '%20') with quote(q, safe='') - Properly encodes: &, =, %, +, #, ?, and other special chars - Prevents URL injection attacks --- skills/polymarket-browse/scripts/browse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skills/polymarket-browse/scripts/browse.py b/skills/polymarket-browse/scripts/browse.py index e1af87b..1cac50e 100644 --- a/skills/polymarket-browse/scripts/browse.py +++ b/skills/polymarket-browse/scripts/browse.py @@ -13,7 +13,7 @@ import os from concurrent.futures import ThreadPoolExecutor, as_completed from datetime import datetime, timezone, timedelta from typing import Any, Callable, TypedDict -from urllib.parse import urlencode +from urllib.parse import urlencode, quote from urllib.request import urlopen, Request @@ -166,7 +166,7 @@ def fetch_page( ) -> dict[str, Any] | None: base = "https://gamma-api.polymarket.com/public-search" url = ( - f"{base}?q={q.replace(' ', '%20')}&limit={PAGE_SIZE}&page={page}" + f"{base}?q={quote(q, safe='')}&limit={PAGE_SIZE}&page={page}" f"&search_profiles=false&search_tags=false" f"&keep_closed_markets=0&events_status=active&cache=false" ) From 3016d1287c79335dd63513830968b478a8bb1520 Mon Sep 17 00:00:00 2001 From: shoko <270575765+shokollm@users.noreply.github.com> Date: Fri, 27 Mar 2026 01:14:45 +0000 Subject: [PATCH 2/2] test(polymarket-browse): add URL encoding unit tests Add TestUrlEncoding class testing quote() encodes: - Space -> %20 - & -> %26 - = -> %3D - % -> %25 - + -> %2B - ( -> %28 - ) -> %29 - # -> %23 --- skills/polymarket-browse/tests/test_browse.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/skills/polymarket-browse/tests/test_browse.py b/skills/polymarket-browse/tests/test_browse.py index 397c581..a103434 100644 --- a/skills/polymarket-browse/tests/test_browse.py +++ b/skills/polymarket-browse/tests/test_browse.py @@ -1839,5 +1839,25 @@ class TestBrowseEvents(unittest.TestCase): self.assertIn("partial", result) +class TestUrlEncoding(unittest.TestCase): + """Tests for proper URL encoding of search queries.""" + + def test_quote_encodes_special_chars(self): + """quote() should properly encode all special characters.""" + from urllib.parse import quote + + test_cases = [ + ("Team A", "Team%20A"), + ("Team A & Team B", "Team%20A%20%26%20Team%20B"), + ("a=b", "a%3Db"), + ("100%", "100%25"), + ("C++", "C%2B%2B"), + ("Team (A)", "Team%20%28A%29"), + ("Team#1", "Team%231"), + ] + for input_str, expected in test_cases: + self.assertEqual(quote(input_str, safe=""), expected) + + if __name__ == "__main__": unittest.main()