Filter the normalized query in strict check_url path filtering#140
Filter the normalized query in strict check_url path filtering#140gaoflow wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #140 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 12 +1
Lines 853 863 +10
Branches 165 167 +2
=========================================
+ Hits 853 863 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@gaoflow Thanks! Since we're at it we could tackle other similar issues here. It is a broader pattern, several filters run on the raw input before |
|
Agreed, it's the same shape as this fix. Mapping
The clean generalization of this PR is to feed each filter the value that survives normalization (as I did for the query via Two questions so I scope this right:
|
|
Yes, you got my point. I think you could address |
The extension and domain filters ran on the raw parsed components while normalize_url() later emits lower-cased, punycode-decoded, default-port- stripped authorities and slash-collapsed paths, so they could reject a URL that normalizes into a perfectly valid one. Most visibly, an IP host with an explicit default port (http://1.2.3.4:80/) was dropped even though it normalizes to http://1.2.3.4/, because domain_filter saw '1.2.3.4:80'. Extract normalize_authority()/normalize_path() from normalize_url() and feed the filters the same normalized values, mirroring the existing clean_query() treatment of the query in the strict path filter.
|
Done — extended in One honest note on scope, since I checked both before wiring them up:
|
In
check_url, strict content filtering ranpath_filteragainst the raw query string:but the query the function ultimately returns has been normalized (tracker parameters and non-whitelisted keys stripped). So an index-style path could survive strict filtering only because of a query parameter that normalization then removes, leaving
check_urlto accept a URL whose own cleaned output it would reject.That breaks idempotence:
check_url(check_url(url, strict=True)[0], strict=True)did not equalcheck_url(url, strict=True). This runspath_filteragainstclean_query(parsed_url.query, strict, language)(the query as it will actually survive), so the strict decision matches the returned URL.test_path_filterwas extended to assert the round-trip is stable for tracker params, non-whitelisted keys, and query-stripped index paths.ruff check,ruff format --check, andmypyare clean.