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

rpc: Sanitize label name in various RPCs with tests #26186

Merged
merged 3 commits into from Jan 10, 2023

Conversation

aureleoules
Copy link
Member

@aureleoules aureleoules commented Sep 27, 2022

The following RPCs did not sanitize the optional label name:

  • importprivkey
  • importaddress
  • importpubkey
  • importmulti
  • importdescriptors
  • listsinceblock

Thus is was possible to import an address with a label * which should not be possible.
The wildcard label is used for backwards compatibility in the listtransactions rpc.
I added test coverage for these RPCs.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 27, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK furszy, stickies-v, ajtowns, theStack, achow101
Concept ACK MarcoFalke, 1440000bytes

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26840 (refactor: importpubkey, importprivkey, importaddress, importmulti, and importdescriptors rpc by KolbyML)
  • #26174 (rpc, wallet: add ability to retrieve all address book entries by w0xlt)
  • #24897 ([Draft / POC] Silent Payments by w0xlt)
  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)
  • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@stickies-v stickies-v 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 3012200

test/functional/wallet_labels.py Outdated Show resolved Hide resolved
test/functional/wallet_labels.py Outdated Show resolved Hide resolved
src/wallet/rpc/backup.cpp Outdated Show resolved Hide resolved
src/wallet/rpc/backup.cpp Outdated Show resolved Hide resolved
@aureleoules
Copy link
Member Author

Thanks for the review @stickies-v, I've addressed all your comments.

test/functional/wallet_labels.py Outdated Show resolved Hide resolved
test/functional/wallet_labels.py Outdated Show resolved Hide resolved
@aureleoules
Copy link
Member Author

Pushed, thanks @stickies-v.

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

ACK d293585 - nice improvement, straightforward code changes and test.

Left a few nits, nothing blocking.

test/functional/wallet_labels.py Outdated Show resolved Hide resolved
test/functional/wallet_labels.py Outdated Show resolved Hide resolved
test/functional/wallet_labels.py Outdated Show resolved Hide resolved
Copy link
Member

@maflcko maflcko 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. Left a follow-up idea

src/wallet/rpc/backup.cpp Outdated Show resolved Hide resolved
src/wallet/rpc/backup.cpp Outdated Show resolved Hide resolved
src/wallet/rpc/coins.cpp Outdated Show resolved Hide resolved
src/wallet/rpc/addresses.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

ACK 8b71661

@aureleoules
Copy link
Member Author

Please restore it.

Done @luke-jr.

src/wallet/rpc/util.h Outdated Show resolved Hide resolved
@aureleoules aureleoules force-pushed the 2022-09-test-label-invalid branch 2 times, most recently from cce2e87 to b119bb8 Compare December 16, 2022 13:52
src/wallet/rpc/util.cpp Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Dec 18, 2022

Concept ACK

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

re-ACK 408e375

Reduced string copying compared to my previous ACK. One non-blocking nit.

src/wallet/rpc/transactions.cpp Outdated Show resolved Hide resolved
src/wallet/rpc/util.h Outdated Show resolved Hide resolved
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

ACK 893c288

Copy link
Contributor

@ajtowns ajtowns 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/wallet/rpc/util.h Outdated Show resolved Hide resolved
- importprivkey
- importaddress
- importpubkey
- listtransactions
- listsinceblock
- importmulti
- importdescriptors
src/wallet/rpc/util.h Outdated Show resolved Hide resolved
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

diff ACK 65e78bd

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

re-ACK 65e78bd

Comment on lines +135 to +136
static const std::string empty_string;
if (value.isNull()) return empty_string;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: not needed anymore now that we're returning a string copy

Suggested change
static const std::string empty_string;
if (value.isNull()) return empty_string;
if (value.isNull()) return "";

Copy link
Contributor

Choose a reason for hiding this comment

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

Or return {};

@ajtowns
Copy link
Contributor

ajtowns commented Jan 6, 2023

ACK 65e78bd

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK 65e78bd

[node.getnewaddress],
[node.setlabel, address],
[node.getaddressesbylabel],
[node.importpubkey, pubkey],
Copy link
Member

Choose a reason for hiding this comment

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

In 65e78bd "test: Invalid label name coverage"

importpubkey is a legacy wallet only RPC. The reason this test still passes with --descriptors is because the test framework has this (and some of the other import RPCs) aliased to importdescriptors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know. But considering this PR has 4 ACKs, is it worth the change? The test is executed with both --legacy-wallet and --descriptors anyway.

@achow101
Copy link
Member

ACK 65e78bd

@achow101 achow101 merged commit 68f88bc into bitcoin:master Jan 10, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 11, 2023
65e78bd test: Invalid label name coverage (Aurèle Oulès)
552b51e refactor: Add sanity checks in LabelFromValue (Aurèle Oulès)
67e7ba8 rpc: Sanitize label name in various RPCs (Aurèle Oulès)

Pull request description:

  The following RPCs did not sanitize the optional label name:
  - importprivkey
  - importaddress
  - importpubkey
  - importmulti
  - importdescriptors
  - listsinceblock

  Thus is was possible to import an address with a label `*` which should not be possible.
  The wildcard label is used for backwards compatibility in the `listtransactions` rpc.
  I added test coverage for these RPCs.

ACKs for top commit:
  ajtowns:
    ACK 65e78bd
  achow101:
    ACK 65e78bd
  furszy:
    diff ACK 65e78bd
  stickies-v:
    re-ACK 65e78bd
  theStack:
    re-ACK 65e78bd

Tree-SHA512: ad99f2824d4cfae352166b76da4ca0069b7c2eccf81aaa0654be25bbb3c6e5d6b005d93960f3f4154155f80e12be2d0cebd5529922ae3d2a36ee4eed82440b31
@aureleoules aureleoules deleted the 2022-09-test-label-invalid branch January 12, 2023 11:51
@bitcoin bitcoin locked and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet