Handlebars: Access has been denied to resolve the property “from” because it is not an “own property” of its parent

后端 未结 11 1834
我在风中等你
我在风中等你 2020-12-05 13:27

I am using a Nodejs backend with server-side rendering using handlebars. After reading a doc array of objects from handlebars, which contains key \"content\" an

11条回答
  •  情深已故
    2020-12-05 13:36

    There was a breaking change in the recent release of Handlebars which has caused this error.

    You could simply add the configurations they suggest in their documentation, however be aware, depending on you implementation, this could lead the vulnerability to XXS and RCE attacks.

    https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access

    Confession.find()
      .sort({date: -1})
      .then(function(doc){
        for(var i=0; i < doc.length; i++){
          //Check whether sender is anonymous
          if (doc[i].from === "" || doc[i].from == null){
            doc[i].from = "Anonymous";
          }
    
          //Add an extra JSON Field for formatted date
          doc[i].formattedDate = formatTime(doc[i].date);
        }
        res.render('index', {title: 'Confession Box', success:req.session.success, errors: req.session.errors, confession: doc}, {
    
          // Options to allow access to the properties and methods which as causing the error.
    
          allowProtoMethodsByDefault: true,
          allowProtoPropertiesByDefault: true
    
        });
    
        req.session.errors = null;
        req.session.success = null;
      });
    

提交回复
热议问题