Contents

bcup2kdbx: a security audit, a fix, and my vault converted

Yesterday I wrote about moving from Buttercup to KeePassXC, and ended with bcup2kdbx ★ star note, a community tool that converts a Buttercup vault into a KDBX database: “It’s third-party and new, so check it before you use it.” So before giving it my vault, I checked it, and fixed what I found along the way. Then I converted my vault.

What I wanted to know

Two things: that it doesn’t reach the Internet while it runs, and that it writes nothing anywhere except the output file I name.

Reading the code

The tool itself is small: convert.js, lib.js, a test file and two workflows. It reads the vault, writes the KDBX, and nothing else. Its lockfile lists 122 packages, none with an install script, all from the npm registry with integrity hashes.

I installed the locked tree in a scratch copy, without running any scripts, to read the dependencies too. Buttercup ships clients for Dropbox, WebDAV and Google Drive, but they are only built for vaults stored there; the tool always opens a local file, keeps its cache in memory and turns auto-update off. A search of every package for child processes, sockets, eval, environment reads and install hooks found only known boilerplate.

Watching it run

Then I built a test vault with an attachment and ran the real command under strace:

  • no network calls, and no other program started
  • one file written: the output .kdbx
  • one folder created: .buttercup/<vault id>, next to the input vault

That folder is the only surprise. When an entry has attachments, Buttercup’s file source creates it, and it stays behind, empty. The project’s SECURITY.md says “the only file written is the KDBX database you name”, which is not quite true. So: safe to use offline, and to leave nothing behind, convert from a copy of the vault, or delete the empty folder afterwards.

npm audit and the xmldom pin

On a fresh clone, npm install reports 8 vulnerabilities and suggests npm audit fix. Running it is a trap: it replaces the project’s deliberate pin of @xmldom/xmldom at 0.7.13 with 0.8.15, and the test suite fails, because a \r\n in a note comes back as \n. SECURITY.md explains why the pin is there, and covers 5 of the 16 advisories npm now reports.

Before reporting it, I looked at the two questions that matter for a password converter:

  • Are the new advisories reachable? Most are about building XML with names taken from user data. kdbxweb, the library that writes the KDBX, only creates elements and attributes with constant names, and puts user data in as text. The rest are about parsing, and the only XML this tool parses is the file it has just written, to verify it. I don’t think any of them are exploitable here.
  • Does 0.8.15 change what gets written? I saved the same note, with tabs, \r\n and a lone \r, under both versions and compared the decrypted XML inside the file. The bytes written are the same. The difference is only on reading it back, and the XML 1.0 standard (§2.11) requires every conforming parser to turn \r\n into \n anyway. So the pin protects a difference in the tool’s own verify step, not in the database it produces.

The issue and the pull request

I filed issue #5: the npm audit fix trap, the 11 advisories SECURITY.md doesn’t explain, and the case for 0.8.15. SECURITY.md asks for private reports, but every fact here was already public and nothing was exploitable, so I filed it in the open.

Then pull request #6, from a fork: the pin moved to 0.8.15, a test that checks the bytes written (the tab and \r\n must be in the file), SECURITY.md’s advisories section rewritten, with a warning against npm audit fix --force. With it, npm audit shows none of the 15 xmldom advisories; six others remain (three with open Dependabot pull requests, and one for minimatch that the tool can’t reach). As I write this, the pull request is waiting for a maintainer.

Converting my vault

With the fix in place, I converted my own Buttercup vault to a KDBX database and opened it in KeePassXC: my entries are there. That was the point of all this, and it worked.

I also checked whether the newest xmldom line, 0.9, could go further than 0.8.15. It can’t: with 0.9.0 and with 0.9.12, the converter fails as soon as it saves the database (“errorHandler object is no longer supported, switch to onError!”), because kdbxweb still sets up xmldom’s parser the old way. So 0.8.15 is as far as the pin can go until kdbxweb is updated.

Special thanks

To Anindya Chatterjee (anidotnet) and Dizitart, for writing and sharing bcup2kdbx.

References