Conversation
…redential leaks - Refactor URL parsing onto shared _split_url() primitive in nac_test/utils/url.py - Handle malformed/non-numeric ports in _safe_port() without raising ValueError - Strip embedded user credentials and fix schemeless host:port in extract_host() - Sanitize failure.controller_url directly at the pre-flight failure report boundary - Add leak regression tests across banners, controller_auth, and combined_generator
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.
Description
Sanitizes controller URLs for display, banners, curl examples, failure reports, and auth check results/logs by stripping embedded user credentials (
user:password@oruser@), trailing slashes (/), and surrounding whitespace while preserving scheme, hostname, port, path, query parameters, and fragments. Also hardensextract_host()to strip userinfo and accurately extract host from schemelesshost:portURLs.Closes
Related Issue(s)
Type of Change
Test Framework Affected
Network as Code (NaC) Architecture Affected
Platform Tested
Key Changes
nac_test/utils/url.py):_split_url()so authority always lands innetloceven without scheme, eliminating code duplication across URL utilities._safe_port()to preventValueErrorcrashes on malformed/non-numeric/out-of-range ports (e.g.,:notaportor:99999), preserving the raw port text for user-visible typo detection.sanitize_url_for_display(url: str) -> strusing the shared primitive, correctly handling edge cases like@in unencoded passwords, query params with@, IPv6 brackets, and protocol-relative URLs.extract_host(url: str) -> str(drive-by fix): strips embedded userinfo (preventing password leaks intopingcommands/reports) and corrects schemelesshost:port/pathparsing which previously returned the port instead of the hostname. Hostnames are consistently normalized to lowercase.nac_test/core/controller_auth.py: Sanitized URL inpreflight_auth_checkbefore logging tologger.info(...), preventing credential leakage into log files.nac_test/core/reporting/combined_generator.py: Sanitized URL directly at the_generate_pre_flight_failure_reportboundary forcontroller_url,host, and_get_curl_example, ensuring HTML failure reports never expose credentials even when called independently.nac_test/cli/ui/banners.py: Sanitized URLs indisplay_auth_failure_banneranddisplay_unreachable_banner.sanitize_url_for_display) and auth cache keys (raw_url.rstrip("/")).TestSanitizeUrlForDisplayandTestExtractHostintests/unit/utils/test_url.pywith explicit test IDs covering standard URLs, embedded credentials, IPv6 literals, malformed ports,@edge cases, and case normalization.tests/unit/core/test_combined_generator.py,tests/unit/core/test_controller_auth.py, andtests/unit/cli/ui/test_banners.pyensuring credentials never appear in stdout, logs, or HTML reports.Testing Done
pytest/pre-commit run -a)Test Commands Used
Checklist
pre-commit run -apasses)Screenshots (if applicable)
N/A
Additional Notes
None