Skip to content

24 security pagination follows nextlink urls without origin validation#48

Open
cocallaw wants to merge 6 commits intomainfrom
24-security-pagination-follows-nextlink-urls-without-origin-validation
Open

24 security pagination follows nextlink urls without origin validation#48
cocallaw wants to merge 6 commits intomainfrom
24-security-pagination-follows-nextlink-urls-without-origin-validation

Conversation

@cocallaw
Copy link
Copy Markdown
Owner

@cocallaw cocallaw commented Apr 18, 2026

Description

Related Issue

Fixes #24

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test updates

Changes Made

This pull request enhances the security of the Invoke-AzPagedRequest function by validating the nextLink URLs during pagination. The main improvement is to ensure that only trusted hosts over HTTPS are followed, preventing potential security risks from untrusted pagination links.

Security improvements to pagination:

  • Added an $allowedHosts list (currently allowing only "management.azure.com") to restrict which hosts can be followed in paginated responses.
  • Implemented a check to ensure that any nextLink URL uses the HTTPS scheme and its host is in the $allowedHosts list; if not, an error is logged and pagination stops.
  • Updated logic to set $nextUri to $null when there is no nextLink, ensuring proper termination of pagination.

Testing

  • Tested with Azure CLI authentication
  • Tested with Az.Accounts authentication
  • Tested across multiple subscriptions
  • Added/updated unit tests
  • All existing tests pass

Checklist

  • My code follows the existing code style
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have updated the documentation (README, function help, etc.)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally
  • I have checked for any breaking changes

Additional Notes

@cocallaw cocallaw self-assigned this Apr 18, 2026
Copilot AI review requested due to automatic review settings April 18, 2026 18:22
@cocallaw cocallaw added security Security vulnerability or hardening priority: medium Medium priority — plan for near-term labels Apr 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves the security posture of Invoke-AzPagedRequest by validating nextLink pagination URLs before following them, reducing the risk of forwarding ARM bearer tokens to untrusted endpoints.

Changes:

  • Introduces an allowlist of trusted hosts for pagination (management.azure.com).
  • Validates that nextLink uses https and an allowed host; otherwise stops pagination.
  • Ensures pagination terminates cleanly by setting $nextUri = $null when nextLink is absent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Private/Invoke-AzPagedRequest.ps1 Outdated
Comment thread Private/Invoke-AzPagedRequest.ps1 Outdated
Comment thread Private/Invoke-AzPagedRequest.ps1 Outdated
cocallaw and others added 4 commits April 19, 2026 16:29
Replace Write-Error + break with throw when encountering an untrusted nextLink host in Invoke-AzPagedRequest. This ensures the pipeline stops immediately and the error is propagated to callers instead of silently continuing, allowing higher-level code to handle the exception.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: medium Medium priority — plan for near-term security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Pagination follows nextLink URLs without origin validation

2 participants