Repository navigation
fix(#6380, #6381): stale bucket-selection total after bucket removal, and restore's unrevalidated HTTP redirects - #6449
Conversation
…BUCKET -b, and restore database following unrevalidated HTTP redirects #6380 - LocalDocumentType.removeBucketInternal shrank the bucket list but never re-bound the type's bucket-selection strategy, so a round-robin (or thread, or partitioned) strategy kept handing out indexes sized to the pre-removal bucket count. The very next index at the old boundary landed on buckets.get(index) for an index that no longer existed, throwing IndexOutOfBoundsException on an otherwise ordinary insert. addBucketInternal already rebinds after growing the list; removeBucketInternal now does the same after shrinking it. #6381 - restore database opened its HTTP(S) input with a bare HttpURLConnection, which follows same-protocol 3xx redirects on its own with no revalidation of the redirect target. The server's one-shot pre-check (PostServerCommandHandler.validateClientRestoreImportUrl) only resolves and checks the original hostname before handing the raw URL to restore, so a public-looking host that redirects to a private or link-local address walked straight past it - the same class of bypass IMPORT DATABASE was hardened against. openInputFile() now opens the connection through SafeHttpFetcher, the shared fetcher that re-validates scheme and address on every hop and is gated by the same SERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLS setting the pre-check uses.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 92.31% diff coverage · -6.53% coverage variation
Metric Results Coverage variation ✅ -6.53% coverage variation Diff coverage ✅ 92.31% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (1dd19de) 162935 129963 79.76% Head commit (7993a29) 195329 (+32394) 143046 (+13083) 73.23% (-6.53%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6449) 13 12 92.31% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
ReviewBoth fixes are narrowly scoped, well-reasoned, and each ships a regression test that fails on pre-fix code. Nice work. #6380 - stale bucket-selection strategy after
|
Codacy's PMD flagged RESERVED_ADDRESSES declared after the private RestoreCallback interface. Moved above it, matching the class's other field-then-nested-type ordering.
ReviewBoth fixes are targeted, well-reasoned, and each ships a regression test that reproduces the original bug and fails against pre-fix code. Nice use of the shared #6380 — stale bucket-selection strategy after
|
…server's own configuration The claude-review round on this PR pointed out that the fetch-time check added for #6381 (FullRestoreFormat.openInputFile) reads the static, JVM-wide GlobalConfiguration value, while the server's pre-check (PostServerCommandHandler.validateClientRestoreImportUrl) reads the setting from its own per-instance ContextConfiguration. An operator who enables SERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLS only on that server's own configuration (the mechanism the existing tests already exercise) would have the pre-check accept a restore that the fetch then refused anyway - fail-closed, not an SSRF hole, but a silent break of the documented opt-out. Restore has no server object to consult on its own: it is invoked reflectively from PostServerCommandHandler, but also runs standalone from the CLI with no server at all. So rather than making FullRestoreFormat guess at a server context, the caller that already resolved the setting threads its answer through explicitly: RestoreSettings gains a nullable allowLocalUrls override, Restore.setAllowLocalUrls(boolean) sets it (mirroring the existing setLogger/ setRestoreThreads reflective setters), and the handler calls it with the exact boolean its own pre-check already used. A CLI/embedded caller that never sets it keeps falling back to the static default, unchanged.
ReviewReviewed the two fixes and their regression tests. Both are correct, minimal, and well-targeted. #6380 - stale bucket-selection strategy after
|
…cked local restore fetch The integration-tests CI lane failed on Issue6086ParallelRestoreIT.anArchiveReadOverHttpFallsBackToTheSequentialWalk after the #6381 fix: the test restores from its own loopback HttpServer, and SERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLS now defaults to false, so the fetch correctly refused to reach 127.0.0.1 - exactly the new protection working as intended, just against test infrastructure rather than an attacker. The test now opts in the same way a trusting operator would, mirroring Issue6381RestoreSsrfTest's own use of the same flag.
Review of #6449Reviewed both fixes end-to-end (bucket-strategy staleness + restore SSRF), including the follow-up commits that tightened them. Solid work overall - the fixes are minimal, symmetric with existing patterns, and each is backed by a regression test that actually reproduces the pre-fix failure. #6380 - stale bucket-selection strategy after
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6449 +/- ##
==========================================
+ Coverage 71.04% 71.06% +0.01%
==========================================
Files 1861 1861
Lines 162935 162942 +7
Branches 34390 34391 +1
==========================================
+ Hits 115764 115798 +34
+ Misses 33012 32981 -31
- Partials 14159 14163 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…isagreed on the local-URL policy PostServerCommandHandler's 'import database' pre-check validated the URL against SERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLS (read from this server's own configuration), while the actual fetch deep inside SourceDiscovery re-derived its own answer from the different, static-only SERVER_SECURITY_IMPORT_BLOCK_LOCAL_NETWORKS. An operator enabling the documented opt-out on their server's own configuration therefore got past the pre-check, only to have the fetch refuse the same URL anyway - both fail closed today, so not an active bypass, but exactly the same class of divergence already fixed for 'restore database' in ArcadeData#6381/ArcadeData#6449. Threads the pre-check's resolved boolean explicitly into the importer, mirroring the restore-side fix: Importer.setAllowLocalUrls() for the SSE path (same reflective call restore already makes), and the SQL command's per-call ContextConfiguration for the synchronous fallback, which goes through ImportDatabaseStatement instead of constructing Importer directly. The override is deliberately not exposed through IMPORT DATABASE's own 'WITH ...' settings syntax, so a client cannot self-authorize past the SSRF guard from SQL text alone.
Summary
LocalDocumentType.removeBucketInternalshrank the bucket list but never re-bound the bucket-selection strategy, so a round-robin (or thread, or partitioned) strategy kept its pre-removal bucket count and could hand out an index one past the new last bucket, throwingIndexOutOfBoundsExceptionon an ordinary insert afterALTER TYPE ... BUCKET -b. Fixed by callingbucketSelectionStrategy.setType(this)at the end ofremoveBucketInternal, symmetric to the existing call inaddBucketInternal.restore database's HTTP(S) input path used a bareHttpURLConnection, which follows same-protocol 3xx redirects itself with no revalidation of the redirect target. The server's one-shot pre-check only validates the original hostname before handing the URL to restore, so a redirect (or DNS rebinding) to a blocked address bypassed it - the class of SSRF bypassIMPORT DATABASEwas already hardened against.openInputFile()now routes through the sharedSafeHttpFetcher, which re-validates scheme and address on every hop, gated by the existingSERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLSsetting.Test plan
Issue6380RemoveBucketStrategyRefreshTest: new regression test - fails withIndexOutOfBoundsExceptionagainst the pre-fix code, passes after the fix.Issue6381RestoreSsrfTest: new regression test - proves restore refuses a local/blocked address by default and follows a redirect only when the operator explicitly opts in viaSERVER_RESTORE_IMPORT_ALLOW_LOCAL_URLS.engineandintegrationmodule test suites run green (mvn -o -pl integration -am test -DexcludedGroups=benchmark,slow,vector): 588+ tests, 0 failures.com.arcadedb.schema.*Testrun (436 tests) green.🔗 Closes #6380, closes #6381