Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove user input from URI error message #280

Merged
merged 1 commit into from May 10, 2021
Merged

Remove user input from URI error message #280

merged 1 commit into from May 10, 2021

Conversation

ghost
Copy link

@ghost ghost commented Apr 13, 2021

Removes the user input from error message to avoid it being used in attacks.

Its not really a vulnerability in Bitcoin Core because involves social engineering, dependency on user environment etc. But this PR improves security and by avoiding abuse of URI error in future.

Example of an attack:

  1. User opens a link in firefox:
bitcoin:tb1qag2e6yhl52hr53vdxzaxvnjtueupvuftan4yfu%0A%0AWARNING%3A%20DO%20NOT%20CLOSE%20THIS%20WINDOW%20OR%20TURN%20OFF%20YOUR%20PC!%20IF%20YOU%20ABORT%20THIS%20PROCESS%2C%20YOU%20COULD%20DESTROY%20ALL%20OF%20YOU%20DATA!%20PLEASE%20ENSURE%20THAT%20YOUR%20POWER%20CABLE%20IS%20PLUGGED%20IN!%0A%0AYou%20became%20victim%20of%20the%20XYZ%20RANSOMWARE!%0A%0AThe%20hard%20disks%20of%20your%20computer%20have%20been%20encrypted%20with%20a%20military%20grade%20encryption%20algorithm.%20There%20is%20no%20way%20to%20restore%20your%20data%20without%20a%20special%20key.%20You%20can%20purchase%20this%20key%20on%20the%20darknet%20page%20shown%20in%20step%202.%0ATo%20purchase%20your%20key%20and%20restore%20your%20data%2C%20please%20follow%20these%20three%20easy%20steps%3A%0A%0A1.%20Download%20the%20Tor%20browser%20at%20%E2%80%9Chttps%3A%2F%2Fwww.torproject.org%2F%E2%80%9C.%0A2.%20Visit%20one%20of%20the%20following%20pages%20with%20the%20Tor%20Browser%3A%0Ahttp%3A%2F%2Frandomchars.onion%2Fabc123%0A3.%20Send%20BTC%20by%20following%20the%20instructions%20on%20the%20page
  1. User selects Bitcoin Core to open the link:

image

  1. User is asked to send BTC with some message convincing enough which can be different depending on the victim:

image

After this PR (No user input mentioned in the error):

image

@sipa
Copy link
Contributor

sipa commented Apr 13, 2021

Nice find. Presumably we could also just sanitize the address before showing?

@ghost
Copy link
Author

ghost commented Apr 13, 2021

Presumably we could also just sanitize the address before showing?

Yes that's possible. I thought a generic error message is good enough in this case for user and there is no need to know the wrong address or anything else which was entered.

For sanitization I will have to do more research if it's already done for something else in GUI or find best way to do it in C++.

@jarolrod
Copy link
Member

I think it would be better to always sanitize the address before showing it. @Bosch-0 what do you think about this from a UX perspective. should the incorrect address be shown back to the user?

@Bosch-0
Copy link

Bosch-0 commented Apr 15, 2021

The blank error that prayank presented in the OP would be my suggestion. The only information I would include (if you can) alongside the incorrect address is why the address is invalid. Say for example is opening a testnet address when running mainnet it could notify the user of this. @GBKS thoughts?

@GBKS
Copy link

GBKS commented Apr 15, 2021

Agree with Bosch. Giving a reason why it's invalid would be helpful for the user to address the problem. Alternatively, if the input should stay visible, it could be clearly separated from the UI copy (see crappy mock-up below).

Frame 13

@hebasto
Copy link
Member

hebasto commented Apr 15, 2021

My vote is for @Bosch-0's and @GBKS's vision.

@ghost
Copy link
Author

ghost commented Apr 16, 2021

Thanks everyone for the review.

I think it would be better to always sanitize the address before showing it.

@jarolrod
IMO there is no need to show address in error message if the address fails validation.

