twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.4k stars 493 forks source link

Chezmoi gives parse error if notes field in KeepassXC password contain a certain combination #1969

Closed sm1999 closed 2 years ago

sm1999 commented 2 years ago

Describe the bug

If notes field in keepassxc password contains :=:. chezmoi throws parse error and show all the output of keepassxc show command. It's a bit flaky, sometimes it doesn't throw error.

To reproduce

Steps to reproduce the behavior.

  1. Have an entry containing :=: in notes field of keepassxc entry.
  2. execute chezmoi execute-template '{{ (keepassxc "test").Password }}'
  3. chezmoi throws parse error with all the output of keepassxc show command

    Expected behavior

A clear and concise description of what you expected to happen.

chezmoi should not throw the parse error

Output of command with the --verbose flag

$ chezmoi --verbose execute-template '{{ (keepassxc "test").Password }}'
Insert password to unlock C:/Users/Saura/test.kdbx:
Enter password to unlock C:/Users/Saura/test.kdbx:
chezmoi: template: arg1:1:4: executing "arg1" at <keepassxc "test">: error calling keepassxc: keepassxc-cli show --show-protected 'C:/Users/Saura/test.kdbx' test: : parse error
Title: test
UserName: test
Password: test
URL:
Notes: :=:

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.14.0, commit 7a2edbef28cc946972799ec287f78cb3b867ead4, built at 2022-03-09T21:44:20Z, built by goreleaser ok latest-version v2.14.0 ok os-arch windows/amd64 ok systeminfo Microsoft Windows 10 Pro (10.0.19044 N/A Build 19044) ok go-version go1.17.8 (gc) ok executable ~/scoop/apps/chezmoi/current/chezmoi.exe ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml ok source-dir ~/.local/share/chezmoi is a directory ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a directory ok dest-dir ~ is a directory ok shell-command found C:/Windows/system32/cmd.exe ok shell-args 'C:\\Windows\\system32\\cmd.exe' ok cd-command found C:/Windows/system32/cmd.exe ok cd-args 'C:\\Windows\\system32\\cmd.exe' ok edit-command found C:/Windows/system32/notepad.exe ok edit-args 'C:\\Windows\\system32\\notepad.exe' info diff-command not set ok git-command found ~/scoop/shims/git.exe, version 2.35.1 ok merge-command found ~/scoop/shims/nvim.exe info age-command age not found in $PATH info gpg-command gpg not found in $PATH info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info gopass-command gopass not found in $PATH ok keepassxc-command found C:/Program Files/KeePassXC/keepassxc-cli.exe, version 2.7.0 ok keepassxc-db ~/test.kdbx is a file info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

I tried to minimize my note to find the pattern and settled on :=:. Also happens on Linux.

twpayne commented 2 years ago

I tried to reproduce this in #1970 which includes :=: in the Notes: field. This test passes on all platforms. What is the full contents of the Notes: field? Could it be something else?

sm1999 commented 2 years ago

Thank you for your prompt reply!

Contain of the Notes field

account: 123456789
2021-11-27 [expires: 2023-02-25]
main = false

Output of command

❯ chezmoi --verbose execute-template '{{ (keepassxc "test").Password }}'
Insert password to unlock /home/sm1999/test.kdbx:
Enter password to unlock /home/sm1999/test.kdbx:
chezmoi: template: arg1:1:4: executing "arg1" at <keepassxc "test">: error calling keepassxc: keepassxc-cli show --show-protected /home/sm1999/test.kdbx test: main = false: parse error
Title: test
UserName: test
Password: test
URL:
Notes: account: 123456789
2021-11-27 [expires: 2023-02-25]
main = false

I tried to reproduce it in the dev environment locally referencing #1970 but was not successful to reproduce the error.

twpayne commented 2 years ago

Thanks for the extra details. I see where the problem is: the characters before expires: are confusing chezmoi. This is definitely a bug. Fix coming later today.

sm1999 commented 2 years ago

Thank you for this amazing program! Really made dotfiles managing a lot easier.

One more thing, can you pass --quiet flag to keepassxc-cli. so that these duplicate lines do not occur

❯ chezmoi --verbose execute-template '{{ (keepassxc "test").Password }}'
Insert password to unlock /home/sm1999/test.kdbx:
Enter password to unlock /home/sm1999/test.kdbx:
twpayne commented 2 years ago

One more thing, can you pass --quiet flag to keepassxc-cli. so that these duplicate lines do not occur

Please open a new issue for this. Adding new issues to existing issues makes it hard to track and untangle them.

twpayne commented 2 years ago

Fixed with #1970.