Skip to content

Bitcoin-uri fuzzing crash #10

Closed
Closed

Description

@benalleng

I encountered a bitcoin-uri fuzzing crash that could just be expected behavior within the spec that just is a little weird.

Parsing this uri Bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX6=q3Ҁf&pj=\u{3}\0\0\0\0\0\0http\r\r\r\r\r\r\r\r\r:\r\r\\.onion\\\\\\\\\\q3 and then re-serializing it in a roundtrip results in a loss of data. Resulting uri bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTP://.ONION/////q3 my question is whether it is expected that uris may not always be able to be de-serialized in a roundtrip and end up the same, especially when considering unknown or unsupported data.

It is my intuition that a uri should retain the unknown data so that it is not lost just because payjoin does not understand how to parse it but maybe it is just expected that an external uri should be cloned or passed as a ref into parsing programs.

Here is a basic unittest to show how this happens.

#[test]
    fn test_fuzz_crash() {
        use Uri;
        let valid_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pjos=0&pj=HTTPS://EXAMPLE.COM/%23OH1QYPM5JXYNS754Y4R45QWE336QFX6ZR8DQGVQCULVZTV20TFVEYDMFQC";

        let round_trip = valid_uri.parse::<Uri<_>>().unwrap().assume_checked().to_string();
        println!("{}\n", valid_uri.parse::<Uri<_>>().unwrap().assume_checked().to_string());
        assert_eq!(valid_uri, round_trip);

        let uri = "Bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?6=q3Ҁf&pj=\u{3}\0\0\0\0\0\0http\r\r\r\r\r\r\r\r\r:\r\r\\.onion\\\\\\\\\\q3";

        let round_trip = uri.parse::<Uri<_>>().unwrap().assume_checked().to_string();
        println!("{}", uri.parse::<Uri<_>>().unwrap().assume_checked().to_string());
        assert_eq!(uri, round_trip);
    }

Activity

  1. benalleng commented on Jan 15, 2026

    @benalleng
    CollaboratorAuthor

    @spacebear21 prompted an llm which had this response which says that perhaps there is an even more minimal example which could demonstrate this.

    Summary: Minimal Viable Inputs
    The original fuzz crash combines multiple issues. Here are the minimal inputs that cause the same round-trip assertion failure:
    BUG 1: Unknown query params silently dropped (PRIMARY BUG)
    Minimal input:
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?a=1&pj=HTTPS://X.COM/
    Output: bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTPS://X.COM/
    The a=1 param is silently lost. This is the core data loss bug.
    BUG 2: pjos=1 dropped (default value not serialized)
    Minimal input:
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pjos=1&pj=HTTPS://X.COM/
    Output: bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTPS://X.COM/
    BUG 3: Backslash → forward slash in URL
    Minimal input:
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTP://A.ONION/\
    Output: ...?pj=HTTP://A.ONION//
    BUG 4: Control chars stripped from URL
    Minimal input:
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=HTTP://A.ONION/\r
    Output: ...?pj=HTTP://A.ONION/
    The absolute minimal input that causes the same crash is:
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?a=1&pj=HTTPS://X.COM/
    The original fuzz input's complexity (control chars, null bytes, backslashes, unicode) is mostly unnecessary - a single unknown query param a=1 triggers the same round-trip failure.

    upon further testing it does seem that this also fails. so minimally the test can just use
    bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?a=1&pj=HTTPS://X.COM/

  2. benalleng commented on Jan 15, 2026

    @benalleng
    CollaboratorAuthor

    I guess the question is whether this falls within spec or is otherwise acceptable as an implementation detail as it does not seem to be explicitly described in the spec regarding unknown Params.

    i.e. should we maybe store "unknown_data" as a Param to be added back at the time of serialization?

    https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki#forward-compatibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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