Skip to content

Raise legible error when issuer or accountname contains colon or URI-encoded colon #174

@TriVoxel

Description

@TriVoxel

Issue copied from "Secrets", a KeepassXC-compatible GNOME app using this library for TOTP generation. See more about the original issue here.

Description

This library cannot generate an OTP from a URL containing %3A in the URL (the result of a user using a colon in the name field)

Example

pyauth fails to generate an OTP from the following string:

otpauth://totp/Text%3A%20More%20Text:Secret?secret=FFFFFFFAAAAAABBBBBBB&issuer=Text%3A%20More%20Text

This is due to the %3A in the URL.

Steps to repeat

  1. Create a new Entry
  2. Title it Text: More Text
  3. Enter OTP Secret, eg. FFFFFFFAAAAAABBBBBBB
  4. Save
    (you get otpauth://totp/Text%3A%20More%20Text:Secret?secret=FFFFFFFAAAAAABBBBBBB&issuer=Text%3A%20More%20Text as the URL generated by "Secrets")
  5. Close
  6. Open and find Entry (no OTP gen)

Debug info

OS: Fedora Atomic 40 x86_64 (GNOME 46)

Secrets version: 9.6 (Flathub)

Logs

04-09-24 21:19:37 | ERROR | Could not parse OTP
Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/gsecrets/safe_element.py", line 606, in __init__
    self._otp = parse_uri(otp_uri)  # type: ignore
                ^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/pyotp/__init__.py", line 68, in parse_uri
    raise ValueError('If issuer is specified in both label and parameters, it should be equal.')
ValueError: If issuer is specified in both label and parameters, it should be equal.
04-09-24 21:19:37 | ERROR | Could not parse OTP
Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/gsecrets/safe_element.py", line 606, in __init__
    self._otp = parse_uri(otp_uri)  # type: ignore
                ^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/pyotp/__init__.py", line 68, in parse_uri
    raise ValueError('If issuer is specified in both label and parameters, it should be equal.')
ValueError: If issuer is specified in both label and parameters, it should be equal.
04-09-24 21:19:37 | ERROR | Could not parse OTP
Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/gsecrets/safe_element.py", line 606, in __init__
    self._otp = parse_uri(otp_uri)  # type: ignore
                ^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/pyotp/__init__.py", line 68, in parse_uri
    raise ValueError('If issuer is specified in both label and parameters, it should be equal.')
ValueError: If issuer is specified in both label and parameters, it should be equal.
04-09-24 21:19:37 | ERROR | Could not parse OTP
Traceback (most recent call last):
  File "/app/lib/python3.11/site-packages/gsecrets/safe_element.py", line 606, in __init__
    self._otp = parse_uri(otp_uri)  # type: ignore
                ^^^^^^^^^^^^^^^^^^
  File "/app/lib/python3.11/site-packages/pyotp/__init__.py", line 68, in parse_uri
    raise ValueError('If issuer is specified in both label and parameters, it should be equal.')
ValueError: If issuer is specified in both label and parameters, it should be equal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions