Skip to content

fix(abstractions): add null checks and reject userinfo in AllowedHostsValidator - #2217

Merged
Vincent Biret (baywet) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/allowed-hosts-null-safety-and-userinfo
Oct 26, 2026
Merged

Vincent Biret (baywet) merged 2 commits into
microsoft:mainfrom
hardikkaurani:fix/allowed-hosts-null-safety-and-userinfo

Conversation

@hardikkaurani

@hardikkaurani Hardik K (hardikkaurani) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR strengthens AllowedHostsValidator.isUrlHostValid(URI) in kiota-java:

  1. Validation & userinfo rejection:

    • Retains @Nonnull final URI uri and validates via Objects.requireNonNull(uri, "parameter uri cannot be null") to fail fast, preserving compile-time and static analysis safety.
    • Validates that uri.getScheme() and uri.getHost() are non-empty before proceeding, preventing unexpected exceptions on opaque URIs (e.g. mailto:, URNs, or relative path URIs).
    • Rejects URIs containing userinfo (uri.getUserInfo() != null && !uri.getUserInfo().isEmpty()) to protect against host spoofing and credential leaks (consistent with other Kiota SDKs).
    • Enforces URI structure and userinfo rejection even when allowedHosts is empty (validHosts.isEmpty()).
  2. Tests:

    • Added unit tests covering defensive null handling, URIs without scheme/host, URIs with userinfo, and empty allowedHosts validation.

cc Vincent Biret (@baywet)

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

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.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet), submitted this PR to add null checks and userinfo rejection in AllowedHostsValidator with full unit tests. All checks and builds are green. Whenever you have some time, could you please review? Thank you!

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.

🟢 Approval recommended

The focused validation changes match the stated requirements, include regression coverage, and have no identified blocking issues.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 23, 2026 14:06

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.

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.

🟢 Approval recommended

The focused validation changes and regression tests have no identified blocking issues; tests were not executed.

No open issues 🎉

Review effort: Balanced

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

Following up on the review feedback:

  • Retained @Nonnull final URI uri and added Objects.requireNonNull(uri, "parameter uri cannot be null") to preserve static analysis and compile-time guarantees while failing fast at runtime.
  • Updated the test suite to verify NullPointerException for null URIs (using the project's nullValue() helper to satisfy SpotBugs).
  • All CI checks, CodeQL, API level linter, and Gradle builds are passing green, with no open issues.

Whenever you have a moment, could you please take another look? Thank you!

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 26, 2026
@baywet
Vincent Biret (baywet) merged commit ab6fae4 into microsoft:main Oct 26, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants