Uh oh!
There was an error while loading. Please reload this page.
Inject remote context createChangeStream method - #3064
Conversation
slnode
commented
Jan 3, 2017
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
slnode
commented
Jan 3, 2017
Can one of the admins verify this patch? |
3 similar comments
slnode
commented
Jan 3, 2017
Can one of the admins verify this patch? |
slnode
commented
Jan 3, 2017
Can one of the admins verify this patch? |
slnode
commented
Jan 3, 2017
Can one of the admins verify this patch? |
davidcheung
commented
Jan 3, 2017
@BramKleinhout thanks for the contribution! |
BramKleinhout
commented
Jan 3, 2017
@davidcheung That is no problem, I have added the test for the injection. |
| type: 'ReadableStream', | ||
| json: true, | ||
| }, | ||
| accepts: {arg: 'options', type: 'object', http: 'optionsFromRequest'}, |
There was a problem hiding this comment.
I did not realise that createChangeStream was already exposing the options argument. The change proposed in this pull request can break existing applications, because right now it's possible to specify options via query string:
GET /api/mymodels/change-stream?options[flag]=value
-> options = {flag: 'value'}
We need to preserve backwards compatibility. The solution is to add a feature flag (a model-level setting) that will control whether the options argument should be provided by the user (current state) or constructed via optionsFromRequest (the new version).
Here is a quick mock-up:
varstreamOptionsArg={arg: 'options',type: 'object'};// TODO: remove this flag in 4.0if(PersistedModel.settings.injectChangeStreamOptions){streamOptionsArg.http='optionsFromRequest';}setRemoting(PersistedModel,'createChangeStream',{// ...,accepts: streamOptionsArg,returns: // ...});There was a problem hiding this comment.
Actually, on the second thought, considering that Operation hooks observers now expect that ctx.options is always constructed by the server and cannot be injected by the client, I think the original options configuration would create a serious security vulnerability and therefore we should change it even though it may break existing apps.
Modify the remoting metadata for the "options" argument to use the new `http: 'optionsFromRequest'` mapping. The old configuration, where the clients could set arbitrary "options", opened a security vulnerability because with "optionsFromReqest" in place in other PersistedModel methods, users are expecting that "ctx.options" provided by Operation hooks is always created server-side and cannot be tampered by clients.
8c8fa75 to
5b6ceffComparebajtos
commented
Jan 13, 2017
Hmm, it turns out the built-in In that light, it does not make sense to me to modify the way how the If you are overriding MyModel.disableRemoteMethodByName('createChangeStream');MyModel.myCreateChangeStream=function(options,cb){// your custom implementation, possibly calling out to MyModelcreateChangeStream}MyModel.remoteMethod('myCreateChangeStream',{description: 'Create a change stream.',accessType: 'READ',http: [{verb: 'post',path: '/change-stream'},{verb: 'get',path: '/change-stream'},],accepts: {arg: 'options',type: 'object',http: 'optionsFromRequest'},returns: {arg: 'changes',type: 'ReadableStream',json: true},}); |
Description
Implement, in addition to #3023, the injection of remote context to the options argument of the createChangeStream method.
Related issues
Checklist