ProgramingTip

DeprecationWarning : 펼쳐보기를 다른 서버로 실행할 때 보안 및 사용성 문제로 인해 Buffer ()가 더 이상 사용되지 않습니다.

bestdevel 2020. 11. 26. 19:41
반응형

DeprecationWarning : 펼쳐보기를 다른 서버로 실행할 때 보안 및 사용성 문제로 인해 Buffer ()가 더 이상 사용되지 않습니다.


펼쳐지는 서버로 최고의 때 오류가 발생합니다.

(node ​​: 15707) [DEP0005] DeprecationWarning : Buffer ()는 보안 및 사용성 문제로 인해 더 이상 사용되지 않습니다. 대신 Buffer.alloc (), Buffer.allocUnsafe () 또는 Buffer.from () 메소드를 사용하십시오.

현재 버전 :

Ubuntu 16.04.4 LTS  
Node - v10.9.0  
NPM - 6.2.0  

이전 버전 :

Ubuntu 14.04.3 LTS
NPM - 3.10.10
Node - v6.10.3


exports.basicAuthentication = function (req, res, next) {
    console.log("basicAuthentication");
    if (!req.headers.authorization) {
        return res.status(401).send({
            message: "Unauthorised access"
        });
    }
    var auth = req.headers.authorization;
    var baseAuth = auth.replace("Basic", "");
    baseAuth = baseAuth.trim();
    var userPasswordString = new Buffer(baseAuth, 'base64').toString('ascii');
    var credentials = userPasswordString.split(':');

    var username = credentials[0] !== undefined ? credentials[0] : '';
    var password = credentials[1] !== undefined ? credentials[1] : '';
    var userQuery = {mobilenumber: username, otp: password};
    console.log(userQuery);
    User.findOne(userQuery).exec(function (err, userinfo) {
        if (err || !userinfo) {
             return res.status(401).send({
                message: "Unauthorised access"
             });
        } else {
            req.user = userinfo;
            next();
        }
    });

 }

new Buffer(number)            // Old
Buffer.alloc(number)          // New

new Buffer(string)            // Old
Buffer.from(string)           // New

new Buffer(string, encoding)  // Old
Buffer.from(string, encoding) // New

new Buffer(...arguments)      // Old
Buffer.from(...arguments)     // New

참고 Buffer.alloc ()가 빠른 달리 제로 충전을 보장 할 필요가 무엇 .fill 새로운 버퍼 (크기) (0)보다 현재 Node.js를 버전에 대한도이다.


지원 중단 된 생성자 new Buffer()(Yarn에서 사용하는 iE)를 사용하면 지원 중단 경고가 보관 수 있습니다. Buffer 생성되지 않는 안전하지 않은 버퍼는 사용되지 않습니다.

사용 중단 경고 new Buffer()에 따라 다음 중 하나로 교체해야합니다.

  • Buffer.alloc()
  • Buffer.allocUnsafe() 또는
  • Buffer.from()

이 문제를 방지하기위한 또 다른 옵션은 대신 안전 버퍼 패키지를 사용하는 것입니다.

당신은 또한 시도 할 수 있습니다 (실을 사용할 때 ..) :

yarn global add yarn

여기에 언급 된대로 : 링크

참고 URL : https://stackoverflow.com/questions/52165333/deprecationwarning-buffer-is-deprecated-due-to-security-and-usability-issues

반응형