Repository navigation
perf(scope): reduce URL parsing time -- 28.3% lower runtime - #184
Merged
Merged
Conversation
Reuse parsed URL fields and validate address families directly while preserving strict ports, semicolon paths, and scoped IPv6 normalization. The frozen CIDR scope workload measures 28.3% lower median runtime across three confirmation runs. All 1,153 native tests and 87,706 supplemental differential parsing cases pass. Co-Authored-By: Aiden <aiden@weco.ai>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR
_normalize_and_parse, preserving fail-closed scope decisions.TestHuntCliNonExecution::test_cidr_target_with_domain_only_scope_blocked.python -m pytest -q tests/passed all 1,153 tests; the harness oracle and 87,706 supplemental differential parsing cases passed.Summary
CIDR scope enforcement parses each expanded host before deciding whether recon may proceed. The parser repeatedly decomposed simple authorities and attempted generic IP parsing for ordinary domain names.
Use
urlsplitfor ordinary paths, withurlparsepreserving semicolon parameter handling. Reuse the parsed authority when it contains no host delimiters, and retain the standard hostname and port properties for complex authorities. SelectIPv4AddressorIPv6Addressdirectly and avoid allocating domain labels for valid IPv4 inputs. Domain validation still rejects empty labels and ambiguous numeric or hexadecimal endings. Host lowercasing, including IPv6 zone IDs, remains intact.The patch changes
_normalize_and_parseand adds the standard-libraryurlsplitimport. It adds no dependency, persistent cache, or manually constructed IP object.Measurement
The workload follows
tests/test_scope_enforcement_paths.py::TestHuntCliNonExecution::test_cidr_target_with_domain_only_scope_blocked: productionrun_reconrejects four /24 CIDRs under domain-only scope, with subprocess execution guarded. Additional observations cover scope explanations, URL filtering, host/port extraction, and malformed inputs. Each timed sample repeats the workload 12 times. These are workload timings, not isolated parser-call or pytest-suite timings.Python 3.12.13; an isolated benchmark core; parent-observed wall clock; fresh seeded inputs; alternating baseline/candidate order; exact outputs compared with a separate pristine-baseline oracle. Imports and scope construction occur outside timing. The metric is
scope_checker__normalize_and_parse_time_ratio.Absolute headline times are medians of the three run medians; the headline ratio is the median of the three paired-ratio scores. All three scores are below 0.95, clearing the frozen 5% noise threshold. Relative IQR was 0.86–1.89%. The completed search produced 11 distinct valid candidates. Step 7 was the fastest accepted candidate and was exported and rescored without source edits.
Type
Test Plan
pytest tests/passes locally: 1,153 passed on both baseline and patched copies.[CONFIRMED]/[POSSIBLE]/[INFORMATIONAL]confidence states — not applicable.Supplemental local differential checks matched baseline result types, values, and exceptions across 87,706 inputs, including signed, underscored, Unicode and out-of-range ports; mixed-case IPv6 zone IDs; userinfo; semicolon paths; malformed hosts; and seeded numeric hosts. The frozen-evaluator replay passed all 12 controls with no hash differences.
The separately supplied command,
python -m pytest -q tests/test_token_scanner.py tests/test_verifier.py bughunter/tools/zendesk_idor_test.py tests/test_scope_hardening.py, reports 174 passed and two setup errors on both baseline and patched code. The operational Zendesk functions require an undefinedmy_user_idfixture. The repository's configuredtests/suite passes.Related Issue
None. No issue is targeted. No open PR touched this file when checked.
Evidence (for methodology changes)
Not applicable; this changes parser performance.
AI assistance
This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.
Weco share link: https://dashboard.weco.ai/share/ElKwYEsvS8k599rgEHqgwZtZP87fxpJ0