The blank error that prayank presented in the OP would be my suggestion. The only information I would include (if you can) alongside the incorrect address is why the address is invalid.

@Bosch-0
Done. Made changes in 9885de1

Alternatively, if the input should stay visible, it could be clearly separated from the UI copy (see crappy mock-up below).

@GBKS Thanks for sharing the mockup. However, less is better in this case IMO.

My vote is for @Bosch-0's and @GBKS's vision.

@hebasto Few examples of different reasons mentioned in the error messages:

  1. User input mentioned in the description of this PR:
bitcoin:tb1qag2e6yhl52hr53vdxzaxvnjtueupvuftan4yfu%0A%0AWARNING%3A%20DO%20NOT%20CLOSE%20THIS%20WINDOW%20OR%20TURN%20OFF%20YOUR%20PC!%20IF%20YOU%20ABORT%20THIS%20PROCESS%2C%20YOU%20COULD%20DESTROY%20ALL%20OF%20YOU%20DATA!%20PLEASE%20ENSURE%20THAT%20YOUR%20POWER%20CABLE%20IS%20PLUGGED%20IN!%0A%0AYou%20became%20victim%20of%20the%20XYZ%20RANSOMWARE!%0A%0AThe%20hard%20disks%20of%20your%20computer%20have%20been%20encrypted%20with%20a%20military%20grade%20encryption%20algorithm.%20There%20is%20no%20way%20to%20restore%20your%20data%20without%20a%20special%20key.%20You%20can%20purchase%20this%20key%20on%20the%20darknet%20page%20shown%20in%20step%202.%0ATo%20purchase%20your%20key%20and%20restore%20your%20data%2C%20please%20follow%20these%20three%20easy%20steps%3A%0A%0A1.%20Download%20the%20Tor%20browser%20at%20%E2%80%9Chttps%3A%2F%2Fwww.torproject.org%2F%E2%80%9C.%0A2.%20Visit%20one%20of%20the%20following%20pages%20with%20the%20Tor%20Browser%3A%0Ahttp%3A%2F%2Frandomchars.onion%2Fabc123%0A3.%20Send%20BTC%20by%20following%20the%20instructions%20on%20the%20page

Before this PR:
image

After this PR:

image

  1. User input: bitcoin:bc1qjjrlgl28uqjtv0at2n3pfv3qtuvrm85vr0am5v Mainnet bech32 address on testnet. Prefix on testnet is tb1.

Before this PR:

image

After this PR:

image

  1. User input: bitcoin:1GmHaHzNDfMC8TY3Qaw9xt9FeBnzBYtGXz Mainnet legacy address on testnet. Prefix on testnet is N or M

Before this PR:

image

After this PR:

image

There is one more case which was already mentioned and can be tested with bitcoin:?r=https://merchant.com/pay.php?h%3D2a8628fc2fbe:

