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

Reject Solana SignTransaction/SignAllTransactions when blockhash is invalid #18200

Merged
merged 2 commits into from
Apr 22, 2023

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Apr 21, 2023

Resolves brave/brave-browser#29798

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Switch to Solana devnet and visit https://pwgoom.csb.app/.
  2. Click Sign Transaction (Invalid blockhash), wallet panel won't prompt and should see
    [error] signTransactionWithInvalidBlockhash: {"code":-32603,"message":"Blockhash is invalid or can not be validated"} on the screen.
  3. Click Sign All Transactions (Invalid blockhash), wallet panel won't prompt and should see
    [error] signAllTransactionsWithInvalidBlockhash: {"code":-32603,"message":"Blockhash is invalid or can not be validated"} on the screen.
  4. Click Sign Transaction and Sign All Transactions (multiple). In both cases, transaction signing prompt should be shown, and shouldn't see blockhash is invalid error. Note: It could fail after you approve for other reasons like insufficient funds or no record of a prior credit, which is fine.

There is also a test case provided in the hackerone report, but requires manual setup, please reach out to me for the zip of the repo and how to configure it.
(I did verify it locally, however, I think the tests I added in our test dApp should be enough. So maybe just test below on one platform to be extra safe.)
For testing the dApp in the hackerone report:

  1. Get a fresh profile and setup wallet with two Solana accounts created. Alternatively, you can also use an existing wallet with two Solana accounts.
  2. Get the repo copy from @yrliou and run yarn setup in that repo folder. (Node v18 is needed.)
  3. In solana-cross-cluster-poc/src/cross-cluster.js, replace the address in accounts with address of your Solana Account 1 (around line 9), and replace address used asattackerPubkey with address of your Solana Account 2 (around line 77).
  4. Save the change and run yarn start under the repo folder.
  5. Back to browser, make sure Default Solana Wallet setting is set to Brave Wallet and set active Solana network to mainnet beta.
  6. Visit http://localhost:9011/, connect to the wallet, click SEND FUNDS…, should see prompt for transaction signing. Approve it. Depends on whether you have funds available in your account, you’ll either see error later due to insufficient fund when the dApp trying to send transaction, or you'll see it successfully sends out a transaction and gives you the tx hash that you can query on explorer if you have funds enough to complete the transaction.
  7. Switch active network to devnet, reload the page and click SEND FUNDS…, wait for error {"code":-32603,"message":"Blockhash is invalid or can not be validated"} to show up and you should not see any prompt for transaction signing.

@yrliou yrliou self-assigned this Apr 21, 2023
@yrliou yrliou requested review from a team as code owners April 21, 2023 23:28
@yrliou yrliou force-pushed the validate_blockhash_from_dapps branch from e35f306 to c154ac6 Compare April 22, 2023 00:16
@@ -305,6 +292,13 @@ bool WaitForWalletBubble(content::WebContents* web_contents) {

return tab_helper->IsShowingBubble();
}

void CloseWalletBubble(content::WebContents* web_contents) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to add it to multiple Call* functions otherwise WaitForWalletBubble isn't working as what we expected because it was never dismissed after the previous request (we use NotifyXXXProcessed directly so UI doesn't really get dismissed).

params.Append(blockhash);

base::Value::Dict configuration;
configuration.Set("commitment", commitment ? *commitment : "processed");
Copy link
Member Author

Choose a reason for hiding this comment

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

Use processed as default so newer blockhash won't be invalid.

@yrliou yrliou force-pushed the validate_blockhash_from_dapps branch 3 times, most recently from d3f45e4 to 218e798 Compare April 22, 2023 02:44
@yrliou yrliou force-pushed the validate_blockhash_from_dapps branch 2 times, most recently from 7c910fd to 21bcc78 Compare April 22, 2023 03:57
@@ -9,6 +9,7 @@
<message name="IDS_WALLET_EXPECTED_SINGLE_PARAMETER" desc="The text of the response for wallet_addEthereumChain call with empty parameters">Expected single, object parameter.</message>
<message name="IDS_WALLET_CHAIN_EXISTS" desc="The text of the response for wallet_addEthereumChain call with existing chain id">This Chain ID is currently used</message>
<message name="IDS_WALLET_INTERNAL_ERROR" desc="The text of the response for wallet_addEthereumChain call with internal error">An internal error has occurred</message>
<message name="IDS_WALLET_INVALID_BLOCKHASH_ERROR" desc="The text of the response for Solana signTransaction and signAllTransactions with invalid blockhash or unable to validate due to network or RPC error">Blockhash is invalid or unable to be validated</message>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Blockhash is invalid or can not be validated

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, updated as suggested.

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

