Skip to content

security: ensure COUNT(*) selects have restricted format#3765

Merged
farnabaz merged 2 commits intomainfrom
security/sql-safe-check
Apr 13, 2026
Merged

security: ensure COUNT(*) selects have restricted format#3765
farnabaz merged 2 commits intomainfrom
security/sql-safe-check

Conversation

@farnabaz
Copy link
Copy Markdown
Member

@farnabaz farnabaz commented Apr 9, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
content Ready Ready Preview, Comment Apr 9, 2026 3:53pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 768944f9-f260-45b3-a453-af97b3960f88

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1116f and 1e981b9.

📒 Files selected for processing (1)
  • test/unit/assertSafeQuery.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/assertSafeQuery.test.ts

📝 Walkthrough

Walkthrough

The change tightens SQL validation by updating SQL_COUNT_REGEX in the security module to require the exact COUNT(...) as <alias> form (anchored, case-insensitive) instead of accepting any COUNT(...) anywhere in the column string. A new unit test was added asserting that a query containing COUNT(*) as c alongside a nested subquery projecting from sqlite_master is rejected by assertSafeQuery.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is a template with unchecked items and no actual description content provided by the author, making it vague and non-informative about the changeset. Provide a meaningful description explaining why the SQL_COUNT_REGEX was tightened, what security issue it addresses, and how the regex change affects validation behavior.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'security: ensure COUNT(*) selects have restricted format' directly and clearly describes the main change: tightening the SQL_COUNT_REGEX validation to restrict COUNT projections to a specific format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/sql-safe-check

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/unit/assertSafeQuery.test.ts`:
- Line 47: Replace the fragile test entry in test/unit/assertSafeQuery.test.ts
with a query that isolates the COUNT alias check (e.g. "SELECT COUNT(*) as count
FROM _content_content") so it only exercises the COUNT(...) as count restriction
and cannot fail for unrelated multi-column/select-from issues, and ensure the
test mapping line ends with the required trailing comma to satisfy linting;
target the test case string that currently contains "COUNT(*) as c" and update
it to use "COUNT(...) as count" and include the trailing comma.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 071c5dd8-fa66-4819-a292-c3d7a187cd65

📥 Commits

Reviewing files that changed from the base of the PR and between 06c84f5 and 7e1116f.

📒 Files selected for processing (2)
  • src/runtime/internal/security.ts
  • test/unit/assertSafeQuery.test.ts

Comment thread test/unit/assertSafeQuery.test.ts Outdated
'SELECT * FROM _content_test WHERE (1=\' \\\' OR id IN (SELECT id FROM _content_docs) OR 1!=\'\') ORDER BY id ASC': false,
'SELECT "id", "id" FROM _content_docs WHERE (1=\' \\\') UNION SELECT tbl_name,tbl_name FROM sqlite_master-- \') ORDER BY id ASC': false,
'SELECT "id" FROM _content_test WHERE (x=$\'$ OR x IN (SELECT BLAH) OR x=$\'$) ORDER BY id ASC': false,
'SELECT COUNT(*) as c,(SELECT group_concat(name,\'|\') FROM sqlite_master WHERE type=\'table\') AS leak FROM _content_content ORDER BY stem ASC': false
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Line 47 test does not isolate the COUNT-alias guard (and currently fails lint).

This case can throw for unrelated reasons (FROM _content_content mismatch and multi-column select), so it doesn’t prove the new COUNT(...) as count restriction. It also misses the required trailing comma, which is failing CI lint.

🔧 Suggested fix
-    'SELECT COUNT(*) as c,(SELECT group_concat(name,\'|\') FROM sqlite_master WHERE type=\'table\') AS leak FROM _content_content ORDER BY stem ASC': false
+    'SELECT COUNT(*) as c FROM _content_test ORDER BY stem ASC': false,
+    'SELECT COUNT(*) as count FROM _content_test ORDER BY stem ASC': true,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'SELECT COUNT(*) as c,(SELECT group_concat(name,\'|\') FROM sqlite_master WHERE type=\'table\') AS leak FROM _content_content ORDER BY stem ASC': false
'SELECT COUNT(*) as c FROM _content_test ORDER BY stem ASC': false,
'SELECT COUNT(*) as count FROM _content_test ORDER BY stem ASC': true,
🧰 Tools
🪛 GitHub Actions: ci

[error] 47-47: ESLint error from 'pnpm lint' (eslint .): 47:156 Missing trailing comma (@stylistic/comma-dangle)

🪛 GitHub Check: ubuntu

[failure] 47-47:
Missing trailing comma

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/unit/assertSafeQuery.test.ts` at line 47, Replace the fragile test entry
in test/unit/assertSafeQuery.test.ts with a query that isolates the COUNT alias
check (e.g. "SELECT COUNT(*) as count FROM _content_content") so it only
exercises the COUNT(...) as count restriction and cannot fail for unrelated
multi-column/select-from issues, and ensure the test mapping line ends with the
required trailing comma to satisfy linting; target the test case string that
currently contains "COUNT(*) as c" and update it to use "COUNT(...) as count"
and include the trailing comma.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 9, 2026

npm i https://pkg.pr.new/@nuxt/content@3765

commit: 1e981b9

@farnabaz farnabaz merged commit 6d85aba into main Apr 13, 2026
7 checks passed
@farnabaz farnabaz deleted the security/sql-safe-check branch April 13, 2026 16:07
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.

1 participant