overleaf/services/real-time/app/coffee/SafeJsonParse.coffee
Jakob Ackermann cb675d38c2 [misc] SafeJsonParse: align the size limit with the frontend->rt limit
frontend -> real-time and doc-updater -> real-time should be in sync.
Otherwise we can send a payload to doc-updater, but can not receive the
 confirmation of it -- and the client will send it again in a loop.

Also log the size of the payload.
2020-03-24 09:14:15 +01:00

13 lines
No EOL
423 B
CoffeeScript

Settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
module.exports =
parse: (data, callback = (error, parsed) ->) ->
if data.length > Settings.maxUpdateSize
logger.error {head: data.slice(0,1024), length: data.length}, "data too large to parse"
return callback new Error("data too large to parse")
try
parsed = JSON.parse(data)
catch e
return callback e
callback null, parsed