fix(security): standard quotes and block IN operator validate - #3862
Conversation
`WHERE` keyword check
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Priority: ⬆️ High Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to No actionable blocker is established. The change intentionally rejects unsupported WHERE syntax; merge after normal checks pass. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change narrows accepted SQL and preserves validation before database execution. No introduced or worsened security issue was established. Deployment-specific authentication, collection access controls, and database privileges remain unconfirmed. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
src/runtime/internal/security.tsParsing error: Unexpected token : test/unit/assertSafeQuery.test.tsParsing error: Unexpected token as 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. Comment |
This PR tackles with two issue:
The WHERE validator only blocked function calls and some SQL keywords.
SQLite accepts other forms that the query builder never produces, and
they could be abused:
x IN table_nameis an implicit subquery. It also accepts eponymoustable-valued pragmas, so
'ok' IN pragma_integrity_checkran a fullintegrity check for every term. A balanced AND tree of these
blocked the Node worker for tens of seconds per request. The same
form could also check for values in other tables.
passed because they contain no
name(call.||,->>, arithmetic) passed too,because they contain no letters.
After quoted strings and identifiers are removed, the WHERE clause must
now meet three rules:
INmust be followed by a parenthesised listNOT, IN, LIKE, BETWEEN, IS, NULL)
(,),,,=,<and>may appear
Each rule is a single pass over the query. Unquoted column names in
WHERE are now rejected; the query builder always quotes them, so
queryCollection() output is unaffected.
Refs: VULN-14102
cleanupQuery() removed [...] and
...regions before checking WHEREfor SELECT and other banned words, because SQLite accepts them as
identifier quotes. PostgreSQL has neither: [...] is an array subscript
that runs whatever it contains. On the postgresql and pglite adapters,
a payload like
WHERE ("meta"[(SELECT CASE WHEN THEN 1 ELSE 2 END)] IS NULL)
therefore hid a sub-select from the check and gave an unauthenticated
blind boolean oracle over the whole database. This was a regression
from #3819 (3.15.2).
That check now removes only the quote styles the query builder emits
('value' and "field"). Any [ or backtick left outside them is rejected
on every adapter. Brackets and backticks inside value strings and
quoted field names are still allowed.
Refs: VULN-14510