security(polymarket-browse): use proper URL encoding for --search parameter #34
Reference in New Issue
Block a user
Delete Branch "security/6-url-encoding"
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
Replace manual space replacement with proper URL encoding for --search parameter.
Changes
quotefromurllib.parseq.replace(" ", "%20")withquote(q, safe="")Before
Only spaces were encoded. Special chars like
&,=,%,#could cause URL injection.After
All special characters are properly encoded:
&->%26=->%3D%->%25+->%2B#->%23Testing
70/70 tests passing
- Import quote from urllib.parse - Replace q.replace(' ', '%20') with quote(q, safe='') - Properly encodes: &, =, %, +, #, ?, and other special chars - Prevents URL injection attacksReview requested
what happen with symbols like (, ), +, -, ", etc can you create unit test cases to cover these symbols? I think testing only the q.replace functions should be sufficient. what do you think?
Good point! I added unit tests for URL encoding of special characters:
Test Coverage Added
Test Code
Tests pass: 71/71 passing
The issue was that the old code only did
q.replace(" ", "%20")which only encoded spaces. The fix usesquote(q, safe="")which properly encodes all special characters.lgtm
Pull request closed