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

Reserved handle word check should be post-canonical #2147

Open
wilwade opened this issue Sep 3, 2024 · 0 comments
Open

Reserved handle word check should be post-canonical #2147

wilwade opened this issue Sep 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wilwade
Copy link
Collaborator

wilwade commented Sep 3, 2024

Summary

A user can claim a handle very similar to those in the RESERVED_WORDS list by using Unicode characters.

Issue details

During the execution of the claim_handle extrinsic, the base handle, which is passed by the user, is validated by the validate_base_handle function. One of the checks in this function ensures that the handle is not part of a list of reserved words:

ensure!(!is_reserved_handle(&base_handle_str), Error::<T>::HandleIsNotAllowed);

The is_reserved_handle function does not check the canonical base representation of the base_handle_str. As a result, a user can create a handle which looks very similar to a reserved one.

As an example, the following test claims a handle with "here" as prefix, by using Unicode character "\u0435" instead of "e" for the first 'e':

fn claim_handle_unicode() {
	new_test_ext().execute_with(|| {
		let alice = sr25519::Pair::from_seed(&[0; 32]);
		let expiry = 100;
		let (payload, proof) =
			get_signed_claims_payload(&alice, "hеre".as_bytes().to_vec(), expiry);
		assert_ok!(Handles::claim_handle(
			RuntimeOrigin::signed(alice.public().into()),
			alice.public().into(),
			proof,
			payload
		));

	});
}

The code for the final handle creation correctly uses the base_handle_str with a suffix that does take the canonical representation into account. As a result, there will never be two handles that only differ by a similar Unicode character.

However, to prevent any kind of confusion, the check for reserved handles in the RESERVED_WORDS list should use the canonical representation.

Mitigation

A simple mitigation would be to adjust the is_reserved_handle function to check the canonicalized representations of the strings:

pub fn is_reserved_handle(input_str: &str) -> bool {
  RESERVED_WORDS.map(|w| convert_to_canonical(w)).contains(&convert_to_canonical(&input_str))
}

However for efficiency, reserved word map should be converted for the constant and test moved to after the canonical conversion of the input.

@wilwade wilwade added the bug Something isn't working label Sep 3, 2024
@wilwade wilwade changed the title Reserved word check should be post-canonical Reserved handle word check should be post-canonical Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant