Skip to content
cccskills
FreePublished on GitHub

nosql-injection-defense

Use this skill whenever user-controlled input flows into a MongoDB query, filter, or update. Trigger words: NoSQL Injection, ユーザー入力, req.body, クエリに渡す, find, filter, spread, $where, 検索条件, security review.

The English summary is being prepared. Showing the original description.

Works withMongoDB
See how to install

Files included (1)

  • SKILL.md2.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

NoSQL Injection 防御

いつ使うか

  • ユーザー入力(リクエストボディ・クエリ文字列・フォーム)がクエリの条件に入るとき。
  • 既存コードのクエリ構築箇所をセキュリティレビューするとき。

やること

  • 入力はまず Zod で型強制し、想定する型(string/number 等)に確定させてから query へ。
  • クエリのキー(フィールド名)と値を明示的に組み立てる。入力でキーを決めさせない。
  • 演算子($gt $where 等)を含むオブジェクトを入力から受け取らない。
  • 必要なら sanitizeFilter 相当の方針で $/. を含むキーを拒否する。

守るルール

  • ❌ find({ ...req.body }) のような spread 禁止(任意の演算子を注入される)。
  • ❌ $where に文字列を渡さない(任意 JS 実行)。
  • ✅ 入力は Zod で string()/number() 等に強制してから比較に使う。
  • ✅ 検索条件のフィールド名はコード側の許可リストで決める。

典型例(コード片)

import { z } from 'zod';

// ❌ 危険:{ email: { $ne: null } } を送られると全件一致
async function badLogin(body: unknown) {
  return UserModel.findOne({ ...(body as object) });
}

// ✅ 安全:型強制 + フィールド固定
const Login = z.object({ email: z.string().email(), password: z.string().min(1) });
async function login(body: unknown) {
  const { email } = Login.parse(body);     // string に確定
  return UserModel.findOne({ email });      // 演算子注入の余地なし
}

アンチパターン

  • req.query をそのままフィルタに展開する。
  • 「型は string のはず」と決めつけ、検証なしで比較に使う。
  • 入力にフィールド名(ソートキー等)を自由に指定させる。

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Use this skill when creating or reviewing Next.js Route Handlers (app/api), adding rate limiting, input validation, or auth to API endpoints. Trigger words: API ルート, Route Handler, app/api, エンドポイント, レート制限, 入力検証, CORS, ヘッダー, 認証付き API, hardening.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when implementing full-text search, autocomplete, or vector/semantic search and RAG with MongoDB Atlas. Trigger words: 全文検索, あいまい検索, オートコンプリート, ベクトル検索, セマンティック検索, 類似検索, Atlas Search, $search, $vectorSearch, RAG, embedding.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when implementing sign-in, sessions, authorization checks, or protecting routes and Server Actions. Trigger words: 認証, ログイン, サインイン, セッション, 認可, 権限チェック, Better Auth, Auth.js, 保護, ミドルウェア, getSession.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when starting a new session, opening this project for the first time, or when you need to recall the project's tech stack, hard rules, and which other skills exist. Trigger words: セッション開始, このプロジェクト, 全体像, どのスキル, 何から, getting started, overview.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when setting up or modifying CI pipelines, GitHub Actions workflows, or automated checks (lint, typecheck, test, build) for this project. Trigger words: CI, GitHub Actions, ワークフロー, パイプライン, 自動テスト, lint チェック, typecheck, ビルド検証, .github/workflows.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

Use this skill when writing end-to-end tests, browser automation, or verifying user flows in a real browser. Trigger words: E2E, Playwright, ブラウザテスト, ユーザーフロー, 結合テスト, シナリオテスト, ログインテスト, getByRole, expect.

The English summary is being prepared. Showing the original description.

Akira-Papa/claude-code-nextjs-mongo-template-16Updated May 24, 2026

See all skills by Akira-Papa

Report a problem with this skill