Giter Site home page Giter Site logo

think-qs's Introduction

think-qs

Build Status Coverage Status npm

Use qs module to parse query & post data, support array & object value.For example, the string 'foo[bar]=baz' converts to:

foo: {
  bar: 'baz'
}

Installation

npm install think-qs

think-qs need thinkjs version >=3.2.2.

How to use

Config file src/config/middleware.js (in multi mode, file is src/common/config/middleware.js), add middleware after payload:

const qs = require('think-qs');
module.exports = [
  ...
  {
    handle: 'payload'
  },
  {
    handle: qs,
    options: {

    }
  }
]

After config, you can get array & object value by this.get or this.post in controller.

options

This middleware support follow options:

  • query: true, enable use qs to parse querystring
  • post: true, enable use qs to parse post data

You can find more options from https://github.com/ljharb/qs.

Security

If you use this middleware, you must be careful about security. some ORM support array/object in where conditions, it may be cause SQL injections.

// http://docs.sequelizejs.com/manual/tutorial/querying.html
Post.findAll({
  where: {
    id: this.get('id')
  }
});

In here, we want id is an integer, but when url is /pathname?id[$gt]=6, id value is an object:

{
  $gt: 6
}

then where conditions is not we wanted, it caused SQL injection. you can config logic to resolve this security problems.

module.exports = class extends think.Logic {
  indexAction() {
    this.rules = {
      id: {
        int: true
      }
    }
  }
}

you can get more information about logic from https://thinkjs.org/zh-cn/doc/3.0/logic.html.

think-qs's People

Contributors

welefen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.