atom / node-keytar

Native Password Node Module

Home Page:https://atom.github.io/node-keytar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

windows 10 password Nul value \x00 added to string characters

saostad opened this issue · comments

Description

in windows 10 build 19042.804 passwords created by Windows credential manager, comes back with NUL Characters.

Steps to Reproduce

// t.js
const keytar = require("./lib/keytar");

keytar.findCredentials("test_cred").then((result) => {
  console.log(`File: t.js,`, `Line: 4 => `, result);
});

Expected behavior:

$ node ./t.js 
File: t.js, Line: 4 =>  [ { account: 'test_user', password: 'test_pass' } ]

Actual behavior:

$ node ./t.js 
File: t.js, Line: 4 =>  [
  {
    account: 'test_user',
    password: 't\x00e\x00s\x00t\x00_\x00p\x00a\x00s\x00s\x00'
  }
]

Reproduces how often:
every time.

Versions

Node v14.16.0
Screenshot 2021-03-01 143111

Additional Information

This is how I fixed it:
in source code lib\keytar.js
changed:

findCredentials: function (service) {
    checkRequired(service, 'Service')

    return keytar.findCredentials(service)
  }

TO:

findCredentials: function (service) {
    checkRequired(service, "Service");

    return keytar.findCredentials(service).then((data) =>
      data.map((el) => ({
        ...el,
        password: el.password.replace(/[\x00-\x08\x0E-\x1F\x7F-\uFFFF]/g, ""),
      }))
    );
  },

I know this is not the best way to fix the problem but I am not good at C++ so this is the fastest and best way I could do it, so if that's acceptable I can create a pull request.