Skip to content

A free open source IT asset/license management system

Added additional pagination tests

snipe3bd99714a843
diff --git a/app/SyncAdapters/CustomHttp/CustomHttpAdapter.php b/app/SyncAdapters/CustomHttp/CustomHttpAdapter.php
index f95f2460f7..81d3237024 100644
--- a/app/SyncAdapters/CustomHttp/CustomHttpAdapter.php
+++ b/app/SyncAdapters/CustomHttp/CustomHttpAdapter.php
@@ -860,7 +860,24 @@ class CustomHttpAdapter extends SyncAdapter implements PushableAdapter
return null;
}
- $endpoint = $origin.($parsed['path'] ?? '/').(isset($parsed['query']) ? '?'.$parsed['query'] : '');
+
+ // Reject path-relative cursors with no leading slash
+ // ("page2" rather than "/page2"). Rebasing those produced
+ // an unparseable "https://hostpage2" that aborted the sync
+ // on the next iteration. Fails safe but we'd rather be
+ // explicit (reported post-fix by Zer0Gate as a robustness
+ // note). Only path+query is kept from the supplied cursor
+ // on purpose, so any path prefix on the configured base
+ // URL is dropped. Absolute cursors are the standard shape
+ // and this matches that.
+ $path = $parsed['path'] ?? '/';
+ if (! str_starts_with($path, '/')) {
+ Log::channel('sync-adapters')->warning($this->name().' pull aborted: next-page URL is path-relative with no leading slash');
+
+ return null;
+ }
+
+ $endpoint = $origin.$path.(isset($parsed['query']) ? '?'.$parsed['query'] : '');
} else {
$pullPath = $this->safeCredential('pull_path');
if ($pullPath !== '' && ! str_starts_with($pullPath, '/')) {
diff --git a/app/SyncAdapters/Intune/IntuneClient.php b/app/SyncAdapters/Intune/IntuneClient.php
index 141233a6f0..961b359685 100644
--- a/app/SyncAdapters/Intune/IntuneClient.php
+++ b/app/SyncAdapters/Intune/IntuneClient.php
@@ -56,8 +56,8 @@ class IntuneClient
if (is_array($scopeTagIds) && $scopeTagIds !== []) {
// Graph expects: $filter=roleScopeTagIds/any(x: x eq 'id1' or x eq 'id2')
// Quote each id and OR them inside a single any() clause.
- $clauses = array_map(fn(string $id) => "x eq '" . addslashes($id) . "'", $scopeTagIds);
- $query['$filter'] = 'roleScopeTagIds/any(x: ' . implode(' or ', $clauses) . ')';
+ $clauses = array_map(fn (string $id) => "x eq '".addslashes($id)."'", $scopeTagIds);
+ $query['$filter'] = 'roleScopeTagIds/any(x: '.implode(' or ', $clauses).')';
}
do {
@@ -88,7 +88,7 @@ class IntuneClient
public function roleScopeTags(): array
{
$graphOrigin = $this->origin($this->graphBaseUrl);
- $url = rtrim($this->graphBaseUrl, '/') . '/v1.0/deviceManagement/roleScopeTags';
+ $url = rtrim($this->graphBaseUrl, '/').'/v1.0/deviceManagement/roleScopeTags';
$out = [];
do {
@@ -125,7 +125,21 @@ class IntuneClient
return null;
}
- return $origin.($parsed['path'] ?? '/').(isset($parsed['query']) ? '?'.$parsed['query'] : '');
+ // Reject path-relative cursors with no leading slash
+ // ("page2" rather than "/page2"). Rebasing those produced an
+ // unparseable "https://hostpage2" that aborted the sync on the
+ // next iteration. Fails safe but we'd rather be explicit
+ // (reported post-fix by Zer0Gate as a robustness note).
+ // Only path+query is kept from the supplied cursor on purpose,
+ // so any path prefix on the configured base URL (not Graph's
+ // case, but legal in general) is dropped. Absolute cursors are
+ // the standard shape here and this matches that.
+ $path = $parsed['path'] ?? '/';
+ if (! str_starts_with($path, '/')) {
+ return null;
+ }
+
+ return $origin.$path.(isset($parsed['query']) ? '?'.$parsed['query'] : '');
}
/**
diff --git a/tests/Feature/SyncAdapters/CustomHttp/CustomHttpAdapterTest.php b/tests/Feature/SyncAdapters/CustomHttp/CustomHttpAdapterTest.php
index 3ee26bd46d..bcd229451c 100644
--- a/tests/Feature/SyncAdapters/CustomHttp/CustomHttpAdapterTest.php
+++ b/tests/Feature/SyncAdapters/CustomHttp/CustomHttpAdapterTest.php
@@ -578,6 +578,39 @@ class CustomHttpAdapterTest extends TestCase
&& $request->hasHeader('Authorization', 'Bearer leak-canary'));
}
+ /**
+ * Reporter-identified robustness note (Zer0Gate post-fix for
+ * GHSA-cf4m-f928-928g): if upstream emits a path-relative cursor
+ * with no leading slash (e.g. `"next": "page2"`), parse_url returns
+ * `path => "page2"` and the earlier concatenation produced
+ * `https://hostpage2` which was unparseable. Pagination aborted on
+ * the next iteration (fail-safe) but we'd rather be explicit. The
+ * adapter now rejects the cursor and logs the abort when the path
+ * lacks a leading slash.
+ */
+ public function test_next_url_pagination_rejects_relative_cursor_without_leading_slash()
+ {
+ $adapter = $this->configuredAdapter([
+ 'records_path' => 'rows',
+ 'field_source_id' => 'id',
+ 'pagination_style' => 'next_url',
+ 'pagination_next_path' => 'links.next',
+ ]);
+
+ Http::fake([
+ 'vendor.example/api' => Http::response([
+ 'rows' => [['id' => 'first']],
+ 'links' => ['next' => 'page2'],
+ ]),
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertCount(1, $records, 'First page processes, pagination stops at malformed cursor.');
+ Http::assertNotSent(fn ($request) => str_contains($request->url(), 'vendor.examplepage2')
+ || str_contains($request->url(), 'vendor.example/page2'));
+ }
+
public function test_pull_path_query_string_survives_pagination_style_none()
{
// Regression test for #19755. The admin configures a filtered
@@ -597,7 +630,7 @@ class CustomHttpAdapterTest extends TestCase
iterator_to_array($adapter->pull());
- Http::assertSent(fn($request) => str_contains($request->url(), 'ancestor_group_id=42')
+ Http::assertSent(fn ($request) => str_contains($request->url(), 'ancestor_group_id=42')
&& str_contains($request->url(), 'limit=100'));
}
@@ -618,7 +651,7 @@ class CustomHttpAdapterTest extends TestCase
iterator_to_array($adapter->pull());
- Http::assertSent(fn($request) => str_contains($request->url(), 'ancestor_group_id=42')
+ Http::assertSent(fn ($request) => str_contains($request->url(), 'ancestor_group_id=42')
&& str_contains($request->url(), 'limit=50')
&& str_contains($request->url(), 'offset=0'));
}
@@ -646,8 +679,8 @@ class CustomHttpAdapterTest extends TestCase
$records = iterator_to_array($adapter->pull());
- $this->assertSame(['a', 'b'], array_map(fn($r) => $r->sourceId, $records));
- Http::assertSent(fn($request) => str_contains($request->url(), 'skiptoken=next-page-cursor'));
+ $this->assertSame(['a', 'b'], array_map(fn ($r) => $r->sourceId, $records));
+ Http::assertSent(fn ($request) => str_contains($request->url(), 'skiptoken=next-page-cursor'));
}
public function test_pagination_style_none_yields_one_page_and_stops()
diff --git a/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php b/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php
index 080edf03b3..a3aa112bbb 100644
--- a/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php
+++ b/tests/Feature/SyncAdapters/Intune/IntuneAdapterTest.php
@@ -120,6 +120,36 @@ class IntuneAdapterTest extends TestCase
&& $request->hasHeader('Authorization', 'Bearer leak-canary'));
}
+ /**
+ * Reporter-identified robustness note (Zer0Gate post-fix for
+ * GHSA-cf4m-f928-928g): if upstream emits a path-relative cursor
+ * with no leading slash (e.g. `"@odata.nextLink": "page2"`),
+ * `parse_url` returns `path => "page2"` and the earlier shape
+ * concatenated it directly onto the origin, producing an
+ * unparseable "https://hostpage2". Pagination aborted on the next
+ * iteration (fail-safe) but we'd rather be explicit. The
+ * rebasedCursor helper now rejects the cursor outright when its
+ * path lacks a leading slash.
+ */
+ public function test_relative_nextlink_cursor_without_leading_slash_terminates_pagination_without_malformed_request()
+ {
+ $adapter = $this->configuredAdapter();
+
+ Http::fake([
+ '*/oauth2/v2.0/token' => Http::response(['access_token' => 'stub', 'expires_in' => 3600]),
+ 'graph.microsoft.com/v1.0/deviceManagement/managedDevices' => Http::response([
+ 'value' => [$this->intuneDevice(id: 'guid-1', name: 'host-one')],
+ '@odata.nextLink' => 'page2',
+ ]),
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertCount(1, $records, 'First page should still process, pagination stops at malformed cursor.');
+ Http::assertNotSent(fn ($request) => str_contains($request->url(), 'graph.microsoft.compage2')
+ || str_contains($request->url(), 'graph.microsoft.com/page2'));
+ }
+
public function test_scope_tag_filter_resolves_names_to_ids_and_sends_odata_filter()
{
$adapter = $this->configuredAdapter(scopeTagFilter: 'Marketing, 7');