tr("Cannot process payment request because BIP70 is not supported.\n"

@GBKS
Copy link

GBKS commented Apr 16, 2021

Invalid prefix for Base58-encoded address requires technical understanding (What is Base58? Which part of the address is the prefix and what prefixes are valid?) to make sense of. Would it be possible to simplify the language? Something like Addresses should start with a 1.

Copy link

@Talkless Talkless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 9885de1, tested on Debian Sid with Qt 5.15.2

To reproduce, I've created wrapper open.sh file with this content:

#!/usr/bin/bash

/home/vincas/code/bitcoin/280-bitcoin-core-gui.git/_build_pr/src/qt/bitcoin-qt -regtest $@

Then, in about:config Firefox page I've set network.protocol-handler.expose.bitcoin to boolean false value.

Finally, entered specially-crafted link into Firefox address bar to open it, selected open.sh I've prepared earlier.

Master: got cracker message, this PR: got vague (but safe) error message as expected.

I personally don't care much about "usefulness" of the error message, better just fix it ASAP and improve in later PR.

@ghost
Copy link
Author

ghost commented Apr 26, 2021

I personally don't care much about "usefulness" of the error message, better just fix it ASAP and improve in later PR.

I agree. I think this PR is good enough to be merged. I have opened another PR bitcoin/bitcoin#21755 to improve error messages for invalid addresses.

@Bosch-0
Copy link

Bosch-0 commented Apr 27, 2021

tACK a79ca55 on windows 10 - looks good to me!

Before / After:

Frame 36

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concept ack

src/qt/paymentserver.cpp Outdated Show resolved Hide resolved
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK a79ca55.

src/qt/paymentserver.cpp Outdated Show resolved Hide resolved
src/qt/paymentserver.cpp Outdated Show resolved Hide resolved
@Rspigler
Copy link
Contributor

Rspigler commented May 1, 2021

tested ACK commit a79ca55

Great find!

A valid address still contains a label, but an invalid address will now only contain the error message (without extra info).

+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin/bitcoin#20832 for solution
@ghost
Copy link
Author

ghost commented May 2, 2021

@Rspigler I tried the examples mentioned in BIP 21 with a testnet address in bitcoin-qt(testnet). They are all working.

bitcoin:tb1q2ansurk0fypm2aex605m7z5rxxfe2k4umkxa2u

bitcoin:tb1q2ansurk0fypm2aex605m7z5rxxfe2k4umkxa2u?label=Luke-Jr

bitcoin:tb1q2ansurk0fypm2aex605m7z5rxxfe2k4umkxa2u?amount=20.3&label=Luke-Jr

bitcoin:tb1q2ansurk0fypm2aex605m7z5rxxfe2k4umkxa2u?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz

Not sure what did I test last time when I got error and opened this PR: bitcoin/bitcoin#21819. Maybe I used mainnet address in testnet.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 3bad0b3, tested on Linux Mint 20.1 (Qt 5.12.8).

Error message:

Screenshot from 2021-05-02 13-10-49

@hebasto hebasto added this to the 22.0 milestone May 8, 2021
Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 3bad0b3

Tested on macOS 11.3, Qt 5.15.2

Master PR.
Screen Shot 2021-05-09 at 10 26 32 PM Screen Shot 2021-05-09 at 10 27 51 PM

@maflcko maflcko modified the milestones: 22.0, 0.21.2 May 10, 2021
@maflcko
Copy link
Contributor

maflcko commented May 10, 2021

Concept ACK. Nice find. Added for backport.

@hebasto hebasto merged commit b49fe0a into bitcoin-core:master May 10, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 11, 2021
3bad0b3 Remove user input from URI error message (unknown)

Pull request description:

  Removes the user input from error message to avoid it being used in attacks.

  Its not really a vulnerability in Bitcoin Core because involves social engineering, dependency on user environment etc. But this PR improves security and by avoiding abuse of URI error in future.

  Example of an attack:

  1. User opens a link in firefox:

  ```
  bitcoin:tb1qag2e6yhl52hr53vdxzaxvnjtueupvuftan4yfu%0A%0AWARNING%3A%20DO%20NOT%20CLOSE%20THIS%20WINDOW%20OR%20TURN%20OFF%20YOUR%20PC!%20IF%20YOU%20ABORT%20THIS%20PROCESS%2C%20YOU%20COULD%20DESTROY%20ALL%20OF%20YOU%20DATA!%20PLEASE%20ENSURE%20THAT%20YOUR%20POWER%20CABLE%20IS%20PLUGGED%20IN!%0A%0AYou%20became%20victim%20of%20the%20XYZ%20RANSOMWARE!%0A%0AThe%20hard%20disks%20of%20your%20computer%20have%20been%20encrypted%20with%20a%20military%20grade%20encryption%20algorithm.%20There%20is%20no%20way%20to%20restore%20your%20data%20without%20a%20special%20key.%20You%20can%20purchase%20this%20key%20on%20the%20darknet%20page%20shown%20in%20step%202.%0ATo%20purchase%20your%20key%20and%20restore%20your%20data%2C%20please%20follow%20these%20three%20easy%20steps%3A%0A%0A1.%20Download%20the%20Tor%20browser%20at%20%E2%80%9Chttps%3A%2F%2Fwww.torproject.org%2F%E2%80%9C.%0A2.%20Visit%20one%20of%20the%20following%20pages%20with%20the%20Tor%20Browser%3A%0Ahttp%3A%2F%2Frandomchars.onion%2Fabc123%0A3.%20Send%20BTC%20by%20following%20the%20instructions%20on%20the%20page
  ```

  2. User selects Bitcoin Core to open the link:

  ![image](https://user-images.githubusercontent.com/13405205/114619801-8ee9a080-9cc8-11eb-9fad-23a2b831e8df.png)

  3. User is asked to send BTC with some message convincing enough which can be different depending on the victim:

  ![image](https://user-images.githubusercontent.com/13405205/114620061-d3753c00-9cc8-11eb-8314-e3362ebb90ac.png)

  **After this PR** (_No user input mentioned in the error_):

  ![image](https://user-images.githubusercontent.com/13405205/114624342-2b627180-9cce-11eb-93a8-0b2438d71571.png)

ACKs for top commit:
  hebasto:
    ACK 3bad0b3, tested on Linux Mint 20.1 (Qt 5.12.8).
  jarolrod:
    tACK 3bad0b3

Tree-SHA512: aac2fdfcaa7a9cd6582750c1960682554795640f5aacb78bdae121724e1151da3cbb62b8f8b1e0bc37347afe78b3e9a446277cab8e009d2a1050c0e971f001b3
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request May 22, 2021
+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin#20832 for solution

Github-Pull: bitcoin-core/gui#280
Rebased-From: 3bad0b3
@maflcko
Copy link
Contributor

maflcko commented May 22, 2021

Backported in bitcoin/bitcoin#22022

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request May 22, 2021
+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin#20832 for solution

Github-Pull: bitcoin-core/gui#280
Rebased-From: 3bad0b3
fanquake added a commit to bitcoin/bitcoin that referenced this pull request May 31, 2021
09620b8 Update Windows code signing certificate (Andrew Chow)
46320ba Remove user input from URI error message (unknown)
f2a8898 p2p, bugfix: use NetPermissions::HasFlag() in CConnman::Bind() (Jon Atack)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 09620b8 Diffs match.
  hebasto:
    ACK 09620b8, tested bitcoin-core/gui#280 behavior.
  fanquake:
    ACK 09620b8

Tree-SHA512: 1c4aaec42ea047261b5d30851bca605540eccf572708403335b38016127d3230b5380b3f5ef03921ed62192239b0d3da9787d51f557ed7911bf6bb2a7c172753
ComputerCraftr pushed a commit to ComputerCraftr/XEP-Core that referenced this pull request Jun 9, 2021
09620b89f5f78434080196162c75e3e65cc8d47f Update Windows code signing certificate (Andrew Chow)
46320ba72f80dd865b05bbfe2654cde124859881 Remove user input from URI error message (unknown)
f2a88986a18f197f6a4690f5dcca248f6b6170e2 p2p, bugfix: use NetPermissions::HasFlag() in CConnman::Bind() (Jon Atack)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 09620b89f5f78434080196162c75e3e65cc8d47f Diffs match.
  hebasto:
    ACK 09620b89f5f78434080196162c75e3e65cc8d47f, tested bitcoin-core/gui#280 behavior.
  fanquake:
    ACK 09620b89f5f78434080196162c75e3e65cc8d47f

Tree-SHA512: 1c4aaec42ea047261b5d30851bca605540eccf572708403335b38016127d3230b5380b3f5ef03921ed62192239b0d3da9787d51f557ed7911bf6bb2a7c172753
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants