pykeepass icon indicating copy to clipboard operation
pykeepass copied to clipboard

`entry._get_string_field` fails if `key` contains a double quote due to missing XPath escaping

Open shadow1runner opened this issue 3 years ago • 1 comments

This is closely related to the subject discussed in #123 and the corresponding PR #204 and appeared in downstream https://github.com/jampe/kp2bw/issues/10.

The issue in entry.py are threefold:

  • https://github.com/libkeepass/pykeepass/blob/9f517fefcbcdc43275d5af6324de433605f34ed5/pykeepass/entry.py#L80
  • https://github.com/libkeepass/pykeepass/blob/9f517fefcbcdc43275d5af6324de433605f34ed5/pykeepass/entry.py#L85
  • https://github.com/libkeepass/pykeepass/blob/9f517fefcbcdc43275d5af6324de433605f34ed5/pykeepass/entry.py#L248

which all boil down do the fact, that using the latter as an example, the given key is not properly escaped:

prop = self._xpath('String/Key[text()="{}"]/..'.format(key), first=True)

Now @Evidlo already mentioned the possibility of using a simple escape method for this purpose; however, I assume there will be more of these xpath related issues which makes me wondering whether you guys think that it's time that #204 gets merged? As far as I see it doesn't fix the issues outlined here, but it lays the required foundation to do so

Thanks

shadow1runner avatar Mar 23 '21 18:03 shadow1runner

Can Evidlo's referenced function be used for now while other fixes are worked on, since this is a crashing bug for consuming applications if the user tries to use quotation marks in various places, and the bug's been around for at least 2.5 years now per the git blame of the above.

smithfred avatar Jul 05 '21 14:07 smithfred