Improving the Node.js Driver’s SCRAM-SHA-256 Support

原文英文,约1400词,阅读约需5分钟。发表于:

MongoDB always strives to offer best-in-class features, functionality, and security. A number of authentication mechanisms currently exist to verify the identity of a connecting client to your cluster, and when using the Salted Challenge Response Authentication Mechanism (SCRAM) there are two possible hashing functions: SCRAM-SHA-1 and SCRAM-SHA-256. The MongoDB Driver Authentication Specification outlines that when attempting to authenticate using SCRAM: “If SCRAM-SHA-256 is present in the list of mechanism, then it MUST be used as the default; otherwise, SCRAM-SHA-1 MUST be used as the default [...]”. A MongoDB Server (mongos or mongod) can be configured with a list of possible authenticationMechanisms. As a result, MongoDB can be configured to return new authentication mechanisms which can upgrade already running applications to more secure authentication. This is the case when SCRAM-SHA-256 is added to a cluster that previously only supported SCRAM-SHA-1. Prior to hashing passwords with SHA-256, they will first be prepared using SASLprep. The MongoDB Node.js driver leverages an external library (saslprep) for this functionality, which was an optional dependency and only used if available. Though a number of checks were in place to ensure the library was available (and loaded), an edge case was found where these checks could fail and report availability incorrectly. Potential use Most applications won’t experience this issue, however if your Node.js project is being bundled using an alternate bundler (such as webpack) it’s possible a variation of this issue may surface. If your application was affected, it would be unable to connect to your MongoDB cluster. The stack trace from the error that would be thrown should include a call to continueScramConversation similar to the following examples: {&NewLine "errorType": "TypeError",&NewLine "errorMessage": "saslprep is not a function",&NewLine "stack": [&NewLine "TypeError: saslprep is not a function",&NewLine " at continueScramConversation ([...]/index.js:xxx:yyy)",&NewLine [...]&NewLine ] &NewLine}&NewLine TypeError: l is not a function&NewLine at continueScramConversation (/app/webpack:[...]/mongodb/lib/core/auth/scram.js:xxx:yy)&NewLine Note that Mongoose applications can also be affected, as Mongoose wraps the Node.js driver: TypeError: (0 , o.saslprep) is not a function&NewLine at continueScramConversation (/app/webpack:[...]/mongoose/node_modules/mongodb/lib/cmap/auth/scram.js:xxx:yy)&NewLine Next steps The underlying issue was addressed in versions 5.7.0, 4.17.0 and 3.7.4 of the MongoDB Node.js driver, so depending on the version of the driver being used by your application a minor version update will address this. Upgrading your application’s libraries and deploying to production may not always be possible in a timely fashion. If this is the case and you happen to hit the issue described above a workaround would be to append the authMechanism option to your connection string with a value of SCRAM-SHA-1 as follows: mongodb+srv://xyz.mongodb.net/test?authMechanism=SCRAM-SHA-1&NewLine This will force the driver to attempt authorization using the SCRAM-SHA-1 hashing algorithm. Note that connection string changes would still require the application to be restarted for those changes to take effect.

在竞争激烈的零售行业中,实时数据策略对于提升库存管理至关重要。通过建立单一的库存视图,零售商可以加速开发卓越的顾客体验,提高库存管理效率,并通过实时分析和人工智能来优化库存分配。使用MongoDB的文档数据模型可以实现实时库存跟踪和分析,提高库存可见性和一致性。采用事件驱动架构可以提高工作效率,自动化库存管理流程。

Improving the Node.js Driver’s SCRAM-SHA-256 Support
相关推荐 去reddit讨论