Skip to content

Hash injection (security) #7310

@homakov

Description

@homakov

Using specially crafted requests we can trivially bypass secret_token protections on websites using sequalize.

Many people have code like this

db.Token.findOne({
      where: {
        token: req.query.token
      }
);

But Node.js and other platforms allow nested parameters, ie token[$gt]=1 will turn into token = {"$gt":1}. When we pass such hash to sequalize it will consider it a query (greater than 1) and find the first token in DB, bypassing security of this endpoint. This behavior was copied from Mongo https://docs.mongodb.com/manual/reference/operator/query/

Using finely tuned $gt we can iterate all tokens in db and impersonate every single user.

There are vulnerable sites in the wild.

That's how it can be exploited in Mongo http://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html and https://cirw.in/blog/hash-injection

My advice would be to either disable this functionality entirely (i.e. require passing token {"$eq":token} every time) or make sure the parameter isn't coming from req.query and is native hash object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsFor issues and PRs. Things related to documentation, such as changes in the manuals / API reference.status: in discussionFor issues and PRs. Community and maintainers are discussing the applicability of the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions