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

URLs containing a / after the address no longer cause parsing errors. #4622

Merged
merged 1 commit into from Aug 11, 2014

Conversation

rnicoll
Copy link
Contributor

@rnicoll rnicoll commented Aug 2, 2014

In some cases under Windows a / is appended to bitcoin: URIs sent from browser to the client. This patch catches that case and removes the /.

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 3, 2014

Tested with:

bitcoin-qt -testnet bitcoin:n4dqmiBSWCTLnJRs4FXRxeHVAhZJhyPGCR
bitcoin-qt -testnet bitcoin:n4dqmiBSWCTLnJRs4FXRxeHVAhZJhyPGCR/
bitcoin-qt -testnet bitcoin:n4dqmiBSWCTLnJRs4FXRxeHVAhZJhyPGCR/?amount=100

With 0.9.2 the latter two fail, with the revised patch all three are parsed as valid URIs and the prompt to complete payment is shown after startup.

@laanwj
Copy link
Member

laanwj commented Aug 3, 2014

What are these cases?
I'd like to know why this corruption happens in the first place.
Do we do something wrong with escaping?

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 3, 2014

It's only something I'm seeing arising in Windows, but for some reason bitcoin: URIs are arriving with the client with a / on the end, as if they're being treated as URLs by some intermediary which rewrites them. Bitcoin is fine in theory, as the URI shouldn't have a / injected, but as it happens it seems practical to handle it.

The last test case was suggested as an extreme example, I haven't seen a / injected mid-URI, but as the code handles the possibility it's good to verify it.

@laanwj
Copy link
Member

laanwj commented Aug 3, 2014

OK. Weird. I've never heard this reported before.

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 3, 2014

I'll come back with more detail later, under the wrong OS right now.

@laanwj
Copy link
Member

laanwj commented Aug 3, 2014

Something 'intermediating' between the browser and Bitcoin Core does sound vaguely scary, by the way. I hope it's not a man in the middle attack :)

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 3, 2014

I meant it looks like the OS takes the URI and modifies it. Still, this is fairly much why the client verifies payments before they're sent, right? :)

@cdecker
Copy link
Contributor

cdecker commented Aug 3, 2014

Does this have an impact on people (wrongfully) using URIs with the bitcoin:// prefix, or are these broken anyway? Splitting by '/' feels awkward when a more explicit if-else checking for the last char would have done the trick.

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 4, 2014

@cdecker No, the rewrite to replace "bitcoin://" with "bitcoin:" occurs before this step, at around line 167 of guiutil.cpp

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 4, 2014

Reconfirmed the problem under Windows 7 with Chrome, and I think found why it occurs...

Looking at https://chain.so/address/BTC/14nsgXjL7xCEXFf8UkGCm9KnSTTFBDKqcn (just a random address that's been used recently), the "Send Bitcoin" link has bitcoin:// in it, which somehow triggers a / being appended to the URI as well. Fixing the URI in the page does also resolve this.

@laanwj
Copy link
Member

laanwj commented Aug 5, 2014

OK - they shouldn't be using bitcoin:// in the first place. But we remove the //, so it's fine with me to remove the trailing slash too.

I agree with @cdecker that splitting and then taking the first feels awkward though. I'd prefer a more specific if(uri.path().endsWith("/")) check.

@laanwj laanwj added GUI labels Aug 6, 2014
@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 7, 2014

Not sure why we got a bunch of random commits first update... anyway, that should be it just removing any ending / now.

@cdecker
Copy link
Contributor

cdecker commented Aug 7, 2014

Thanks, that looks a lot better.

@@ -117,6 +117,10 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)

SendCoinsRecipient rv;
rv.address = uri.path();
// Trim any leading forward slash which may have been added by the OS
if (rv.address.endsWith("/")) {
rv.address.truncate(rv.address.length() - 1);
Copy link

Choose a reason for hiding this comment

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

Nit: Indentation (use 4 spaces).

@laanwj
Copy link
Member

laanwj commented Aug 8, 2014

ACK after nit

@rnicoll
Copy link
Contributor Author

rnicoll commented Aug 8, 2014

Once more, with feeling...

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4622_c7f3876d4af37cfd6e587d0ab7ddbeaedda27857/ for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@laanwj laanwj merged commit c7f3876 into bitcoin:master Aug 11, 2014
laanwj added a commit that referenced this pull request Aug 11, 2014
c7f3876 URLs containing a / after the address no longer cause parsing errors. (Ross Nicoll)
@rnicoll rnicoll deleted the master-uri-parse branch August 29, 2014 23:46
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants