Skip to content

fix(abstractions): normalize allowed hosts, reject userinfo, and validate URL structure - #824

Open
Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/allowed-hosts-validation-and-normalization
Open

Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/allowed-hosts-validation-and-normalization

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Description

This PR strengthens host validation and normalization in AllowedHostsValidator:

  1. Host normalization & prefix validation:

    • AllowedHostsValidator.__init__ now delegates to set_allowed_hosts to maintain a single normalization path.
    • Trims leading and trailing whitespace from host entries (host.strip()) before storing and checking prefixes.
    • Performs case-insensitive checks for http:// and https:// prefixes (e.g., catching HTTP://... or http://...), raising ValueError consistently.
    • Enforces element type validation (isinstance(host, str)), raising TypeError if a non-string entry is provided.
  2. URL validation & security hardening:

    • Strips leading and trailing whitespace from the candidate URL before parsing.
    • Rejects URLs containing userinfo (o.username or o.password) outright to prevent host spoofing and credential leakage (aligning with the TypeScript implementation).
    • Validates URL structure (scheme, netloc, and hostname) before considering allowed_hosts empty fallback, ensuring malformed URLs are rejected even when allowed hosts are not configured.
  3. Test coverage:

    • Added unit tests covering whitespace trimming, uppercase/padded prefix rejection, non-string element rejection, userinfo rejection, and malformed URL handling.

cc Vincent Biret (@baywet)

Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:35
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 22, 2026 05:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet), opened this PR to normalize allowed hosts, reject URLs with userinfo, and validate URL structure. Unit tests and SonarCloud analysis are all passing. Whenever you have time, please review. Thank you!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants