Bug "Strict: true" work perfectly in create mode but in edit mode it doesn't work ?
@bajtos @raymondfeng Bug "Strict: true" work perfectly in create mode but in edit mode it doesn't work ? Example in Book model with "strict" is set true, when you create new Book with defined properties: title, description. JSON when create new Book POST: /Books/
{
"title":"How to program",
"description":"Please tell me know how to program"
"otherfield":"this property is not expected to save to mongodb"
}
It's ok about "otherfield" is not save to mondodb as we expected. But when i updated the book which i just created with the same information in created JSON. PUT /Books/{id} I saw that in mongodb / Book collection, it appeared "otherfield" property in the updated record. I thinked that, maybe we don't prevent unexpected properties in the update process. Please check and fix this bug. thanks much.
I am having the same issue, strict:true does not work when you do updateAttributes. Good to know it is a bug i guess. I don't think it is a loopback core bug, it should be the loopback datasource juggler. not sure
@mashiya @bluestaralone could you please have a look at:
https://github.com/strongloop/loopback-datasource-juggler/pull/666 ?
Unfortunately, I was not able to reproduce the issue of the otherfield property to be persisted to the database.
Although it must have appeared like that, because it was returned from the in-memory representation that did include otherfield indeed.
Awesome, thanks Fabien
I just got bitten by this issue in a different form that was apparently not covered by the above fix. Not with a PUT on an instance (prototype.updateAttributes in node API terms) like reported in this issue, but rather with a POST to /update (updateAll in node API terms). The backend will happily persist (yes, actually persist, not just a wrong in-memory representation) random properties to MongoDB through an updateAll even though strict mode is enabled for the model.
Versions:
+-- [email protected]
| +-- [email protected]
+-- [email protected]
| +-- [email protected]
+-- [email protected]
Probably related: strongloop/loopback-datasource-juggler#771
@tvdstaaij this is indeed the case for updateAll, as none of the instance-level logic is applied (including calling isValid as you point out in the related issue). Knowing this, I always disable the /update endpoint by default, and either implement a before filter or create an endpoint myself that will incorporate the desired logic.
Perhaps the documentation should be more clear about this, and warn for the potential security issues related to it.
@bajtos @crandmck thoughts?
Hello, I think there are two parts to this issue: 1) enforce strict mode 2) validate property values. I opened https://github.com/strongloop/loopback/issues/3183 to fix the first part, let's move the discussion there.
Perhaps the documentation should be more clear about this, and warn for the potential security issues related to it.
+1
@fabien could you contribute this doc improvement yourself please? See http://loopback.io/doc/en/contrib/doc-contrib.html to get started.
@bajtos I would prefer someone else to handle the documentation. Is that OK with you? I don't know exactly where to add this information, or how to word it correctly.
I would prefer someone else to handle the documentation. Is that OK with you?
Sure, no worries.
Added issue to track doc work #3187 .
Similar issue with PUT for updateAttributes https://github.com/strongloop/loopback/issues/3425