Skip to content

fix(decode_qr): validate scanned QR payload structure before field access (fixes #1029) - #1067

Open
muskan-creates352 wants to merge 1 commit into
SeedSigner:devfrom
muskan-creates352:validate-qr-payload-structures
Open

muskan-creates352 wants to merge 1 commit into
SeedSigner:devfrom
muskan-creates352:validate-qr-payload-structures

Conversation

@muskan-creates352

Copy link
Copy Markdown

Fixes #1029

Description

As highlighted in #1029, scanned QR payloads previously lacked defensive structural validation before individual attributes and positional fields were accessed. Scanning malformed or incomplete QR payloads could trigger unhandled exceptions (such as TypeError, IndexError, or bare Exception) rather than gracefully returning DecodeQRStatus.INVALID.

Changes Made

  1. SettingsQrDecoder:

    • Replaced unhandled raise Exception("Invalid SettingsQR data") with defensive validation and safe return of DecodeQRStatus.INVALID.
    • Verified that prefix is settings:: and includes a valid version token before accepting.
  2. SpecterWalletQrDecoder:

    • Fixed bug where is_complete() invoked self.is_valid() with parentheses despite is_valid being a @property, which raised TypeError: 'bool' object is not callable.
    • Hardened validate_json and is_valid to ensure parsed JSON is a dictionary containing a string descriptor.
    • Replaced bare except: blocks in segment parsing with safe regex match validation.
  3. MultiSigConfigFileQRDecoder / multisig_setup_file_to_descriptor:

    • Defensively handled missing format (avoiding UnboundLocalError on script_type).
    • Removed fixed xpubs = [None] * n pre-allocation to prevent IndexError when Policy: line is missing or comes after xpubs.
    • Handled empty or missing derivation paths safely.
    • Wrapped DecodeQR.multisig_setup_file_to_descriptor() in MultiSigConfigFileQRDecoder.add() so invalid config files return DecodeQRStatus.INVALID gracefully.
  4. GenericWalletQrDecoder:

    • Added validation check to reject empty or non-string inputs before invoking embit descriptor parser.

Testing

  • Created tests/test_qr_decoder_validation.py containing 10 dedicated test cases covering valid and malformed payloads across all updated decoders (10/10 passed in 0.29s).
  • Ran full test suite across the project; all 332 tests pass cleanly.

@muskan-creates352

Copy link
Copy Markdown
Author

hii , @wolgwang1729 plz ptal...

@kdmukai

kdmukai commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@muskan-creates352:

  1. Please make sure your PRs adhere to our PR template: https://github.com/SeedSigner/seedsigner/blob/dev/.github/pull_request_template.md

  2. A key note in that PR template is: "Please only "@" mention a contributor if their input is truly needed to enable further progress."

SeedSigner contributors are all volunteers. You have just created a large amount of notification spam asking for a volunteer's time across a number of PRs. It is up to each volunteer how and where they spend their time; a PR author does not have the right to dictate what someone gives their attention to.

We always appreciate people's interest and contributions. But understand that this notification spamming behavior is considered extremely rude.

@muskan-creates352

Copy link
Copy Markdown
Author

Hi @kdmukai,

I sincerely apologize for the notification spam and for not strictly adhering to the PR template guidelines regarding mentions. I completely understand and respect that all maintainers and contributors are volunteers dedicating their valuable time. It was never my intention to be rude, impatient, or disruptive.

I have taken this feedback to heart, thoroughly reviewed the PR template, and will strictly follow it across all my PRs. I will also make sure not to tag or mention maintainers going forward.

Thank you for your patience and for pointing this out to help me learn proper repository etiquette.

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

Successfully merging this pull request may close these issues.

Feature request: structural validation of scanned QR payloads before field access

2 participants