strings ++ (with a suggestion)

@yrliou yrliou force-pushed the validate_blockhash_from_dapps branch from 21bcc78 to bf6ffdf Compare April 22, 2023 04:21
@yrliou
Copy link
Member Author

yrliou commented Apr 22, 2023

macOS had a known test failure: P3ARotationSchedulerTest.ConstellationRotation.

@wknapik wknapik merged commit 297c1d4 into master Apr 22, 2023
@wknapik wknapik deleted the validate_blockhash_from_dapps branch April 22, 2023 15:21
@github-actions github-actions bot added this to the 1.52.x - Nightly milestone Apr 22, 2023
@wknapik
Copy link
Collaborator

wknapik commented Apr 22, 2023

@kdenhartog kdenhartog restored the validate_blockhash_from_dapps branch April 24, 2023 00:41
@kdenhartog kdenhartog deleted the validate_blockhash_from_dapps branch April 24, 2023 00:42
@kdenhartog
Copy link
Member

Screen.Recording.2023-04-24.at.1.06.07.PM.mov

@yrliou from what I'm seeing locally, this is breaking proper transaction signing now. Is this what you saw when you tested the happy path case as well?

@yrliou
Copy link
Member Author

yrliou commented Apr 24, 2023

@kdenhartog I didn't use their dApp to test the happy path but used our own dApp's normal cases which works fine, can test theirs tomorrow.

@yrliou
Copy link
Member Author

yrliou commented Apr 24, 2023

@kdenhartog I just tested it locally on master, signing works on mainnet and failed due to blockhash invalid error on devnet.

@kdenhartog
Copy link
Member

Ok must just be a local failure for me - thanks for double checking. I just tested on the PR build rather than master so that's probably the issue for me. I'll go ahead and close out the H1 issue - thanks for fixing so quickly!

@yrliou
Copy link
Member Author

yrliou commented Apr 24, 2023

@kdenhartog PR build should work too, not sure if it's environment or the some mistakes during testing, feel free to reach out to me if it's broken for you on latest nightly.

yrliou added a commit that referenced this pull request Apr 24, 2023
…nvalid (#18200)

* Add Solana IsBlockhashValid JSON-RPC support

* Reject Solana SignTransaction/SignAllTransactions when blockhash is invalid
@srirambv
Copy link
Contributor

srirambv commented Apr 25, 2023

Verification passed on

Brave 1.52.69 Chromium: 113.0.5672.53 (Official Build) nightly (64-bit)
Revision 12f5dac35d12e8f4e72d7dd11df557ef93bc046f-refs/branch-heads/5672@{#703}
OS Windows 11 Version 22H2 (Build 22621.1555)
  • Verified steps from PR using https://pwgoom.csb.app
  • Verified clicking on Sign Transaction (Invalid blockhash) doesn't show the panel for approval but instead shows [error] signTransactionWithInvalidBlockhash: {"code":-32603,"message":"Blockhash is invalid or can not be validated"}
  • Verified clicking on Sign All Transaction (Invalid blockhash) doesn't show the panel for approval but instead shows [error] signAllTransactionsWithInvalidBlockhash: {"code":-32603,"message":"Blockhash is invalid or can not be validated"}
  • Verified Sign Transaction (Invlalid blockhash) and Sign All Transactions (Invalid blockhash) fails when both Solana Mainnet and Solana Devnet are set as active network
    18200-TestDapp.mp4

Verification passed on

Brave 1.52.69 Chromium: 113.0.5672.53 (Official Build) nightly (64-bit)
Revision 12f5dac35d12e8f4e72d7dd11df557ef93bc046f-refs/branch-heads/5672@{#703}
OS Linux
  • Verified steps from PR of using the PoC setup
  • Verified when no funds in Mainnet and attempt to send funds shows Result: Error: failed to send transaction: Transaction simulation failed: Attempt to debit an account but found no record of a prior credit. error message
  • Verified when switching to Devnet and attempt to send funds shows Result: Error: Blockhash is invalid or can not be validated
    18200.mp4

Verified Sign Transaction and Sign All Transactions (multiple) works as expected.

18200-Sign.Transactions.mp4

kjozwiak pushed a commit that referenced this pull request Apr 25, 2023
…nvalid (uplift to 1.51.x) (#18217)

Reject Solana SignTransaction/SignAllTransactions when blockhash is invalid (#18200)

* Add Solana IsBlockhashValid JSON-RPC support

* Reject Solana SignTransaction/SignAllTransactions when blockhash is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hackerone]: blind cross chain signing should be prevented
7 participants