-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Verification of address is different from intent. #1906
Comments
I won't be extending the allowed addresses to have a I wasn't quite sure what you meant by the address can have Thanks! |
I meant the addresses that have checksum, but no '0x' prefix. // https://github.com/ethers-io/ethers.js/blob/master/packages/bignumber/src.ts/bignumber.ts#L228-L241
static from(value: any): BigNumber {
if (value instanceof BigNumber) { return value; }
if (typeof(value) === "string") {
if (value.match(/^-?0x[0-9a-f]+$/i)) { // my mistake
return new BigNumber(_constructorGuard, toHex(value));
} My personal question is, is there any reason not to allow '0X' prefixed addresses? Or, I wonder why web3.utils.isAddress allowed it. |
Mainly that making that change could have other consequences I'm not thinking of right now, as those hexstrings and hexdatastrings are used in many places, across other RegExps, string matching, string comparison, etc. But I also find the Ethers has never strived to be compatible with Web3.js; a lot of it is, by virtue that they both aim to provide an Ethereum-friendly experience, but a lot of decisions for Web3.js were made very early, under tight deadlines, and they have had to live with a lot of legacy as a result. One of the biggest things I've strived for with ethers is never guessing and only coercing when the intent is obvious. I expect people using ethers to use the I'm more that open to have my mind changed though, if there are good reasons to support it (other than "web3.js does it" ;)). |
Thanks for comment. |
The bug I delivered seems to have been fixed, can I close the issue? |
I can close it shortly. The newest version hasn't been published yet (the CI is having a few hiccups), but once it's up, I'll take care of it. :) No worries at all, I just try to remind people from time to time (it comes up a lot), that ethers is meant to be its own library, not just an alternative to Web3.js. The Web3.js definitely satisfy a need and has a lot of legacy applications they have to keep the lights on for. :) Thanks! :) |
(thanks for finding the above issue, btw; the address coder not properly converting ICAP addresses and addresses without a |
OK, Thank you for creating and managing a good library.😃 |
This has been updated in 5.4.6. Let me know if you have any further issues. Thanks! :) |
Closing now. If you have any issues please feel free to re-open or start a new issue. Thanks! :) |
Describe the bug
It seems ehters.js supports multiple types of addresses in ethereum.
But, contrary to the intended implementation, ethers.js does not support the addresses without '0x' or addresses starts with '0X' that web3.utils.isAddress() supports.
I think it can be a security bug when developers fully trust the results of web3.utils.isAddress() function and sending transactions with those addresses. It may cause an exception and remote DoS occurs.
Sample Contract to Run the PoC
Reproduction steps 1
When I use the addresses without '0x', it causes "invalid BigNumber string" error.
PoC
Result
Root Cause
In
getAddress()
function, if the address passed without '0x', it adds '0x' and checks the checksum.But, In the AddressCoder.encode() function that calls
getAddress()
, it does not append '0x' to the address and call thewriter.writeValue()
In the
writer.writeValue()
function, it parses the address as BigNumber. but, the passed address does not have '0x', and the address can have [a-z0-9A-Z]. So, the below regexp not matches and throw the "invalid BigNumber string" error.Reproduction steps 2
When I use the addresses that start with '0X', it causes "invalid address" error
PoC
Result
Root Cause
In
getAddress()
function, the regexp does not allows the address with '0X'.Environment:
Node
The text was updated successfully, but these errors were encountered: