Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwarden parser: item containing custom field named "url" breaks parsing #213

Closed
Goorzhel opened this issue Feb 26, 2024 · 1 comment
Closed

Comments

@Goorzhel
Copy link

My Bitwarden export contained an identity that had a "URL" field (which probably carried over from a Dashlane import), causing the parser to raise

TypeError: string indices must be integers, not 'str'
❯ pass import -vvv ./bitwarden.json
  .  Trying to guess file format and manager name.
  .  Importer: bitwarden, Format: json, Version:
  .  Importing passwords from BitwardenJSON to PasswordStore
  .  Traceback (most recent call last):
  File "/nix/store/nchhvpp6fax1m9p2dlrn5l3v4kxycafs-pass-import-3.2/lib/python3.11/site-packages/pass_import/__main__.py", line 342, in pass_import
    importer.parse()
  File "/nix/store/nchhvpp6fax1m9p2dlrn5l3v4kxycafs-pass-import-3.2/lib/python3.11/site-packages/pass_import/managers/bitwarden.py", line 98, in parse
    entry['url'] = urls[0]['uri']
                   ~~~~~~~^^^^^^^
TypeError: string indices must be integers, not 'str'

  w  string indices must be integers, not 'str'
 [x] Error: ./bitwarden.json is not a valid exported bitwarden file.

The above is using pass-import 3.2 because that's the latest in NixOS, but you can reproduce it on 3.5 by git applying this diff (based on d12ad97) and running make tests:

diff --git a/tests/assets/db/bitwarden-other.json b/tests/assets/db/bitwarden-other.json
index f4105cf..65a3997 100644
--- a/tests/assets/db/bitwarden-other.json
+++ b/tests/assets/db/bitwarden-other.json
@@ -102,6 +102,14 @@
       "name": "John DOE",
       "notes": null,
       "favorite": false,
+      "fields": [
+        {
+          "name": "url",
+          "value": "https://www.example.com",
+          "type": 0,
+          "linkedId": null
+        }
+      ],
       "identity": {
         "title": "M.",
         "firstName": "John",
Here's how `entry['url']` looks in PDB, using that diff
❯ git clone -q https://github.com/roddhjav/pass-import
❯ cat repro.py
from pass_import.managers.bitwarden import BitwardenJSON

with BitwardenJSON("/tmp/pass-import/tests/assets/db/bitwarden-other.json") as importer:
    importer.parse()
❯ python -m pdb repro.py
> /tmp/repro.py(1)<module>()
-> from pass_import.managers.bitwarden import BitwardenJSON
(Pdb) c
Traceback (most recent call last):
  File "/nix/store/65cp4izx3bllnwqn7c7dhrq9h9gmjkal-python3-3.10.9/lib/python3.10/pdb.py", line 1732, in main
    pdb._runscript(mainpyfile)
  File "/nix/store/65cp4izx3bllnwqn7c7dhrq9h9gmjkal-python3-3.10.9/lib/python3.10/pdb.py", line 1592, in _runscript
    self.run(statement)
  File "/nix/store/65cp4izx3bllnwqn7c7dhrq9h9gmjkal-python3-3.10.9/lib/python3.10/bdb.py", line 597, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/tmp/repro.py", line 4, in <module>
    importer.parse()
  File "/nix/store/ykw1k6lkcss99w44b54qaqh9xvkn4f6a-pass-import-3.2/lib/python3.10/site-packages/pass_import/managers/bitwarden.py", line 98, in parse
    entry['url'] = urls[0]['uri']
TypeError: string indices must be integers
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /nix/store/ykw1k6lkcss99w44b54qaqh9xvkn4f6a-pass-import-3.2/lib/python3.10/site-packages/pass_import/managers/bitwarden.py(98)parse()
-> entry['url'] = urls[0]['uri']
(Pdb) entry
{'group': None, 'title': 'John DOE', 'url': 'https://www.example.com', 'title_': 'M.', 'firstName': 'John', 'middleName': 'Rober', 'lastName': 'DOE', 'address1': '6 Rose street', 'city': 'New York', 'email': 'john.doe@email.com'}
(Pdb) entry['url']
'https://www.example.com'
(Pdb) entry['url'][0]
'h'
@roddhjav
Copy link
Owner

Thanks for this catch. It should now be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants