Skip to main content
Menu
Advisories

Query operator allow-list bypass in @feathersjs/adapter-commons allows $where code execution on @feathersjs/memory

GHSA-6QM5-R3G8-QGQHPublished Updated GitHub

Description

Impact

validateQueryProperty() in @feathersjs/adapter-commons did not recurse into array values. _.isObject() in @feathersjs/commons excludes arrays, so isPlainObject() returned false and the value was returned unvalidated.

An extra array level around a sub-query bypassed the operator allow-list:

  • $or: [{ $where: '1==1' }] was correctly rejected
  • $or: [[{ $where: '1==1' }]] was accepted

The same allow-list also skipped filter values:

  • $or / $and as a non-array object ({ $or: { $where: '1==1' } })
  • Object $select ({ $select: { x: { $function: … } } }), which @feathersjs/mongodb spreads into find().project() / $project
  • Object $sort values containing $ operators

On an application using @feathersjs/memory, an unvalidated $where operator reaches sift, which compiles the supplied string with new Function(). That is remote code execution in the Node.js process from a single unauthenticated query. Express's default extended query parser is enough to produce the nested array; no custom endpoints, operators, or body parsers are required.

Separately, ObjectIdSchema() in @feathersjs/schema and @feathersjs/typebox accepted any object (additionalProperties: true) so that ObjectId instances would validate. Operator documents such as { $where } and { $regex } were therefore treated as valid ids. Generated MongoDB apps put ObjectIdSchema on _id / userId in querySyntax; default validateQuery then marks the query validated and skips the adapter allow-list.

This is a Feathers 5 regression for the array case. The v4 cleanQuery implementation mapped over arrays. All v5 releases through 5.0.48 are affected. v4 is not affected.

filterQuery() is called from AdapterBase.sanitizeQuery(), so unvalidated operators also reach every adapter built on that base class, including @feathersjs/mongodb and @feathersjs/knex. Remote code execution was only verified on @feathersjs/memory.

Patches

Fixed in 5.0.49 via github.com/feathersjs/feathers/pull/3700:

  • validateQueryProperty recurses into arrays
  • $select, $or, $and, and $sort filter values are validated
  • The objectid keyword accepts ObjectId instances and rejects other objects; ObjectIdSchema uses that for its object branch

Upgrade to 5.0.49 or later.

Workarounds

Until you can upgrade:

  • Use validateQuery with a closed query schema (additionalProperties: false), as generated apps already do. This blocks the extra-array wrap, but does not block operator objects assigned to ObjectIdSchema fields unless you also upgrade or tighten that schema.
  • Or set Express to the simple query parser (app.set('query parser', 'simple')) so nested array query keys are not produced.
  • Avoid exposing @feathersjs/memory find to untrusted clients.

Credit

Reported responsibly by Khiêm Trần (@komega2409) and Chien Huynh (@chienhm).

References

Affected versions

References

GitHub · feathersjs/feathers