简体   繁体   中英

How to prevent insert of data that is passed using query string in sails.js for post request?

I have created new table in mysql also created model and controller in sails.js. Now I am trying to insert data using sails. As we know when we create new modal in sails it will create new post, get and other api for us by default.

Now I am trying to insert data using post api using query string and request.body and both are working But I need to insert data into db that is passed using request.body instead of request.querystring data in post request. How can I do it???

  1. Post data using query string in post request => working fine

使用查询字符串发布数据

  1. Post data using request.body in post request => working fine (I want to insert data using this way only)

    使用 request.body 发布数据

Same question I asked here https://gitter.im/balderdashy/sails and https://github.com/balderdashy/sails/issues/6918

sails uses Waterline, this performs sanitation by itself, you should be fine whenever you are using some of this built-in model methods :

.find()
.findOne()
.updateOne() 
.archiveOne()
.destroyOne()
.create()
.createEach()
.count()
.sum()
.avg()
.addToCollection()
.removeFromCollection()

As an extra layer of security you can check that the providing data types are correct and verify range, characters, etc. There are also policies which allow you to restrict certain actions to logged-in users only.

hope this was helpful :)

When you create an API by command line, you'll get an API that lets you search, paginate, sort, filter, create, destroy, update, and associate. Since these blueprint actions are built-in Sails. You can override these actions by yourself. Find more at in Sails.js Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM