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

[DDW-742] Fix receiver address validation (disallow rewards address) #2781

Merged
merged 15 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## vNext

### Fixes

- Fixed receiver address validation by disallowing rewards addresses ([PR 2781](https://github.com/input-output-hk/daedalus/pull/2781))

### Chores

- Updated vulnerable dependencies ([PR 2769](https://github.com/input-output-hk/daedalus/pull/2769))
Expand Down
6 changes: 3 additions & 3 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"homepage": null,
"owner": "input-output-hk",
"repo": "cardano-wallet",
"rev": "dac16ba7e3bf64bf5474497656932fd342c3b720",
"sha256": "012lnp5rah4qyl8r0v04d0rz28b1rdaz6flhjrahf45b9gx7mny1",
"rev": "760140e238a5fbca61d1b286d7a80ece058dc729",
"sha256": "014njpddrlqm9bbab636h2gf58zkm0bx04i1jsn07vh5j3k0gri6",
"type": "tarball",
"url": "https://github.com/input-output-hk/cardano-wallet/archive/dac16ba7e3bf64bf5474497656932fd342c3b720.tar.gz",
"url": "https://github.com/input-output-hk/cardano-wallet/archive/760140e238a5fbca61d1b286d7a80ece058dc729.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gitignore": {
Expand Down
19 changes: 5 additions & 14 deletions source/common/types/address-introspection.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export type IntrospectAddressRequest = {
input: string,
};

export type AddressStyle = 'Byron' | 'Icarus' | 'Jormungandr' | 'Shelley';
export type AddressStyle = 'Byron' | 'Icarus' | 'Shelley';

export type AddressType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15;

export type ChainPointer = {
slot_num: number,
Expand All @@ -13,6 +15,7 @@ export type ChainPointer = {
};

export type AddressBase = {
address_type: AddressType,
address_style: AddressStyle,
network_tag: number | null,
stake_reference: 'none' | 'by pointer' | 'by value',
Expand All @@ -27,14 +30,6 @@ export type IcarusAddress = AddressBase & {
address_root: string,
};

export type JormungandrAddress = AddressBase & {
address_type: 'single' | 'group' | 'account' | 'multisig',
account_key?: string,
merkle_root?: string,
spending_key?: string,
stake_key?: string,
};

export type ShelleyAddress = AddressBase & {
pointer?: ChainPointer,
script_hash?: string,
Expand All @@ -45,10 +40,6 @@ export type ShelleyAddress = AddressBase & {

export type IntrospectAddressResponse =
| {
introspection:
| ByronAddress
| IcarusAddress
| JormungandrAddress
| ShelleyAddress,
introspection: ByronAddress | IcarusAddress | ShelleyAddress,
}
| 'Invalid';
12 changes: 10 additions & 2 deletions source/renderer/app/stores/WalletsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { logger } from '../utils/logging';
import { ROUTES } from '../routes-config';
import { formattedWalletAmount } from '../utils/formatters';
import { ellipsis } from '../utils/strings';
import { bech32EncodePublicKey } from '../utils/hardwareWalletUtils';
import {
bech32EncodePublicKey,
isReceiverAddressType,
} from '../utils/hardwareWalletUtils';
import {
WalletPaperWalletOpenPdfError,
WalletRewardsOpenCsvError,
Expand Down Expand Up @@ -1039,9 +1042,14 @@ export default class WalletsStore extends Store {
}
try {
const response = await introspectAddressChannel.send({ input: address });
if (response === 'Invalid') {

if (
response === 'Invalid' ||
!isReceiverAddressType(response.introspection.address_type)
) {
return false;
}

runInAction('check if address is from the same wallet', () => {
const walletAddresses = this.stores.addresses.all
.slice()
Expand Down
16 changes: 16 additions & 0 deletions source/renderer/app/utils/hardwareWalletUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HARDENED } from '../config/hardwareWalletsConfig';

// Types
import type { CoinSelectionAssetsType } from '../api/transactions/types';
import type { AddressType } from '../../../common/types/address-introspection.types';

export type PathRoleIdentityType =
| 'utxo_external'
Expand Down Expand Up @@ -38,6 +39,21 @@ export const KEY_PREFIXES = {

// Helpers

const receiverAddressTypes: Set<AddressType> = new Set([
0,
1,
2,
3,
4,
5,
6,
7,
8,
]);

export const isReceiverAddressType = (addressType: AddressType) =>
receiverAddressTypes.has(addressType);

// [1852H, 1815H, 0H] => m/1852'/1815'/0'
export const derivationPathToString = (derivationPath: Array<string>) => {
let constructedPath = 'm';
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/is-function/-/is-function-1.0.0.tgz#1b0b819b1636c7baf0d6785d030d12edf70c3e83"

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
"@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"

Expand Down