Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Api Mongo Agg Facet Bypass

ASecurity

Bypass a MongoDB aggregation-pipeline stage allowlist by nesting disallowed read stages inside $facet, then $unionWith/$lookup sibling collections to exfiltrate secrets (invite tokens, creds, hashes). Load when: an endpoint accepts a user-supplied `pipeline` (or errors like "operator-form queries not accepted, use the pipeline parameter"), a Node/Express + MongoDB backend, 24-hex `_id`s, or an "advanced query" API. Authorized targets only.

20 stars
0 votes
0 copies
0 views
Added 9/22/2026
ai-agentspythongoshellbashnodeexpressapidatabasebackend

Works with

api

Security Analysis

A100/100

Scanned 9/22/2026

$npx -y skills add NoorQureshi/SploitAgent --skill api-mongo-agg-facet-bypass --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Mongo Agg Facet Bypass?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Api Mongo Agg Facet Bypass
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/noorqureshi-api-mongo-agg-facet-bypass/badge)](https://www.skillsdirectory.com/skills/noorqureshi-api-mongo-agg-facet-bypass)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: api-mongo-agg-facet-bypass
description: >
  Bypass a MongoDB aggregation-pipeline stage allowlist by nesting disallowed read stages
  inside $facet, then $unionWith/$lookup sibling collections to exfiltrate secrets
  (invite tokens, creds, hashes). Load when: an endpoint accepts a user-supplied `pipeline`
  (or errors like "operator-form queries not accepted, use the pipeline parameter"), a
  Node/Express + MongoDB backend, 24-hex `_id`s, or an "advanced query" API. Authorized targets only.
domain: api
type: technique
stability: learning
modes: [pentest, bugbounty]
severity: high
owasp: [A03:2021-Injection]
cwe: [CWE-943]
schema_version: 1
---

# MongoDB aggregation injection — $facet allowlist bypass → cross-collection read

## When it applies
- An API runs a user-controlled **aggregation pipeline** on a fixed collection
  (`db.collection('x').aggregate(userPipeline)`), usually exposed as a `pipeline`
  query/body parameter for "advanced" search.
- The server defends with a **stage allowlist** — only screens the *top-level* stage
  names (`$match/$project/$sort/$limit/$facet` allowed; `$lookup/$unionWith/$group/…`
  rejected with something like `"invalid or disallowed pipeline stage"`).
- Tell-tale that a `pipeline` param even exists: sending the normal search term as a
  Mongo **operator object** (`?q[$ne]=x`) returns a hint such as
  `"Operator-form queries not accepted on 'q'. Use the 'pipeline' parameter…"`.

## Why it works
The allowlist inspects only the outermost stage keys. **`$facet` runs sub-pipelines
whose stages are never re-screened** by the app, so a disallowed read stage placed
inside a `$facet` sub-pipeline reaches MongoDB unchecked. MongoDB itself still forbids
a few stages inside `$facet` (`$out/$merge/$collStats/$indexStats/$listCatalog/$documents`),
but it **permits `$lookup` and `$unionWith`** there — and those read *other collections
in the same database*. That turns a "search our metadata" endpoint into "read any
collection in this DB".

## Method
1. **Confirm the pipeline sink & allowlist.** Baseline `?pipeline=[{"$limit":1}]` returns
   docs; `?pipeline=[{"$count":"n"}]` / `$group` / top-level `$unionWith` → "disallowed stage".
2. **Leak the namespace.** Trigger a Mongo error (e.g. `$facet` containing a stage Mongo
   rejects) — the 500 body usually includes `"ns":"<db>.<collection>"`. Now you know the DB.
3. **Read a sibling collection** (drop the base docs first so output is only the target):
   ```json
   [{"$facet":{"r":[
       {"$match":{"<anyfield>":"__none__"}},
       {"$unionWith":{"coll":"<target_collection>","pipeline":[{"$limit":20}]}}
   ]}}]
   ```
   `$unionWith` here is legal ONLY inside `$facet` (top-level → allowlist rejects it).
4. **Enumerate collection names** you don't know: build one `$facet` with many sub-pipelines,
   each `$unionWith`-ing a candidate name + `$limit:1`; names that return docs exist & are
   non-empty. **Brute the same naming style as any collection you already know**
   (e.g. known `mds_entries` ⇒ try `pending_invites`, `operator_accounts`, `invite_tokens`).
5. **Loot** the target collection (invite tokens, password hashes, session docs, API keys)
   and pivot (register/login, crack hashes, forge sessions).

## Tools
- `curl -G --data-urlencode 'pipeline=…'` (single-quote so the shell doesn't eat `$`), or a
  short Python `urllib` helper that JSON-encodes and URL-encodes the pipeline (cleaner for
  building big `$facet` maps and parsing results). See `aegis/exploit-dev/*.py` for a worked helper.

## Gotchas
- **Shell `$` expansion**: `"?q[$ne]=x"` in double quotes becomes `?q[]=x` in bash/zsh —
  you'll wrongly conclude "not injectable". Use single quotes / `--data-urlencode`.
- **`$unionWith`/`$lookup` are same-database only.** Cross-DB `{from:{db,coll}}` is a hard
  MongoDB block ("not supported for db: X") for everything except a couple of `config.*`
  system namespaces (empty on standalone). If the app data seems missing, it's almost always
  a *collection-name* you haven't guessed in the *same* DB — not a different DB.
- `$collStats/$listCatalog/$documents` can't nest in `$facet` (Mongo rejects) — so you can't
  cheaply list empty collections; rely on `$unionWith` name-brute for non-empty ones.
- Empty `$unionWith`/`$lookup` result = collection empty *or* absent; the two look identical.

## Verify success
Step 3/4 returns documents whose **fields differ from the base collection** (e.g. a
`token`/`password`/`session` field where the endpoint should only ever return metadata).
That is data exfiltration from a collection the endpoint never intended to expose.

## Learned on
**AEGIS lab, 2026-08** — `GET /api/v1/aegis-mds/search?pipeline=` on `aegis_mds.mds_entries`;
`$facet`→`$unionWith pending_invites` leaked an unredeemed 64-hex WebAuthn invite token →
`register/begin` (attestation:"none") → software authenticator → login. Full worked example
in `aegis/notes.md` (§4–6).

Attribution

NoorQureshiNoorQureshi
View sourceSee grades on GitHubMore from NoorQureshi →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698461 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →