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

fix: permit pages breaking if address user is interacting is invalid integer address #25833

Closed
wants to merge 6 commits into from

Conversation

jpuri
Copy link
Contributor

@jpuri jpuri commented Jul 15, 2024

Description

fix: permit pages breaking if address user is interacting is invalid integer address

Related issues

Fixes: #25733

Manual testing steps

  1. Go to test dapp
  2. Submit confirmation Malicious permit with integer address
  3. Metamask should not throw error

Screenshots/Recordings

Screenshot 2024-07-15 at 6 19 50 PM Screenshot 2024-07-15 at 6 19 43 PM

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@jpuri jpuri added team-confirmations Push issues to confirmations team release-12.1.0 Issue or pull request that will be included in release 12.1.0 labels Jul 15, 2024
@jpuri jpuri requested review from a team as code owners July 15, 2024 13:00
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@sleepytanya
Copy link
Contributor

@jpuri
All PPOM actions work great including Malicious permit with integer address.

Screenshot 2024-07-15 at 13 55 23

* @param {string} address - The address passed.
* @returns Checksum address or undefined.
*/
export const getChecksumAddress = (address) => {
Copy link
Member

@matthewwalsh0 matthewwalsh0 Jul 16, 2024

Choose a reason for hiding this comment

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

We now have toChecksumAddress, toChecksumHexAddress, and getChecksumAddress.

Could we re-use or extend toChecksumHexAddress?

Or at least place our new util in the same folder which is shared/modules/hexstring-utils.ts?

Copy link
Contributor Author

@jpuri jpuri Jul 16, 2024

Choose a reason for hiding this comment

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

toChecksumAddress is from ethjs-util lobrary. This function is different from toChecksumHexAddress and I can not categorise it as hex utillity

Copy link
Member

Choose a reason for hiding this comment

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

My concern is adding to a generic util that's already almost a thousand lines, as opposed to a targeted file so we can keep our logic modular and organised.

Even if they're different, we now have three very similar functions without obvious differences.

I'd argue that hextring-utils.ts is more meaningful than util.js since the checksummed address (if successful) is is a hexadecimal string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add it to a more specific utility class.

But I am not sure if that should be hex utility, is every method returning a hex value candidate for hextring-utils.ts ?

*/
export const getChecksumAddress = (address) => {
if (!ethUtil.isValidAddress(address)) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Was the intent of this fix and util not to convert the integer address to hexadecimal rather than just displaying the original value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ethUtil.isValidAddress throws error for invalid addresses thus this change keeps from metamask breaking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we still want to display invalid address to user with error from blockaid to show its wrong

Copy link
Member

Choose a reason for hiding this comment

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

The Name component is designed to show Ethereum addresses as hexadecimal strings, not whatever unformatted input is given to it.

We want the UX to be consistent, so it seems the best two choices are to reject the request outright if an address is in a bad format, or normalize it so we can render it in a consistent format, plus this would ensure Blockaid can validate it correctly rather than throwing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For a wrong address, I think we should show users that address value as it is so its more obvious to user's what is wrong and not change that.

Copy link
Member

@matthewwalsh0 matthewwalsh0 Jul 16, 2024

Choose a reason for hiding this comment

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

But it's not the user's problem, or even a problem at all if we can just normalize it to hexadecimal then process it as normal.

The average user won't know what to do with an address in a different format to what they're used to, so why should we sacrifice the UX consistency if we can just convert it and then it's no longer an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's discuss this more with product team to reach on decision here.

@jpuri jpuri requested a review from matthewwalsh0 July 16, 2024 10:15
Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

A couple of concerns:

  1. We should add/update tests for name, name-details, and shortenAddress
  2. Resulting UI with shortened invalid addresses is not shown in the PR description. Here are a couple of screenshots of the current UI:
    CleanShot 2024-07-16 at 14 25 21@2x
    CleanShot 2024-07-16 at 14 25 35@2x
  3. Have we discussed handling invalid addresses with design? It might be confusing to the user because we treat the invalid address as an address despite knowing it is an invalid address. This may not be a blocker for the PR, but I believe we should follow-up on this.

return shortenAddress(toChecksumAddress(value));
case NameType.ETHEREUM_ADDRESS: {
const checksumAddress = getChecksumAddress(value);
return shortenAddress(checksumAddress ?? value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting that if it is not a valid address, we may still shorten and truncate the value. Can we include tests for these cases for name and name-details?

also, now that shortedAddress may accept an invalid value, I think we should include a test for this. file: ui/helpers/utils/util.test.js

    it('should return the shortened string if it is not a valid address', () => {
      expect(
        util.shortenAddress('1234567890123456789012345678901234567890'),
      ).toStrictEqual('1234567...67890');
    });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it 👍

@jpuri
Copy link
Contributor Author

jpuri commented Jul 16, 2024

@digiwand : invalid address is shown along with blockaid error. Showing invalid address is better than not showing address at all.

I do not think its blocker as we never handled it even before.

@digiwand
Copy link
Contributor

I agree with you. This is why I also mentioned it would not be a blocker.

I do question if it would be an improvement to include more indicators that it is an invalid address rather than an "unknown address". Currently, users need to click "See details" in the banner alert to see it is. This is hidden. This could be a question for @SayaGT

Copy link

@jpuri
Copy link
Contributor Author

jpuri commented Jul 17, 2024

As discussed, we will reject signature like this. Thus closing this PR.

@jpuri jpuri closed this Jul 17, 2024
@jpuri jpuri deleted the permit_fix branch July 17, 2024 06:19
@github-actions github-actions bot locked and limited conversation to collaborators Jul 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed release-12.1.0 Issue or pull request that will be included in release 12.1.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: PPOM - extension crashes with a error when performing Malicious permit with integer address
5 participants