Skip to content

dbviewer: block cross-db $lookup form in protected-join guard#7692

Merged
ar2rsawseen merged 2 commits into
masterfrom
fix/dbviewer-crossdb-lookup
Jun 9, 2026
Merged

dbviewer: block cross-db $lookup form in protected-join guard#7692
ar2rsawseen merged 2 commits into
masterfrom
fix/dbviewer-crossdb-lookup

Conversation

@ar2rsawseen

Copy link
Copy Markdown
Member

Follow-up to #7686 (review finding). The DB Viewer protected-collection join guard only recognized the string form of $lookup.from, so the cross-database object form — {from: {db, coll}} — slipped past the check and could join into members/auth_tokens.

Fix

  • joinTargetsOf now extracts the collection name from both the string and the {db, coll} object forms (via a collectionOf helper), for $lookup/$graphLookup/$unionWith, so the hard-rule join guard holds regardless of syntax.
  • Minor: aggregate() checks Array.isArray before pushing the iDisplayLength $limit, so a non-array pipeline returns a controlled error.

Tests

Adds a regression test for the {db, coll} cross-db form (28 guard tests pass).

🤖 Generated with Claude Code

joinTargetsOf only extracted $lookup.from when it was a string, so the
cross-database object form (from: {db, coll}) bypassed the members/auth_tokens
join check. Extract the collection from both the string and {db, coll} forms.
Also reorder aggregate() to check Array.isArray before pushing the
iDisplayLength $limit. Adds a cross-db regression test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the DB Viewer aggregation “protected join” guard so it also blocks the cross-database object form of join targets (e.g. $lookup.from: {db, coll}), preventing bypasses that could join into redacted collections like members and auth_tokens. It also makes aggregation handling more robust by avoiding mutations on non-array pipelines.

Changes:

  • Extend join target extraction to handle both string and {db, coll} forms for $lookup/$graphLookup/$unionWith via a collectionOf helper.
  • Add a regression unit test covering $lookup cross-db object form joins into members.
  • Move the iDisplayLength $limit push behind an Array.isArray check to avoid runtime errors on invalid pipeline types.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plugins/dbviewer/api/parts/aggregation_guard.js Adds collectionOf and uses it to recognize protected join targets in both string and {db, coll} forms.
plugins/dbviewer/api/api.js Prevents pushing $limit onto non-array pipelines by validating the pipeline type before mutation.
test/unit-tests/plugins.dbviewer.aggregation-guard.js Adds regression coverage for $lookup.from cross-db object form joining into members.

Comment thread plugins/dbviewer/api/api.js
Comment thread test/unit-tests/plugins.dbviewer.aggregation-guard.js
…s-db test

- non-array aggregation is a client input error -> 400 (was 500), with an
  explicit return
- add a regression test for the cross-db {db, coll} form on $graphLookup too

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ar2rsawseen added a commit that referenced this pull request Jun 9, 2026
Mirror of the master review fixes (#7692) onto the 24.05 backport.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ar2rsawseen ar2rsawseen merged commit 3e73bd7 into master Jun 9, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants