diff --git a/services/real-time/app/coffee/DocumentUpdaterManager.coffee b/services/real-time/app/coffee/DocumentUpdaterManager.coffee index e183d11cec..9f516c2f2d 100644 --- a/services/real-time/app/coffee/DocumentUpdaterManager.coffee +++ b/services/real-time/app/coffee/DocumentUpdaterManager.coffee @@ -1,4 +1,5 @@ request = require "request" +_ = require "underscore" logger = require "logger-sharelatex" settings = require "settings-sharelatex" metrics = require("metrics-sharelatex") @@ -53,6 +54,8 @@ module.exports = DocumentUpdaterManager = return callback(err) queueChange: (project_id, doc_id, change, callback = ()->)-> + allowedKeys = [ 'doc', 'op', 'v', 'dupIfSource', 'meta', 'lastV', 'hash'] + change = _.pick change, allowedKeys jsonChange = JSON.stringify change if jsonChange.indexOf("\u0000") != -1 error = new Error("null bytes found in op") diff --git a/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee b/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee index 2d3e0ad3af..4f2c5d9b51 100644 --- a/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee +++ b/services/real-time/test/unit/coffee/DocumentUpdaterManagerTests.coffee @@ -122,9 +122,9 @@ describe 'DocumentUpdaterManager', -> describe 'queueChange', -> beforeEach -> @change = { - "action":"removeText", - "range":{"start":{"row":2,"column":2},"end":{"row":2,"column":3}}, - "text":"e" + "doc":"1234567890", + "op":["d":"test", "p":345] + "v": 789 } @rclient.rpush = sinon.stub().yields() @callback = sinon.stub() @@ -161,3 +161,16 @@ describe 'DocumentUpdaterManager', -> it "should not push the change onto the pending-updates-list queue", -> @rclient.rpush.called.should.equal false + + describe "with invalid keys", -> + beforeEach -> + @change = { + "op":["d":"test", "p":345] + "version": 789 # not a valid key + } + @DocumentUpdaterManager.queueChange(@project_id, @doc_id, @change, @callback) + + it "should remove the invalid keys from the change", -> + @rclient.rpush + .calledWith("PendingUpdates:#{@doc_id}", JSON.stringify({op:@change.op})) + .should.equal true