CulturalMe / meteor-slingshot

Upload files directly to AWS S3, Google Cloud Storage and others in meteor
MIT License
595 stars 104 forks source link

Remaining Buffer() DeprecationWarning #245

Open igal1c0de4n opened 2 years ago

igal1c0de4n commented 2 years ago

Similar to: https://github.com/CulturalMe/meteor-slingshot/pull/242

On METEOR@2.7.1 : When I upload a file, I see this server-side console warning:

(node:41836) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    at showFlaggedDeprecation (buffer.js:198:11)
    at Buffer (buffer.js:282:3)
    at Slingshot.StoragePolicy.stringify (packages/edgee_slingshot.js:574:14)
    at Object.applySignature (packages/edgee_slingshot.js:759:44)
    at Object.upload (packages/edgee_slingshot.js:717:10)
    at Slingshot.Directive.getInstructions (packages/edgee_slingshot.js:364:46)
    at MethodInvocation.slingshot/uploadRequest (packages/edgee_slingshot.js:446:22)
    at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1885:12)
    at packages/ddp-server/livedata_server.js:769:19
    at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1257:12)
    at packages/ddp-server/livedata_server.js:767:46
    at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1257:12)
    at packages/ddp-server/livedata_server.js:765:46
    at new Promise (<anonymous>)
    at Session.method (packages/ddp-server/livedata_server.js:739:23)
    at packages/ddp-server/livedata_server.js:603:43

The error originates at the server side stringify:

    stringify: function (encoding) {                                             // 102
      /* global Buffer: false */                                                 // 103
      return Buffer(JSON.stringify(policy), "utf-8")                             // 104
        .toString(encoding || "base64");                                         // 105
    }                                                                            // 106
  1. As suggested, replacing Buffer(...) with Buffer.from(...) should take care of it
  2. It makes sense to also replace the other two Buffer(...) calls